Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

hexagonal-architecture

БесплатноБез исполняемых скриптовНе проверен

Use when the user or project explicitly adopts hexagonal (ports and adapters) architecture — a README, CLAUDE.md, or ADR that says so is the opt-in. Once a…

citypaulот citypaul★ 764 звезды на GitHub

Об этом скилле

Hexagonal Architecture (Ports & Adapters)

This skill applies only to projects that have opted in to hexagonal architecture. Do not apply these patterns to projects that use a different architecture. For introducing hex arch into an existing codebase incrementally, see resources/incremental-adoption.md.

Before You Write Code

Read this section as instructions; the rest of the skill explains why.

A third-party SDK's client type is never a port. OrdersApiClient, SmtpClient, PushClient, a Stripe client — anything exported by a vendor package or by the repo's SDK folder (src/lib/, vendor/, node_modules) — is outside the hexagon, and so is every file that imports it, including with import type and including the SDK's DTO types. A deps object whose fields are SDK client types has no ports, however many fakes the tests pass in. Structural compatibility between an SDK client and the interface you need is not a reason to skip the adapter.

Adding a feature in an opted-in codebase — in this order; resources/worked-example.md shows the finished shape:

  1. Put the business rule (time windows, filters, who is addressed, subject lines and message text, truncation) in a pure inside function that takes domain types and now as values; an adapter receives finished values and only translates them to the SDK's shape.
  2. Declare the ports the use case needs as exported interfaces inside, beside the use case: driven ports as role nouns (OrderRepository, ReceiptSender, PaymentGateway) whose methods use your own domain types, never the SDK's DTOs; the driving port as For<Verb>ing<Noun> (ForPlacingOrders, ForSendingReceipts), implemented by create<Capability>(deps) where deps holds only ports and now.
  3. Write one adapter per driven port that imports the SDK and translates its shapes to the port's types, and a driving adapter (route, CLI, queue) that parses input and calls the driving port.
  4. Wire SDK client → adapter → use case in the composition root only (src/index.ts, main.ts, or composition/). The root keeps taking SDK clients or configuration from its caller and builds the adapters itself; do not change its public signature to take ports.
  5. Test the use case through its driving port with hand-written in-memory fakes of the driven ports; test each adapter against the SDK separately.

Changing a use case that still imports an SDK directly — a file the README admits predates the architecture, or any inside file with an import from the SDK folder. In an opted-in repo, porting every SDK dependency of a file you touch is part of the change, not scope creep, and it is a behaviour-preserving REFACTOR step taken with the existing tests green before the RED for the new behaviour — the request's wording sets what changes, the architecture sets how. First extract all of its SDK dependencies behind ports (step 2–4 above) and give it its driving port interface if it has none — an exported function is not a driving port; declare ForSendingReceipts (or the equivalent) and return it from createReceiptSender(deps) — then make the requested change against the ports. Extracting only the dependency the request names leaves the next swap touching the use case again. Before you finish, read the use case's imports: if any still names the SDK folder or an SDK client type, you are not done — extract it too. If the request says "just do it where the SDK call is", the rule still goes inside; say why in one sentence.

Where new files go when no restructuring is requested: keep the repo's layout for the inside, but adapters and fakes are your code, not the vendor's. Put them beside the feature they serve (src/<feature>/ports.ts, src/<feature>/adapters.ts, src/<feature>/testing/) or in an adapters/ folder — never in the folder that holds SDK stand-ins, where an adapter reads as one more third-party client.

Use-case tests use fakes, not mocks. A use-case test contains no vi.fn, vi.mock, or vi.spyOn and imports nothing from the SDK folder; a recording fake (sent: readonly Receipt[]) is how you observe a notifier or mailer. When you touch an existing use-case test that mocks SDK clients, replace those mocks with fakes of the ports you just declared rather than extending them.

For domain modeling (entities, value objects, aggregates, ubiquitous language), load the domain-driven-design skill. Hex arch and DDD are complementary but independent — hex arch provides structural isolation (how the outside connects), DDD provides the domain model (what lives in the center). A project may use one without the other.

Use the structure-codebase skill when designing or changing the physical source tree. For an opted-in hexagonal backend it groups by business capability or bounded context first, then makes the provider-free inside visible under that owner's hexagon/, with concrete driving/driven technology and reusable test interactors outside. If physical restructuring

Полный SKILL.md на GitHub

Установить hexagonal-architecture в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

resources/cqrs-lite.mdresources/cross-cutting-concerns.mdresources/greenfield-sequence.mdresources/incremental-adoption.mdresources/references.mdresources/testing-hex-arch.mdresources/worked-example.md

FAQ

Что делает скилл hexagonal-architecture?

Use when the user or project explicitly adopts hexagonal (ports and adapters) architecture — a README, CLAUDE.md, or ADR that says so is the opt-in. Once a project has opted in, load this for every code change in it, not only architecture work — a new feature, a transport or SDK swap, a bug fix, or a small business-rule change to a function that still calls an SDK directly; load it alongside tdd, never instead of it, and follow its Before You Write Code section before editing. Implements TypeScript ports, driving/driven adapters, dependency inversion, and domain isolation. Do NOT infer hexagonal architecture from a generic adapter, interface, test seam, or isolation request in a project that has not opted in.

Как установить скилл hexagonal-architecture?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл hexagonal-architecture запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить hexagonal-architecture с