Ports and adapters
Ports and adapters (also called hexagonal architecture) is the design pattern that surrounds a core domain model with a layer of ports (interfaces describing what the core needs) and adapters (concrete implementations of those interfaces for specific external systems). The core never depends on adapters; adapters implement the ports the core defines.
The pattern was named by Alistair Cockburn around 2005. The benefit is testability and external-system replaceability: the core domain logic is tested with in-memory adapters; switching from one database to another or one message broker to another is an adapter swap, not a core rewrite. The trade-off is layer proliferation — small applications don't benefit, but applications with many external integrations (databases, message brokers, APIs, file systems) benefit substantially. Hexagonal is sometimes confused with clean architecture and onion architecture; the three are variations on the same dependency-inversion idea with slightly different emphases.
Related terms
- Hexagonal architecture
Hexagonal architecture (also called ports and adapters), introduced by Alistair Cockburn in 2005, structures an application so the core domain logic depends only on abstract 'ports' — and concrete adapters (web framework, database, message bus) plug into those ports from outside.
- Clean architecture
Clean architecture, presented by Robert C.
- Onion architecture
Onion architecture organises code in concentric layers from the domain model at the centre outward through application services, domain services, and infrastructure at the edge.