Hexagonal Architecture
Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases.
Hexagonal Architecture (Ports and Adapters) is a software architectural pattern that isolates your application's business logic from all external concerns — databases, frameworks, UIs, and third-party services. Introduced by Alistair Cockburn, the pattern enables the same application core to be driven by tests, batch scripts, CLI tools, or HTTP clients interchangeably. It produces a codebase where infrastructure is swappable, the core is always testable in isolation, and architectural boundaries are explicit and mechanically enforceable.
“I have a Spring Boot service where my service classes directly autowire JpaRepository interfaces. Testing is painful — I have to spin up an H2…”
Keep business logic pure — swap any database, UI, or API without touching the core
Hexagonal Architecture structures an application around three explicit zones: the Application Core (the hexagon), which contains pure domain and business logic with zero dependencies on infrastructure or frameworks; Ports, which are typed interfaces defining the contracts at the application boundary — split into Primary/Driving Ports (use-case interfaces that external actors call) and Secondary/Driven Ports (infrastructure contracts the core requires, such as repository or notification interfaces); and Adapters, which are concrete implementations of those ports for specific technologies (a Spring REST controller implementing a primary port, a JPA repository implementing a secondary port). The central non-negotiable constraint is the Dependency Rule: all dependencies point inward. The core never imports or references adapter code. This makes the core testable in complete isolation by swapping real adapters for in-memory test doubles, and makes infrastructure interchangeable without modifying business logic. The hexagon shape itself is intentional — each side represents a distinct port, signaling that many different drivers and technologies can connect to the core without any single one being privileged.
Most codebases tightly couple business logic to infrastructure — service classes directly import JPA repositories, domain objects reference HTTP request types, and swapping a database means rewriting core logic. This makes the application impossible to unit-test without spinning up real infrastructure, and every technology change ripples through the entire codebase. Hexagonal Architecture solves this by making the coupling explicit and enforceably one-directional: infrastructure always adapts to the core, never the reverse.
You walk away with a clear architectural boundary — named port interfaces defining your application's contracts, adapter stubs implementing them per technology, and a test double pattern that lets the entire core run in milliseconds with zero infrastructure. Your business logic survives any infrastructure change because it never knew the infrastructure existed.
- A description of your application's domain and its key use cases
- Existing code, a class diagram, or a project structure to audit or migrate
- Your target language or framework (Java, Python, TypeScript, Go, etc.)
- The specific infrastructure you need to isolate (SQL database, REST API, message queue, etc.)
- Named primary and secondary port interface definitions ready to commit to your codebase
- Adapter class skeletons for your specific technology stack (Spring, SQLAlchemy, Mongoose, Stripe SDK, etc.)
- A recommended project directory structure that enforces the hexagonal boundary at the filesystem level
- A dependency-direction compliance checklist with pass/fail verdicts for every boundary in your codebase
Watch the methodology work.
Three specimens from a single real session: the same situation, unaided and calibrated, the full transcript, and the skill answering live in the channel where the work happens.
“Your `OrderService` has `@Autowired OrderJpaRepository repo`, `@Autowired EmailClient emailClient`, and `@Autowired ProductCatalogRestClient catalog` as direct fields. Every unit test requires a full Spring context, an H2 in-memory database, and live API credentials. Changing from SQL to NoSQL means modifying the service class. A bug in the email service fails order placement tests.”
“Your `OrderService` depends only on `OrderRepository`, `NotificationService`, and `ProductCatalog` — three interfaces it owns in the domain package. A 4-line JUnit test constructs it with `InMemoryOrderRepository` and `NoOpNotificationService` and runs in under 50ms with no infrastructure. Swapping Postgres for MongoDB means writing a new `MongoOrderRepository` adapter — zero changes to the core. The compliance checklist shows zero dependency-direction violations.”
The same skill, where the work happens.
No new app to learn. The methodology runs over the WhatsApp Business API, so the answer lands as a reply in the thread you’re already in — same rigour, zero context-switch.
What it does, specifically.
Each capability is a distinct move drawn straight from the source methodology — not a generic assistant guessing.
Port/Adapter Boundary Audit
Analyzes your existing code structure and identifies every place where the Dependency Rule is violated — core classes importing adapter-layer code, domain objects referencing framework annotations, or service layers directly instantiating infrastructure clients. Each violation is classified, explained, and paired with a concrete remediation step.
Port Interface Generator
Takes your use cases and infrastructure dependencies and produces typed interface definitions for both primary ports (the use-case interfaces external drivers call) and secondary ports (the infrastructure contracts the core requires, such as OrderRepository or NotificationService). Output is in your chosen language with idiomatic naming conventions.
Adapter Skeleton Builder
Generates concrete adapter class stubs — both primary adapters (REST controllers, CLI handlers, test harness drivers) and secondary adapters (JPA/SQLAlchemy repositories, SMTP notification clients, in-memory test doubles) — wired to the generated port interfaces. Each adapter is self-contained and interchangeable without modifying the core.
Hexagonal Migration Planner
Produces a step-by-step migration plan for extracting a specific layer (database access, HTTP layer, external API client) from an existing codebase into the ports-and-adapters model. Each step is incremental and preserves behavior while progressively introducing the boundary, with a test strategy at each stage.
Architecture Pattern Disambiguator
Provides precise, concrete comparisons between Hexagonal Architecture and adjacent patterns — Clean Architecture (Uncle Bob), Onion Architecture (Jeffrey Palermo), and traditional Layered Architecture — mapping their terminology to each other and identifying where they diverge in practice, so teams adopt the right pattern with accurate vocabulary.
Graded before it shipped.
Every skill is scored against independent scenarios for methodology fidelity before it goes live — not vibes, a rubric.
Hexagonal Boundary Diagram
A labeled architecture diagram showing the application core (hexagon) at the center, named ports on each face, and adapters on the perimeter connected to their external technologies — suitable for technical documentation or team onboarding.
Port Interface Definitions
Typed primary and secondary port interfaces in your chosen language, with method signatures derived from your use cases and infrastructure dependencies — ready to paste into your codebase with zero infrastructure imports.
Adapter Skeleton Set
Concrete adapter class templates for each port — including a lightweight in-memory test adapter and a real infrastructure adapter stub — wired to the port interfaces and ready to fill with technology-specific logic.
Project Directory Blueprint
A recommended folder and package structure that enforces the hexagonal boundary at the filesystem level, customized to your language and build tool (Maven, Gradle, Poetry, npm, etc.) with notes on which import directions are permitted.
Dependency-Direction Compliance Checklist
A checklist of the pattern's non-negotiable rules with pass/fail status for your codebase: core imports only ports, adapters depend on ports not each other, no framework annotations in the core, and all infrastructure is wired at startup via dependency injection.
Grounded in the original work.
Every answer traces back to a real source and the practitioner who wrote it — not a secondhand summary. Here is the source of record.
Alistair Cockburn
Alistair Cockburn is one of the 17 original signatories of the Agile Manifesto (2001) and a software methodology pioneer. He introduced Hexagonal Architecture in a 2005 article that became a canonical reference in software engineering, and is also the creator of the Crystal family of agile methods and the author of 'Writing Effective Use Cases' and 'Agile Software Development.' He developed Hexagonal Architecture while working as a software architect and consultant, observing that test-driven applications could be generalized by treating tests as interchangeable drivers of an isolated application core.
Hexagonal Architecture (alistair.cockburn.us, 2005)
Co-author of the Agile Manifesto (2001); inventor of Hexagonal Architecture and Crystal Methods; author of 'Writing Effective Use Cases'; software architect and methodology researcher.
Be first to run it.
Hexagonal Architecture is being built right now. Leave your email and we’ll tell you the moment it goes live.