Skip to content

🏛️ Hexagonal Architecture

Hexagonal architecture (also called Ports and Adapters) is an architectural style that makes your application independent of frameworks, databases, UI, and external systems. It places your domain logic at the center, surrounded by “ports” (interfaces) and “adapters” (implementations). This creates a highly testable, maintainable, and flexible system.


Hexagonal architecture organizes a system so that core business logic (the domain) is completely isolated from external concerns. Communication happens through ports (interfaces) and adapters (implementations). This allows you to swap databases, UIs, or external services without changing domain code.

It answers:

  • How do we protect domain logic from external changes?
  • How do we make the system testable and adaptable?
  • How do we enforce clean boundaries?

Hexagonal architecture is often drawn as a hexagon to emphasize multiple entry points (not just one UI or API).

Hexagonal architecture


The center of the architecture.
Contains business rules, entities, value objects, domain services.
No external dependencies.

Interfaces that define how the domain communicates with the outside world.
Two types:

  • Inbound ports — how external actors call the domain
  • Outbound ports — how the domain calls external systems

Implementations of ports.
Examples: controllers, repositories, message handlers, API clients.

Use cases orchestrating domain logic.
Coordinates inbound/outbound ports.


  1. UI/API receives a request
  2. Controller calls an inbound port
  3. Application service executes domain logic
  4. Domain may call outbound ports
  5. Response returned to UI/API
  1. Domain needs external data
  2. Calls an outbound port
  3. Adapter implements the port (e.g., repository)
  4. External system responds
  5. Domain continues processing

This keeps domain logic pure and independent.


  • Strong separation of concerns
  • Domain purity — no framework or database leakage
  • High testability — mock ports, test domain in isolation
  • Replaceability — swap adapters without touching domain
  • Multiple entry points — API, CLI, events, UI
  • Ideal for microservices — clear boundaries and contracts
  • Supports long‑term maintainability

  • Putting business logic in adapters
  • Allowing domain to depend on infrastructure
  • Creating ports that expose infrastructure details
  • Over‑engineering ports for trivial use cases
  • Mixing inbound and outbound responsibilities

AspectLayeredHexagonal
Dependency directionTop → bottomToward the domain
Domain purityMediumVery high
TestabilityGoodExcellent
FlexibilityMediumHigh
Entry pointsUsually oneMany
InfrastructureBottom layerAdapter layer

Hexagonal architecture is stricter and more domain‑centric.


A hexagonal architecture for a Daily Scrum application might look like:

  • Entities: Task, Member, DailySession, Summary
  • Value objects: TaskStatus, MemberRole
  • Domain services: SummaryGenerator
  • IGenerateDailySummary
  • IManageTasks
  • ISendReminder
  • ITaskRepository
  • IMemberRepository
  • INotificationClient
  • IPdfExporter
  • Inbound adapters

    • Blazor components
    • API controllers
    • Message handlers (Service Bus)
  • Outbound adapters

    • PostgreSQL repository
    • Azure Service Bus publisher
    • PDF library implementation
    • Email/SMS provider

This structure ensures your domain is clean, testable, and independent of Blazor, PostgreSQL, or Azure.


Hexagonal architecture isolates your domain logic behind ports and adapters, making your system flexible, testable, and independent of external technologies. It is one of the strongest architectures for long‑term maintainability and aligns perfectly with clean architecture and DDD.