Pattern · Ports & adapters

Hexagonal Architecture

Isolate business logic from infrastructure. Swap databases, APIs, or UIs without touching the core.

HEXAGONAL ARCHITECTURE — PORTS & ADAPTERS Domain Core Business Logic · Entities Use Cases Application Services Domain Services Entities · Rules REST API API Gateway CLI / Events SQS · Lambda Database RDS · DynamoDB External APIs SES · SNS · S3 PRIMARY ADAPTERS SECONDARY ADAPTERS Core depends on ports (interfaces), never on adapters (implementations)

Overview

Hexagonal Architecture (Ports and Adapters) puts the domain model at the center. Everything external — databases, HTTP, queues, CLIs — connects through ports (interfaces) and adapters (implementations). The core never knows what's outside.

Core Concepts

Domain Core

Business logic, entities, and use cases. Has zero dependencies on frameworks, databases, or HTTP.

Ports

Interfaces defined by the core. Input ports (what the core exposes). Output ports (what the core needs).

Primary Adapters

Drive the application. REST controllers, Lambda handlers, CLI commands, SQS consumers.

Secondary Adapters

Serve the application. Database repositories, S3 clients, SES email, external API wrappers.

Key Benefits

AWS Implementation

Comparison

AspectHexagonalLayeredClean Architecture
TestabilityExcellentGoodExcellent
FlexibilityHighMediumHigh
ComplexityMediumLowHigh
Learning CurveMediumLowHigh

References

Lambda Hexagonal Architecture

Serverless hexagonal implementation with Lambda, API Gateway, and DynamoDB

GitHub

AWS Prescriptive Guidance — Hexagonal

Official AWS guidance on hexagonal architecture patterns

AWS Docs