hexagonal-architecture

Implements TypeScript ports and adapters with dependency inversion and domain isolation.

Updated May 18, 2024
One-click install
npx skills add https://github.com/joshhornby/dotfiles --skill hexagonal-architecture-joshhornby
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hexagonal-architecture
Source: https://github.com/joshhornby/dotfiles/tree/main/.claude/skills/hexagonal-architecture
Command: npx skills add https://github.com/joshhornby/dotfiles --skill hexagonal-architecture-joshhornby

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Business logic often becomes tangled with frameworks, databases, and transport protocols, making code untestable and adapter swaps painful. This Skill enforces hexagonal (ports and adapters) architecture so domain code stays pure and external systems connect only through owned interfaces. ## Core Features & Use Cases - Port and Adapter Design: Defines driving and driven ports as TypeScript interfaces named by business purpose, with thin adapters translating between domain types and technology-specific types. - Dependency Injection and Composition: Wires dependencies via function parameters at a composition root, with no DI container required. - Testing Strategy: Prioritizes use-case tests with in-memory fakes over mocks, plus integration tests for driven adapters and a swappability test to validate boundaries. - Use Case: When building a TypeScript backend that has explicitly adopted hexagonal architecture, use this Skill to structure a new feature — domain function, application-owned repository port, Drizzle adapter, and a thin route handler — with tests that run without a database. ## Quick Start Apply the hexagonal-architecture skill to design the ports, adapters, and use case for a new order placement feature in my TypeScript project.

Frequently Asked Questions about hexagonal-architecture

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement hexagonal architecture in TypeScript?

Define driving ports as interfaces named for the business capability, implement them with use case factories that take driven ports as parameters, and write thin adapters that translate between domain types and technology types. Wire everything at a composition root near the executable entrypoint.

How should I name ports and interfaces in hexagonal architecture?

Name ports by business purpose, not technology: use intention names like ForPlacingOrders for driving ports and role nouns like OrderRepository or PaymentGateway for driven ports. Avoid I prefixes, Port or Impl suffixes, and any name that breaks when an adapter is swapped.

Should I use fakes or mocks when testing use cases?

Use in-memory fakes that implement the real port interface and maintain state. Fakes break at compile time when the interface changes and test behavior rather than call sequences, while mocks couple tests to incidental call order.

When should I not apply hexagonal architecture?

Do not apply it to projects that have not explicitly opted in, to simple CRUD endpoints with no business rules, or to stable code that rarely changes. The skill explicitly warns against inferring hexagonal architecture from a generic adapter, interface, or test seam.

How do I introduce hexagonal architecture into an existing codebase?

Use the strangler fig approach: extract one tangled feature at a time by pulling business rules into pure domain functions, defining an application-owned port, wrapping existing database access in an adapter, and proving the boundary with a fake-based use case test before migrating further.

Where do cross-cutting concerns like logging and transactions belong?

Authentication, technical telemetry, transactions, and error formatting live in adapters. Authorization rules live in the domain, and business-significant observations go through a severity-free driven probe port or domain events, never a raw logger in domain code.