hexagonal-architecture
Skill1 starsChanged 58 days agoMITView on GitHub
Ports and adapters design covering domain and use-case boundaries, inbound and outbound ports, dependency inversion, adapters, the composition root, and per-boundary testing in TypeScript, Java, Kotlin and Go. Use when you say "restructure this around ports and adapters", "my domain imports the ORM", "test this use case without a database", or "swap this payment provider". Not for HTTP contract design, use `api-design`.
13 other projects use a version of this, 5 of them edited.
Adopted by
Most recently taken up by
- ankhorage/devtoolsedited, first seen Oct 3, 2026
- templetongroup/radiantedited, first seen Sep 17, 2026
- socialadsmentor/sam-agentic-harnessedited, first seen Sep 3, 2026
- rrezartprebreza/spring-boot-skillstheir own version, first seen Aug 7, 2026
- SamuelNDCE/claude-super-skill-libraryedited, first seen Aug 1, 2026
- spShashankGit/skillstheir own version, first seen Jul 12, 2026
Used with
Projects with it also use domain-driven-design.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
jarrodmedranoSkilldomain-driven-design
This skill should be used whenever domain modeling is taking place. It provides specialized guidance for type-driven and data-driven design based on Rich Hickey and Scott Wlaschin's principles. The skill helps contextualize current modeling within the existing domain model, identifies inconsistencies, builds ubiquitous language, and creates visualizations (Mermaid, Graphviz/DOT, ASCII diagrams) to communicate domain concepts clearly. Use this skill when designing types, modeling business domains, refactoring domain logic, or ensuring domain consistency across a codebase.
Also in 3 projects that use this
Other versions13 projects use a version of this.
Word for word · 0
None found.
Edited · 5
- templetongroup/radiant★ 11375% same
- Jamkris/everything-gemini-code★ 8776% same
- socialadsmentor/sam-agentic-harness★ 476% same
- ankhorage/devtools★ 273% same
- SamuelNDCE/claude-super-skill-library★ 176% same
Wrote their own version · 8
- rrezartprebreza/spring-boot-skills★ 293same name
- fatonh/symfony-skills★ 35same name
- noah-sheldon/ai-dev-kit★ 13same name
- joabgonzalez/ai-agents-skills★ 9same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- kayaman/skills★ 2same name
- gabrielgianesini/Claude-SKILLs-★ 1same name
- spShashankGit/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository59 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .claude/CLAUDE.mdCLAUDE.md
- agentic-engineeringSkill
- ai-regression-testingSkill
- angularSkill
- ansibleSkill
- api-designSkill
- architecture-decision-recordsSkill
- ascend-memorySkill
- ascend-web-hunterSkill
- audio-scribeSkill
- automation-inventorySkill
- backend-patternsSkill
- bashSkill
- build-dependency-managementSkill
- code-formatterSkill
- code-reviewerSkill
- coding-standardsSkill
- dart-flutter-patternsSkill
- database-migrationsSkill
- deployment-patternsSkill
- design-systemSkill
- docker-patternsSkill
- e2e-runbooksSkill
- e2e-testingSkill
- embedded-c-arduinoSkill
- frontend-designSkill
- g-code-3d-printingSkill
- github-opsSkill
- git-workflowSkill
- golang-patternsSkill
- home-assistantSkill
- java-coding-standardsSkill
- jetbrains-ide-opsSkill
- jira-integrationSkill
- keycloak-patternsSkill
- kicadSkill
- markdown-writerSkill
- mongodb-patternsSkill
- nextjs-app-router-patternsSkill
- node-backend-patternsSkill
- observability-and-loggingSkill
- obsidianSkill
- performance-optimizationSkill
- postgres-patternsSkill
- powershellSkill
- project-trackingSkill
- python-patternsSkill
- pytorch-patternsSkill
- react-patternsSkill
- researchSkill
- review-duplicationSkill
- security-reviewSkill
- seoSkill
- soap-webservicesSkill
- springboot-patternsSkill
- tdd-workflowSkill
- unitySkill
- web-accessibilitySkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. 0 are common, 13 are distinctive, and 4 are very specific to this project.
0
Common
Most of the 12 edited versions we read keep these.
13
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
Use this skill when the request involves boundaries, domain-centric design, refactoring tightly coupled services, or decoupling application …
- Distinctive: line 52
Use cases (application layer): Orchestrate domain behavior and workflow steps.
- Distinctive: line 91
Use case class/function receives ports via constructor/arguments.
- Distinctive: line 129
Use feature-first organization with explicit boundaries:
- Distinctive: line 164
Use the same boundary rules across ecosystems.
- Distinctive: line 168
Use cases: classes/functions with constructor/argument injection.
- Very specific: line 175
Use cases: plain classes (Spring @Service is optional, not required).
- Very specific: line 180
Use cases: classes with constructor injection (Koin/Dagger/Spring/manual).
- Very specific: line 185
Use cases: structs with interface fields plus explicit New...
- Very specific: line 193
Use cases reading directly from req, res, or queue metadata.
- Distinctive: line 206
Keep old adapters, but make them delegate to the new use case.
- Distinctive: line 207
Add tests around the new boundary (unit + adapter integration).
- Distinctive: line 213
No big-bang rewrites: migrate per feature slice and preserve behavior with characterization tests.
- Distinctive: line 224
Use-case unit tests: test orchestration with fakes or stubs for outbound ports, asserting business outcomes and port interactions.
- Distinctive: line 251
Every external dependency is represented by an outbound port.
- Distinctive: line 253
Use immutable transformations (return new values/entities instead of mutating shared state).
- Distinctive: line 256
Use cases are testable with simple in-memory fakes for ports.
“Common” is measured: kept by at least 6 in 10 of the 12 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Hexagonal Architecture
Hexagonal architecture (Ports and Adapters) keeps business logic independent from frameworks, transport, and persistence details. The core app depends on abstract ports, and adapters implement those ports at the edges.
This skill is the architecture authority the coding-standards hub defers to for its Architecture section.
Language baselines the examples assume, current as of September 2026: TypeScript 5 on Node.js 24 LTS, Java 21 LTS, Kotlin 2.2, and Go 1.25.
When to activate
- Building new features where long-term maintainability and testability matter.
- Refactoring layered or framework-heavy code where domain logic is mixed with I/O concerns.
- Supporting multiple interfaces for the same use case (HTTP, CLI, queue workers, cron jobs).
- Replacing infrastructure (database, external APIs, message bus) without rewriting business rules.
Use this skill when the request involves boundaries, domain-centric design, refactoring tightly coupled services, or decoupling application logic from specific libraries.
When not to activate
- The HTTP or GraphQL contract at the edge: use
api-design. - Runtime-specific handler, service, and repository code: use
node-backend-patternsorspringboot-patterns. - Language-neutral service concerns such as idempotency, retries, and outbox: use
backend-patterns. - Schema, index, and query work behind the outbound adapter: use
postgres-patternsorspringboot-patterns. - The shared engineering floor of SOLID, naming, and error handling: use
coding-standards. - A one-off script or a prototype whose whole lifetime is a week. The indirection costs more than it returns.
Reference map
| Task | Open |
| A complete vertical slice in TypeScript, from port to composition root | references/typescript-example.md |
Core Concepts
- Domain model: Business rules and entities/value objects. No framework imports.
- Use cases (application layer): Orchestrate domain behavior and workflow steps.
- Inbound ports: Contracts describing what the application can do (commands/queries/use-case interfaces).
- Outbound ports: Contracts for dependencies the application needs (repositories, gateways, event publishers, clock, UUID, etc.).
- Adapters: Infrastructure and delivery implementations of ports (HTTP controllers, DB repositories, queue consumers, SDK wrappers).
- Composition root: Single wiring location where concrete adapters are bound to use cases.
Outbound port interfaces usually live in the application layer (or in domain only when the abstraction is truly domain-level), while infrastructure adapters implement them.
Dependency direction is always inward:
- Adapters -> application/domain
- Application -> port interfaces (inbound/outbound contracts)
- Domain -> domain-only abstractions (no framework or infrastructure dependencies)
- Domain -> nothing external
How It Works
Step 1: Model a use case boundary
Define a single use case with a clear input and output DTO. Keep transport details (Express req, GraphQL context,
job payload wrappers) outside this boundary.
Step 2: Define outbound ports first
Identify every side effect as a port:
- persistence (
UserRepositoryPort) - external calls (
BillingGatewayPort) - cross-cutting (
LoggerPort,ClockPort)
Ports should model capabilities, not technologies.
Step 3: Implement the use case with pure orchestration
Use case class/function receives ports via constructor/arguments. It validates application-level invariants, coordinates domain rules, and returns plain data structures.
Step 4: Build adapters at the edge
- Inbound adapter converts protocol input to use-case input.
- Outbound adapter maps app contracts to concrete APIs/ORM/query builders.
- Mapping stays in adapters, not inside use cases.
Step 5: Wire everything in a composition root
Instantiate adapters, then inject them into use cases. Keep this wiring centralized to avoid hidden service-locator behavior.
Step 6: Test per boundary
- Unit test use cases with fake ports.
- Integration test adapters with real infra dependencies.
- E2E test user-facing flows through inbound adapters.
Architecture Diagram
flowchart LR
Client["Client (HTTP/CLI/Worker)"] --> InboundAdapter["Inbound Adapter"]
InboundAdapter -->|"calls"| UseCase["UseCase (Application Layer)"]
UseCase -->|"uses"| OutboundPort["OutboundPort (Interface)"]
OutboundAdapter["Outbound Adapter"] -->|"implements"| OutboundPort
OutboundAdapter --> ExternalSystem["DB/API/Queue"]
UseCase --> DomainModel["DomainModel"]Suggested Module Layout
Use feature-first organization with explicit boundaries:
src/
features/
orders/
domain/
Order.ts
OrderPolicy.ts
application/
ports/
inbound/
CreateOrder.ts
outbound/
OrderRepositoryPort.ts
PaymentGatewayPort.ts
use-cases/
CreateOrderUseCase.ts
adapters/
inbound/
http/
createOrderRoute.ts
outbound/
postgres/
PostgresOrderRepository.ts
stripe/
StripePaymentGateway.ts
composition/
ordersContainer.tsMulti-Language Mapping
Use the same boundary rules across ecosystems. Only the syntax and the wiring style change.
- TypeScript/JavaScript
- Ports:
application/ports/*as interfaces/types. - Use cases: classes/functions with constructor/argument injection.
- Adapters:
adapters/inbound/*,adapters/outbound/*. - Composition: explicit factory/container module (no hidden globals).
- Ports:
- Java
- Packages:
domain,application.port.in,application.port.out,application.usecase,adapter.in,adapter.out. - Ports: interfaces in
application.port.*. - Use cases: plain classes (Spring
@Serviceis optional, not required). - Composition: Spring config or a manual wiring class, keeping wiring out of domain and use-case classes.
- Packages:
- Kotlin
- Modules/packages mirror the Java split (
domain,application.port,application.usecase,adapter). - Ports: Kotlin interfaces.
- Use cases: classes with constructor injection (Koin/Dagger/Spring/manual).
- Composition: module definitions or dedicated composition functions, never a service locator.
- Modules/packages mirror the Java split (
- Go
- Packages:
internal/<feature>/domain,application,adapters/inbound,adapters/outbound. - Ports: small interfaces declared in the consuming
applicationpackage, not in a separateportspackage. - Use cases: structs with interface fields plus explicit
New...constructors. - Composition: wire in
cmd/<app>/main.go(or dedicated wiring package), keep constructors explicit.
- Packages:
Anti-Patterns to Avoid
- Domain entities importing ORM models, web framework types, or SDK clients.
- Use cases reading directly from
req,res, or queue metadata. - Returning database rows directly from use cases without domain/application mapping.
- Letting adapters call each other directly instead of flowing through use-case ports.
- Spreading dependency wiring across many files with hidden global singletons.
Migration Playbook
- Pick one vertical slice (single endpoint/job) with frequent change pain.
- Extract a use-case boundary with explicit input/output types.
- Introduce outbound ports around existing infrastructure calls.
- Move orchestration logic from controllers/services into the use case.
- Keep old adapters, but make them delegate to the new use case.
- Add tests around the new boundary (unit + adapter integration).
- Repeat slice by slice, and avoid full rewrites.
Refactoring Existing Systems
- Strangler approach: keep current endpoints, route one use case at a time through new ports/adapters.
- No big-bang rewrites: migrate per feature slice and preserve behavior with characterization tests.
- Facade first: wrap legacy services behind outbound ports before replacing internals.
- Composition freeze: centralize wiring early so new dependencies do not leak into domain/use-case layers.
- Slice selection rule: prioritize high-churn, low-blast-radius flows first.
- Rollback path: keep a reversible toggle or route switch per migrated slice until production behavior is verified.
Testing Guidance (Same Hexagonal Boundaries)
- Domain tests: test entities/value objects as pure business rules (no mocks, no framework setup).
- Use-case unit tests: test orchestration with fakes or stubs for outbound ports, asserting business outcomes and port interactions.
- Outbound adapter contract tests: define shared contract suites at port level and run them against each adapter implementation.
- Inbound adapter tests: verify protocol mapping (HTTP/CLI/queue payload to use-case input and output/error mapping back to protocol).
- Adapter integration tests: run against real infrastructure (DB/API/queue) for serialization, schema/query behavior, retries, and timeouts.
- End-to-end tests: cover critical user journeys through inbound adapter -> use case -> outbound adapter.
- Refactor safety: add characterization tests before extraction, and keep them until the new boundary behavior is equivalent.
Related skills
coding-standardsfor the shared engineering floor this skill supplies the architecture section of.api-designfor the contract the inbound adapter exposes.backend-patternsfor idempotency, retries, and outbox behaviour inside the application layer.node-backend-patterns,springboot-patterns,python-patterns, andgolang-patternsfor the adapter code.tdd-workflowfor the test discipline that makes the boundaries worth having.
Checklist
- Domain and use-case layers import only internal types and ports.
- Every external dependency is represented by an outbound port.
- Validation occurs at boundaries (inbound adapter + use-case invariants).
- Use immutable transformations (return new values/entities instead of mutating shared state).
- Errors are translated across boundaries (infra errors -> application/domain errors).
- Composition root is explicit and easy to audit.
- Use cases are testable with simple in-memory fakes for ports.
- Refactoring starts from one vertical slice with behavior-preserving tests.
- Language/framework specifics stay in adapters, never in domain rules.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

