Hexagonal Architecture – Java Starter Project

I have shared the sample code for the  Hexagonal Architecture presentation. You can find the source code  at: github.com/fabricioepa/lab-hexagon-java But I should remeber you these patterns are not exclusively related to the Java technologies and frameworks.

My professional experience using this technique

It was very simple to create a decoupled REST adapter from the core application, it should be simple to create another kind of adapter too. However, if the application domain is quite BIG or there are many ports and adapters, you will have some overhead to maintain different domains translated from the original application core domain. The PORT interface should also have a stable API definition, you should design it to support evolution without easily break compatibility with the adapters implementations for that PORT. As inital strategy to achieve that design, the project has domain events to encapsulate all input and output data for the service, enabling the application to evolute without directly break the adapter code of the API.

core/api/src/main/java/com/ticketapp/core/api/TicketService.java

/**
 * Ticket Service - Use Case API
 */
public interface TicketService {

    TicketsReadEvent list(ReadTicketsEvent event);

    TicketCreatedEvent create(CreateTicketEvent ticket);

    TicketUpdatedEvent update(UpdateTicketEvent ticket);

    TicketDeletedEvent delete(DeleteTicketEvent ticket);
}

This is one reason for this pattern has often been applied to microservices architecture, because it works nice for multiple system integrations and also for small/medium sized application domains. If the application domain starts to grow up, may be it is the time to think about design a new hexagon to it.

Feel free to bring up your ideas 😉

Leave a comment