“Create your application to work without either a UI or a database so you can run automated regression-tests against the application, work when the database becomes unavailable, and link applications together without any user involvement.” –Alistair Cockburn
Hexagonal or Ports & Adapters architecture.
Hexagonal Architecture (also known as Ports and Adapters architecture ) was defined by Alistair Cockburn in his book, “Hexagonal Architecture” in 2005. (Alistair Cockburn is also one of the original authors of he Agile Manifesto.) It depicts the application as a hexagon, where each side represents a Port with one or more Adapters.
A Port is a connector with a pluggable adapter that transforms an outside input to something the inside application can understand.Ports are the interfaces to the outside world and establish a clear API for what is needed and how it should be provided.This gives a lot of flexibility, and it not only allows you to swap adapters, for example during a test, but to also try out different technologies more quickly by actually trying it with the application.
In Hexagonal Architecture everything external is fundamentally an outside interface, and thus it’s a symmetrical view rather than an asymmetrical layering scheme. It’s often represented as a hexagon because it no longer makes sense to talk about a top layer or a bottom layer. Instead, Hexagonal Architecture talks mainly in terms of the outside and the inside.
In this pattern, the application as a whole is seen as a hexagon, with the business domain located inside.This core application logic is insulated with an isolation perimeter. This insulation helps an application to be unaware of the outside world. The insulation opens specific ports for establishing communication channels to and from the application code. Consuming applications can write adapters against these ports to communicate with the applicattion or component. Furthermore, if the application needs to emit a message to the outside, it will also use a port with an adapter to send it and transform it into something that the outside can understand.
The Hexagonal architecture lets the application treat all of its consumers alike, whether it is a user interface, test suit, monitoring service, or an automation script.
Cockburn, A. (2005). Hexagonal architecture.
The Clean Architecture – Uncle Bob (2012)
Picture Credit – Bady QB