What is hexagonal architecture?

What is an application architecture?

A software or application architecture is a high-level view of application components and how they interact with each other. When we follow a specific type of architecture to build an application, it helps us plan, operate, and build a complete application from scratch to a high-level form.

Benefits of the application architecture

Here are the benefits of using the application architecture:

  1. Different application modules efficiently interact with each other.
  2. It becomes easy to implement, develop, and deploy the different modules of an application independently.
  3. Testing the application becomes a lot easier and faster.
  4. A well-structured application allows us to efficiently ensure that each functional requirement of an application is fulfilled.

The hexagonal architecture

The hexagonal architecture

The hexagon in a hexagonal architecture represents the application, where each side of the hexagon represents the external source with which the application interacts.

The hexagonal architecture has three parts:

  1. The user-side
  2. The application
  3. The server-side

All three are explicitly separate from each other. The application plays the most vital role in the architecture, as it contains all the code that implements the business logic.

The user-side and the server-side are both external sources. They interact with the application (the business logic) using ports and adapters, where the user interface (user-side) works as a source that initiates the interaction with the application. The infrastructure (server-side) works as a source initiated by the application. Both external sources are dependent on the application.

As this architecture mostly works using ports and adapters, it is also called the ports and adapters architecture.

The hexagonal architecture

Ports

Ports determine the interface that facilitates external sources to interact with the application and facilitates the application to communicate with external sources and services. Examples of external sources and services include databases, brokers, and other applications.

Adapters

Interactions between clients and the application occur with the help of adapters. Adapters initiate the interaction with the application via ports, and a single port can have as many adapters as needed for the interaction. An example of an adapter is a REST controller.

Application

In hexagonal architecture, an application is the core of the system. It contains all the functionality and business logic and is represented by the hexagon in the middle. The application receives requests from external sources (for example, a user interface) via a port. It then sends the request to an external source (for example, a database) through a port to help fulfill the request.

Benefits of the hexagonal architecture

The ports and adapter architecture allow us to:

  1. Build an application independently, without depending on any external source.
  2. Fully test the application more naturally and easily.
  3. Evolve the application, add a new feature, design new interfaces, or change any layer without worrying about a load of work or technology. We just need to implement the new adapter to allow the new feature to communicate with the application.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved