Hexagonal Architecture

Domain-centric design separating core logic from external concerns via ports (interfaces) and adapters.

Architecture Diagram

Hexagonal ArchitectureDomain core surrounded by ports and adapters, showing dependency inversion and external system integration.🏛️ Hexagonal Architecture🎯 Domain Core• Business Logic• Domain Entities• Use Cases📥 Driving Side(User initiates)📤 Driven Side(Infrastructure)🌐 API PortWeb Interface⚡ Command PortBusiness Operations🔍 Query PortRead Operations💾 Repository PortData Persistence📨 Event PortMessaging & Events🌍 External API PortThird-party ServicesREST Controller• HTTP/JSON• OpenAPICLI Adapter• Command Line• Batch JobsGraphQL Adapter• Query Interface• SchemaDB Adapter• PostgreSQL• ORM/SQLMessage Adapter• Kafka• RabbitMQHTTP Client• External APIs• REST/SOAP🎯 Key PrincipleDependencies point inward toward the domainInfrastructure depends on business logic, never vice versaBenefits: Testability • Independence • Flexibility • Clean DependenciesDomain CorePorts (Interfaces)Adapters (Implementations)External Systems

Enabled By Platform Building Blocks

What it is

Core business logic depends only on abstractions (ports); adapters implement I/O concerns like databases, brokers, and HTTP.

Benefits

  • High testability and substitution of infrastructures
  • Clear boundaries and dependency inversion
  • Supports both monoliths and services

Distinctions vs. Clean Architecture

  • Hexagonal emphasizes external I/O at the boundary via ports/adapters
  • Clean emphasizes concentric layers and the dependency rule
  • Both are domain‑centric; naming and diagrams differ more than intent

Trade-offs

  • More boilerplate (ports, adapters, mappers)
  • Requires discipline in large teams