Hexagonal Architecture Guide

March 18, 2026 · View on GitHub

Hexagonal Architecture (also known as Ports & Adapters) organizes code so that business logic is at the center, isolated from all external concerns. The core application communicates with the outside world only through well-defined interfaces (ports), and concrete implementations (adapters) plug into those interfaces.

Table of Contents

  1. Core Principles
  2. Directory Structure
  3. The Domain Layer
  4. Ports — Defining Contracts
  5. Adapters — Implementing Contracts
  6. The Application Layer (Use Cases)
  7. Handlers — Primary Adapters
  8. Dependency Injection & Wiring
  9. Cross-Cutting Concerns with the Decorator Pattern
  10. Error Handling Strategy
  11. Configuration Management
  12. Testing Strategy
  13. Dependency Flow Rules