Tutorials Clean Architecture & DDD Mastery
Hexagonal Architecture (Ports and Adapters)
On this page
Ports and Adapters
Alistair Cockburn's Hexagonal Architecture teaches us that our application is a 'Hexagon' with many sides, each interacting with the outside world via Ports.
1. Ports (The Interfaces)
A Port is a hole in the Hexagon. It's an interface that defines "I need to send an email" or "I need to save a record". The Hexagon doesn't care who is on the other side.
2. Adapters (The Implementations)
An Adapter plugs into a Port. You can have a SendGridAdapter for production and a MockEmailAdapter for testing. You can have a RestApiAdapter for users and a CliAdapter for developers. The internal logic (the Hexagon) stays exactly the same.
3. Architect Insight
Q: "Is Hexagonal different from Clean Architecture?"
Architect Answer: "They are 90% the same. They both share the same goal: Decoupling. Clean Architecture is slightly more prescriptive about the internal 'layers', while Hexagonal focuses more on the 'Boundary' between the app and the outside world. If you understand one, you understand the other."