Skip to content
BENIBIX Learn

Hexagonal Architecture

Development🏗️ ArchitectureArchitecture Styles

Also known as Ports and Adapters, Ports and Adapters Architecture

Keeping an app's core apart. It links to the outside through ports and adapters.

Think of it like

Think of it like a phone with a charging port. Any charger that fits the port will work.

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.

Definition

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.

Common mistake

Writing a port and adapter for something that will never change. Ports earn their keep where you really swap things.

Key takeaways

  1. 1
    Core in the middle. Knows no outside tools.
  2. 2
    Ports are needs. Simple interfaces.
  3. 3
    Adapters plug in. Real or test.

Compare