The goal of the Hexagonal architecture, also known as Port & Adapter is to isolate the core of the application from the other systems.
Once identified, the outside systems are divided in two categories:
- Driver: that needs our application to work
- Driven: that we need for our application to work
The rest of the code is the application itself, the inside part of the hexagon
The application contains the description of the needed services. Those descriptions are the ports
For the Driver, it will be the use of the ports that we can call. For the Driven, it will be the implementation of the needed service
Source: Hexagonal me
A package organization of this architecture can be
<src>
| <module name>
| domain classes (organized as you want)
| adapter
| in
| out
| ports
| in
| out
As a recap of the whole dependencies:
- The Driver side uses the application logic
- The application implements the provided use cases
- The Driven side implements the services needed by the application
Source: Hexagonal me
Implement the port & adapter aka hexagonal architecture for a simple use case.
This is a quite guided tour on how to setup it.