Skip to content
BENIBIX Learn

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.

Development🏗️ Architecture

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.

Example
Lucy's pricing rules live in plain code with no database calls. Her team moves from one database to another, and not one pricing line changes.
Why it matters
The rules are what make a business unique. Keeping them apart from tools means they outlive those tools.
Full entry
Development🏗️ Architecture

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.

Example
Jack's core has a port for sending messages. In tests he plugs in an adapter that just records them. In production a real email adapter sends them.
Why it matters
The core can be tested with no database or network at all. That makes tests fast and steady.
Full entry

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.