Hexagonal Architecture
Ports and Adapters: keeping business rules independent of web, database and external services.
Hexagonal Architecture, also called Ports and Adapters, was described by Alistair Cockburn (2005). The application core defines ports — interfaces stated in the application’s own terms. Technology-specific adapters plug into those ports. Business rules can then be developed and tested without a web server, a database or a network.
The two published articles form a complete first pass:
- Layered versus Hexagonal Architecture covers the problem, the vocabulary, dependency direction, and when a simpler layered design is enough.
- Hexagonal Architecture with Spring Boot walks through a runnable order-management service. Its use cases are tested without Spring or a database.
The planned articles go deeper on each concept.
Articles
- Layered vs HexagonalHow classic layered architecture and Hexagonal Architecture (Ports and Adapters) differ in dependency direction, testability and cost — what ports and adapters are, why each port exists, and when a simple layered design is enough.
- Spring Boot ImplementationA complete, tested order-management service in Spring Boot 4 and Java 21, built with ports and adapters: package structure, domain model, use cases, REST and JPA adapters, wiring, and tests that run without Spring or a database.
Planned topics
These topics are on the roadmap and not written yet. They appear here so you can see the full scope of the section.
- The problem Hexagonal Architecture addresses
- The application core: domain and use cases
- Inbound ports and inbound adapters
- Outbound ports and outbound adapters
- Dependency direction
- Domain logic versus infrastructure logic
- Unit testing the core
- Integration testing adapters
- Common implementation mistakes
- Hexagonal versus Clean Architecture
- Hexagonal versus Onion Architecture