Skip to main content

Hexagonal Architecture

Invented by Alistair Cockburn, Hexagonal Architecture is one of many ways to design loosely coupled applications. This is also known as Ports and Adapters pattern.

As domain is the king and every other layer should work around it, this solves the layer dependency by inverting them.


Intent

Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases. (Alistair Cockburn)

Principle

Hexagonal architecture divided the system into manageable loosely coupled components centering application core domain. As the domain is at the center, all other layers such as web, database are directing at it.
This is achieved by ports and adapters (hence the name). Each outer layers is connected through ports by implementing them as adapters. Thus core domain is fully independent of changes. This approach is an alternative to traditional layered architecture.

  • Domain - sit center of the layers. Pure domain driven design principles can be used here.
  • Ports - define abstract API which represents application capabilities and needs. There can be incoming and outgoing ports. Application domain only depends on ports.
  • Adapters - glue between component and the outside. Implements ports using desired technical aspects.


Advantages

  • Components are loosely coupled.
  • Easily unit testable.
  • Does not depend on any technology like Spring.
  • Can easily replace adapters at any time.
  • Gives business meaning just looking at ports.

Further reading


Comments