Token导航 LogoToken导航TokenDH.com
研究检索external-servicegithub未标认证来源可访问许可证需确认审计提醒

hexagonal-architecture六边形架构

Agent Skill

hexagonal-architecture 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

34,920

周安装

1,546

GitHub Stars

170,284

下载量

12,240
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:hexagonal-architecture(六边形架构)
来源仓库:https://github.com/affaan-m/everything-claude-code
仓库路径:skills/hexagonal-architecture
安装命令:
npx skills add https://github.com/affaan-m/everything-claude-code --skill hexagonal-architecture
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/affaan-m/everything-claude-code --skill hexagonal-architecture

简介

用于查找、检索和筛选相关信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中根据关键词快速定位候选结果。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装使用。
  • 安装前需确认权限范围、维护状态,避免触发联网或文件读写操作。
  • hexagonal-architecture 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

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.

When to Use

  • 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.

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.ts

TypeScript Example

Port definitions

export interface OrderRepositoryPort {
  save(order: Order): Promise<void>;
  findById(orderId: string): Promise<Order | null>;
}

export interface PaymentGatewayPort {
  authorize(input: { orderId: string; amountCents: number }): Promise<{ authorizationId: string }>;
}

Use case

type CreateOrderInput = {
  orderId: string;
  amountCents: number;
};

type CreateOrderOutput = {
  orderId: string;
  authorizationId: string;
};

export class CreateOrderUseCase {
  constructor(
    private readonly orderRepository: OrderRepositoryPort,
    private readonly paymentGateway: PaymentGatewayPort
  ) {}

  async execute(input: CreateOrderInput): Promise<CreateOrderOutput> {
    const order = Order.create({ id: input.orderId, amountCents: input.amountCents });

    const auth = await this.paymentGateway.authorize({
      orderId: order.id,
      amountCents: order.amountCents,
    });

    // markAuthorized returns a new Order instance; it does not mutate in place.
    const authorizedOrder = order.markAuthorized(auth.authorizationId);
    await this.orderRepository.save(authorizedOrder);

    return {
      orderId: order.id,
      authorizationId: auth.authorizationId,
    };
  }
}

Outbound adapter

export class PostgresOrderRepository implements OrderRepositoryPort {
  constructor(private readonly db: SqlClient) {}

  async save(order: Order): Promise<void> {
    await this.db.query(
      "insert into orders (id, amount_cents, status, authorization_id) values ($1, $2, $3, $4)",
      [order.id, order.amountCents, order.status, order.authorizationId]
    );
  }

  async findById(orderId: string): Promise<Order | null> {
    const row = await this.db.oneOrNone("select * from orders where id = $1", [orderId]);
    return row ? Order.rehydrate(row) : null;
  }
}

Composition root

export const buildCreateOrderUseCase = (deps: { db: SqlClient; stripe: StripeClient }) => {
  const orderRepository = new PostgresOrderRepository(deps.db);
  const paymentGateway = new StripePaymentGateway(deps.stripe);

  return new CreateOrderUseCase(orderRepository, paymentGateway);
};

Multi-Language Mapping

Use the same boundary rules across ecosystems; only syntax and 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).

  • 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 @Service is optional, not required). - Composition: Spring config or manual wiring class; keep wiring out of domain/use-case classes.

  • 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; avoid service locator patterns.

  • Go

- Packages: internal/<feature>/domain, application, ports, adapters/inbound, adapters/outbound. - Ports: small interfaces owned by the consuming application package. - Use cases: structs with interface fields plus explicit New... constructors. - Composition: wire in cmd/<app>/main.go (or dedicated wiring package), keep constructors explicit.

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

  1. Pick one vertical slice (single endpoint/job) with frequent change pain.
  2. Extract a use-case boundary with explicit input/output types.
  3. Introduce outbound ports around existing infrastructure calls.
  4. Move orchestration logic from controllers/services into the use case.
  5. Keep old adapters, but make them delegate to the new use case.
  6. Add tests around the new boundary (unit + adapter integration).
  7. Repeat slice-by-slice; 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/stubs for outbound ports; assert 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; keep them until new boundary behavior is stable and equivalent.

Best Practices 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.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

32.77%
按下载量换算4,011

Claude

30.9%
按下载量换算3,782

Cursor

18.51%
按下载量换算2,266

Gemini CLI

8.26%
按下载量换算1,011

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills