This article is for sharing my understanding about Ports & Adapters pattern (also known as Hexagonal Architecture), hoping it can be helpful to someone interested in this subject.
Documented in 2005 by Alistair Cockburn, Hexagonal Architecture (is also called as Ports & Adapters pattern ) is a architectural pattern used in software design that promotes decoupling from technology and frameworks.
The hexagonal architecture is an attempt to avoid known structural pitfalls in layered architecture.
In layered architecture, over a period of time all the projects get into the problem of excessive coupling across layers.
Alistair Cockburn'a aim was to use architecture to prevent business logic from infrastructure or framework,He accordingly drew application domains as hexagonal shapes.
Imagine a hexagon, here the hexagon is the application itself. Inside the hexagon we just have the things that are important for the business problem that the application is trying to solve.
The hexagon contains the business logic, with no references to any technology, framework or real world device.
In other word, in hexagon, anything inside the hexagon must be free from technology concerns,So the application is technology agnostic.
Outside the hexagon we have any real world thing that the application interacts with.
Overview of what is the Hexagonal Architecture
Adapters
Adapter is to implement a concrete protocol by which some external system or device can communicate with the application.
An adapter translates between a specific technology and a technology free port.
An adapter is a software component that allows a technology to interact with a port of the hexagon
In most of cases, REST controller are act as a our primary adapter, providing endpoints accessing domain through port (Interface)
A adapter converting a specific technology request into a domain understanding form and pass to the hexagonal through Interface( port)
Ports are the application boundary, in the picture a port is an edge of the hexagon.
To let the outside to interact with the domain, the Hexagon provides business interfaces(Ports) divided in two categories:
API : Those interfaces are implemented by the Hexagon, are also called 'Inbound interface'
SPI: (Service Provider Interface) is an interface for a functionality, needed by the hexagon for implementing the business logic. It also called outbound interface
This is my understanding about hexagonal architecture. In Next Part I would like to run through Use Case using hexagonal architecture .
If you want to get more information on the topic, read Alistair Cockburn’s original article on the subject
I hope this article will help you understand idea of Hexagonal Architecture and who they are comes together I’ll be glad for any feedback!