Learn

Navigate through learn topics

Hexagonal (Ports and Adapters)

Domain-centric design with adapters for I/O and frameworks

Last updated: 8/15/2025

Hexagonal (Ports and Adapters)

Hexagonal architecture places the domain model at the centre and isolates it behind ports (interfaces). Adapters implement those ports for databases, HTTP, messaging and third parties.

When it fits

  • You need strong testability and the ability to swap infrastructure
  • Complex domains that must stay independent of frameworks

Risks

  • Extra abstractions can feel heavy for simple apps

Real-world examples

  • Fintech backends that switch between payment gateways or risk providers without touching core domain logic
  • SaaS products that run the same domain code across different databases or queues via adapters

Practical tips

  • Define ports from the domain’s perspective; avoid leaking infrastructure concerns
  • Keep adapters thin and focused on translation