link: Architectural Patterns

Hexagonal Architecture

Diagram

Overview

Hexagonal Architecture, also known as Ports and Adapters Architecture, is a design pattern that aims to decouple the core business logic from external systems, making the application more maintainable and adaptable. It achieves this by placing the inputs and outputs at the edges of the system, allowing the core logic to remain independent of how data is fetched or exposed.

Key Concepts

Core Concepts

  • Core Logic Isolation: The core business logic is isolated from external concerns such as databases, APIs, and user interfaces.
  • Ports: Define interfaces that the core logic requires or provides, abstracting away the details of how these operations are carried out.
  • Adapters: Implement the ports, handling the specifics of interacting with external systems like databases, REST APIs, or other services.
  • Dependency Inversion Principle: Core logic depends on abstractions (ports) rather than concrete implementations (adapters), enhancing flexibility and reducing coupling.

Example

Related Topics

Hexagonal Architecture, by focusing on decoupling and clear interfaces, provides a robust framework for building adaptable and maintainable software systems. By leveraging the Dependency Inversion Principle, it ensures that core logic remains unaffected by changes in external dependencies, thus promoting flexibility and resilience.

Summary

Summary

The idea of Hexagonal Architecture is to put inputs and outputs at the edges of our design. Business logic should not depend on whether we expose a REST or a GraphQL API, and it should not depend on where we get data from — a database, a microservice API exposed via gRPC or REST, or just a simple CSV file.

“The pattern allows us to isolate the core logic of our application from outside concerns. Having our core logic isolated means we can easily change data source details without a significant impact or major code rewrites to the codebase.”

References

Hexagonal Architecture and Clean Architecture (with examples) - DEV Community