# Hexagonal Architecture

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

**Field:** Software Development  
**Category:** Architecture  
**Also known as:** Ports and Adapters, Ports and Adapters Architecture

## Think of it like

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

## 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.

## 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.

## Common mistake

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

## Three principles

- **Core in the middle.** Knows no outside tools.
- **Ports are needs.** Simple interfaces.
- **Adapters plug in.** Real or test.

## Related terms

- [Clean Architecture](https://learn.benibix.com/term/development/clean-architecture)
- [Interface (Programming)](https://learn.benibix.com/term/development/interface)
- [Dependency Injection](https://learn.benibix.com/term/development/dependency-injection)
- [Unit Test](https://learn.benibix.com/term/development/unit-test)

## Told apart from

- [Clean Architecture vs Hexagonal Architecture](https://learn.benibix.com/compare/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.

---

Source: https://learn.benibix.com/term/development/hexagonal-architecture
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
