Hexagonal Architecture

Verified

by Community

Explains the hexagonal architecture (ports and adapters) pattern for building applications that are independent of frameworks, databases, and external services. Covers how to define ports, implement adapters, and structure your application core.

hexagonalports-adaptersarchitecture

Hexagonal Architecture

Design applications using the ports and adapters pattern to achieve framework independence, testability, and clean separation of concerns. The domain logic sits at the center, communicating with the outside world through well-defined ports.

Usage

Ask about structuring your application with hexagonal architecture, defining ports and adapters, or migrating from a layered architecture.

Examples

  • "How do I structure a Node.js app with hexagonal architecture?"
  • "What is the difference between a driving port and a driven port?"
  • "Help me refactor my controller to use ports and adapters"

Guidelines

  • Define ports as interfaces in your domain layer
  • Adapters implement ports and handle external concerns like HTTP or databases
  • The domain core should have zero dependencies on infrastructure
  • Use dependency injection to wire adapters to ports
  • Write tests against ports, not adapters, for maximum flexibility