Hexagonal Architecture

Learn about hexagonal architecture and its pros and cons.

Overview

Hexagonal architecture, also known as ports and adapters architecture, is a design pattern that separates the core functionality of an application from its external dependencies. It’s intended to make an application more flexible, modular, and testable by creating a clear separation between the business logic and the interfaces that connect the application to the outside world.

Principles of hexagonal architecture

Here’s an overview of the main components and principles of hexagonal architecture:

  • Core domain: This is the heart of the application, and it represents the business logic and the entities that make up the application’s domain. The core domain should be isolated from external dependencies and should contain no knowledge of the infrastructure or details of how it’s used.

  • Adapters: These are the components that connect the core domain to the outside world. They provide the interface between the core domain and external systems, such as databases, web services, or user interfaces. Adapters may be implemented as input adapters, which receive data from external systems, or output adapters, which send data to external systems.

  • Ports: These are the interfaces that define the contracts between the core domain and adapters. They specify the methods and data structures the adapters must implement to interact with the core domain.

  • Drivers: These are the components that provide the concrete implementation of the ports. They may be implemented as part of the core domain or as standalone components that connect to the core domain through the ports.

Get hands-on with 1200+ tech skills courses.