Clean Architecture vs Hexagonal Architecture
People think clean and hexagonal architecture are rivals, and they are not. Both keep the business rules at the center. The database and the web depend on the rules, never the other way. One names the plugs: ports, and adapters that fill them. The other draws rings and says code points only inward. The rule is the same.
Clean Architecture
The rules of the business sit in the middle. Tools stay at the edge.
Clean architecture puts the business rules at the center of an app. The database, the web framework and the screens sit in outer rings. The key rule is that code only points inward: the center knows nothing about the outer rings. So you can swap a database or framework without touching the rules. Robert C. Martin described it in 2012.
Hexagonal Architecture
Keeping an app's core apart. It links to the outside through ports and adapters.
Hexagonal architecture keeps an app's core apart from the outside world. It is also called ports and adapters. The core says what it needs through ports, which are simple interfaces. Adapters plug into those ports to connect a real database, a web page or a test. The core never knows which adapter is plugged in. Alistair Cockburn described the idea in 2005.
In one line
- Clean Architecture
- The rules of the business sit in the middle. Tools stay at the edge.
- Hexagonal Architecture
- Keeping an app's core apart. It links to the outside through ports and adapters.