An architecturally expressive package structure
In a Hexagonal Architecture, we have entities, use cases, input and output ports, and input and output (or “driving” and “driven”) adapters as our main architectural elements. Let’s fit them into a package structure that expresses this architecture:
We can map each element of the architecture directly to one of the packages. At the highest level, we have the adapter and application packages.
The adapter package contains the incoming adapters that call the application’s incoming ports and the outgoing adapters that provide implementations for the application’s outgoing ports. In our case, we’re building a simple web application with the web and persistence adapters, each having its own sub-package.
Moving the adapters’ code to their own packages has the benefit that we can very easily replace one adapter with another implementation, should the...