liveBook · Manning

Hexagonal architecture

As explained in Effective Behavior-Driven Development

Hexagonal architecture is a software architecture pattern that isolates core application logic from external systems through ports and adapters.

Hexagonal architecture, also called Ports and Adapters, separates core business logic from external systems. The core defines ports that express what it needs; adapters connect those ports to particular services. This makes external boundaries easier to reconfigure and supports different deployment contexts. section 15.8.1

A payment integration illustrates how the boundaries work:

  • A payment port describes the functionality the application needs, rather than every capability offered by a payment provider. section 15.8.1
  • A Stripe adapter connects that port to the Stripe API. Other adapters can be selected through configuration. section 15.8.1
  • Tests can enter through an inbound port or replace an outbound service adapter with a stub. section 15.8.1

Inbound connections can include a UI or message broker; outbound dependencies can include databases or web services. The pattern brings separation of concerns and inversion of control together under one ports-and-adapters model. section 15.8.1

Figure 15.8 In hexagonal architectures, external services connect to the domain logic through ports and adapters

Use the schematic to visualize external systems connecting to domain logic through ports and adapters. section 15.8.1

How Effective Behavior-Driven Development covers it

How deep it goes
Defines ports, adapters, inbound and outbound connections, and stub-based testing, while leaving detailed treatment aside.
Examples
Uses a payment port with a Stripe adapter, UI and message-broker inputs, database and web-service dependencies, and test stubs.
What you can do after
Apply it by defining ports for core needs, mapping adapters to external services, and replacing service adapters with stubs in tests.
How it connects
Connects separation of concerns and inversion of control with dependency injection, test drivers, polymorphic drivers, and stub dependencies.

Also explained in

Compare how 11 books explain hexagonal architecture →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Behavior-Driven Development. The section links point to the parts of the book it draws on.