jeremie-bardon/hexagonal-architecture icon
public
Published on 8/17/2025
Hexagonal architecture

Rules

Hexagonal architecture - Coding Assistant Guidelines

1. Domain Layer Purity

  • The domain layer contains entities, value objects, and aggregates.
  • It must not depend on:
    • Application layer
    • Infrastructure layer
    • External libraries (except standard language libs)

2. Application Layer Depends Only on Domain

  • Application services (use cases) can depend on the domain layer.
  • They must not depend on the infrastructure layer.

3. Infrastructure Implements Ports Only

  • The infrastructure layer (DB, APIs, messaging, file systems, etc.) should implement ports defined in the domain or application.
  • It must not introduce its own business logic.

4. Adapters Contain No Business Logic

  • Infrastructure adapters (e.g., database repositories, API clients) should contain only integration logic.
  • They should not implement domain rules such as validation, calculations, or business decisions.

5. Ports Are Stable Contracts

  • Ports define the interfaces for repositories, services, or external dependencies.
  • They must not import or depend on the infrastructure layer.

6. Entry Points Live in Interfaces Layer

  • All external entry points (REST controllers, GraphQL resolvers, CLI commands, etc.) belong to the interfaces layer.
  • They should call application services only, not the domain or infrastructure directly.

7. Tests Respect Boundaries

  • Unit tests should mock dependencies across layers.
  • Integration tests should wire adapters together but always go through ports.