| name | hexagonal-ports-adapters |
| description | Use when implementing hexagonal architecture / ports and adapters: domain core isolated from delivery and infrastructure mechanisms, inbound and outbound ports, adapters for external interfaces, dependency inversion, and testable business logic. |
Hexagonal Architecture / Ports and Adapters
Use this skill to make business logic independent of delivery mechanisms and infrastructure.
Fit
Use when domain logic is valuable, tests are brittle due to delivery/infrastructure coupling, or adapters change often.
Avoid if the system is a tiny CRUD wrapper where abstraction would be ceremony.
Agent Workflow
- Read
graphify-out/GRAPH_REPORT.md.
- Run
graphify query "hexagonal architecture ports adapters domain operational coupling".
- Identify the core domain/application use case.
- Define inbound and outbound ports around it.
- Move delivery/infrastructure-specific code to adapters.
- Test the core through ports without infrastructure.
Target Shape
codebase/
core/
domain/
application/
ports/
inbound-port
outbound-port
adapters/
inbound/external-interface/
inbound/operator-interface/
outbound/persistence/
outbound/messaging/
Implementation Rules
- Core owns domain and application behavior.
- Inbound adapters translate external requests into use-case calls.
- Outbound adapters implement core-defined ports for persistence, messaging, time, IDs, and external APIs.
- Dependencies point inward: adapters reference core, core does not reference adapters.
- Use dependency injection/composition at the edge.
Migration Steps
- Pick one use case entangled with delivery or persistence infrastructure.
- Extract its input/output contracts and port interfaces into core.
- Move business decisions into application/domain.
- Wrap existing persistence/integration code as an outbound adapter.
- Wire adapters in the composition root.
- Add core tests with fake outbound ports.
Verification
graphify explain "core" should show no outbound adapter or infrastructure references.
- Search core paths for delivery, persistence, messaging, filesystem, environment, or platform dependencies.
- Test core without starting external infrastructure.
Output Contract
Return: core boundary, ports, adapters, composition root change, tests, and remaining coupling.