Sitemap
Anass Guendef

Anass Guendef

Tech lead — JAVA/ANGULAR

Hexagonal Architecture

2 min readDec 2, 2022

--

Press enter or click to view image in full size
Photo by Donny Jiang on Unsplash

Definition

The main characteristic of “Hexagonal Architecture”, as opposed to the common layered style of architecture, is that the dependencies between our components point “inwards”, towards our domain objects.

Get Anass Guendef’s stories in your inbox

Join Medium for free to get updates from this writer.

The point is to isolate the core business of an application and test its behavior independently of all the rest.

Press enter or click to view image in full size

Three principles

The hexagonal architecture is based on three principles:

  • Explicit separation: Application, Domain, and Infrastructure.
  • Dependencies go to Domain.
  • Ports and Adapters isolate domain boundaries.

Domain

  • The Domain is the core business of the application; it contains the business objects as well as the business rules.
  • Domain Objects have no external dependencies, they are pure Java (POJO).
  • Because domain objects do not depend on other layers of the application, changes from other layers do not affect them.
  • Isolation of the Domain from technical dependencies will allow us to ensure maximum test coverage of the business.
  • Ideally, a business expert who does not know how to code could read a piece of code from this part and tell us about an inconsistency.
  • Domain objects and use cases reside in the hex, i.e. in the core of the application, every communication to and from outside goes through dedicated “ports”.
  • An input port is a simple interface that can be called by external components and implemented. The component calling such an input port is called an input adapter (a Rest API, for example).
  • An output port is still a simple interface that our use cases can call if they need something from the outside (access to a database, for example). it is implemented by an external component called an output adapter.

Application

  • The entry point of our application. It contains the code that allows the interaction of the user or the external programs with the application.
  • This is the side where we find the actors who pilot the Domain.
  • It contains the input adapters.

Infrastructure

  • We put in it what our application needs to work, the essential infrastructure details like the code that interacts with the database, with a partner, with the file system…
  • This is the side where we find the actors who are driven by the Domain.
  • It contains the output adapters.
Press enter or click to view image in full size

--

--