Agent skill

Hexagonal Architecture

by affaan-m in affaan-m/ECC

设计、实现并重构端口与适配器系统,具有清晰的领域边界、依赖反转以及跨 TypeScript、Java、Kotlin 和 Go 服务的可测试用例编排。

MITAuto-check passedMobile

Install Hexagonal Architecture

skills CLI
$ npx skills add affaan-m/ECC --skill hexagonal-architecture -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install affaan-m/ECC hexagonal-architecture --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/affaan-m/ECC.git skills-src && mkdir -p .claude/skills && cp -r skills-src/docs/zh-CN/skills/hexagonal-architecture .claude/skills/hexagonal-architecture && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
hexagonal-architecture
GitHub stars
276k
Token cost
~1.6k tokens
SKILL.md length
140 words
Files
1
Skills in repo
673
Repo updated
First seen
Licence
MIT

At a glance

设计、实现并重构端口与适配器系统,具有清晰的领域边界、依赖反转以及跨 TypeScript、Java、Kotlin 和 Go 服务的可测试用例编排。

  • Works in 7 steps: 选择一个垂直切片(单个端点/任务),该切片频繁变更且带来痛苦。 → 提取具有显式输入/输出类型的用例边界。 → 围绕现有基础设施调用引入出站端口。 → …
  • Tasks that involve Android development
  • SKILL.md covers 适用场景, 核心概念, 工作原理 and 架构图, plus 7 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Hexagonal Architecture is an agent skill from affaan-m/ECC. 设计、实现并重构端口与适配器系统,具有清晰的领域边界、依赖反转以及跨 TypeScript、Java、Kotlin 和 Go 服务的可测试用例编排。

Its SKILL.md is about 1.6k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Mobile, covering Android development. It works with TypeScript, Java and Kotlin. The repository describes itself as: The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond. The licence is MIT.

When your agent uses it

  • Tasks that involve Android development

Example prompts

  • “/hexagonal-architecture”

Workflow steps

7 steps, taken from the first numbered list in SKILL.md.

  1. 选择一个垂直切片(单个端点/任务),该切片频繁变更且带来痛苦。
  2. 提取具有显式输入/输出类型的用例边界。
  3. 围绕现有基础设施调用引入出站端口。
  4. 将编排逻辑从控制器/服务移动到用例中。
  5. 保留旧适配器,但使其委托给新用例。
  6. 围绕新边界添加测试(单元测试 + 适配器集成测试)。
  7. 逐个切片重复;避免完全重写。

What it can do on your machine

Read from SKILL.md and the folder at commit ef648e0. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript and mermaid).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Hexagonal Architecture loads about 1.6k tokens when it runs. Until then it costs about 24 tokens; SKILL.md has 140 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~24
When it runs · the whole SKILL.md, loaded when a task matches
~1.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from affaan-m/ECC at commit ef648e0, republished under its MIT licence (© affaan-m). 140 words, ~1,622 tokens.

Download SKILL.mdSave it as .claude/skills/hexagonal-architecture/SKILL.md (or your agent's skills folder).
name
hexagonal-architecture
description
设计、实现并重构端口与适配器系统,具有清晰的领域边界、依赖反转以及跨 TypeScript、Java、Kotlin 和 Go 服务的可测试用例编排。
origin
ECC

六边形架构

六边形架构(端口与适配器)使业务逻辑独立于框架、传输层和持久化细节。核心应用依赖于抽象端口,而适配器在边缘实现这些端口。

适用场景

  • 构建需要长期可维护性和可测试性的新功能。
  • 重构分层或框架密集型代码,其中领域逻辑与I/O关注点混杂。
  • 为同一用例支持多种接口(HTTP、CLI、队列工作器、定时任务)。
  • 替换基础设施(数据库、外部API、消息总线)而无需重写业务规则。

当需求涉及边界、领域驱动设计、重构紧耦合服务,或将应用逻辑与特定库解耦时,使用此技能。

核心概念

  • 领域模型:业务规则和实体/值对象。无框架导入。
  • 用例(应用层):编排领域行为和工作流步骤。
  • 入站端口:描述应用能力的契约(命令/查询/用例接口)。
  • 出站端口:应用所需依赖的契约(仓库、网关、事件发布器、时钟、UUID等)。
  • 适配器:端口的基础设施和交付实现(HTTP控制器、数据库仓库、队列消费者、SDK封装器)。
  • 组合根:将具体适配器绑定到用例的单一连接位置。

出站端口接口通常位于应用层(仅当抽象真正属于领域层时才位于领域层),而基础设施适配器实现它们。

依赖方向始终向内:

  • 适配器 -> 应用/领域
  • 应用 -> 端口接口(入站/出站契约)
  • 领域 -> 仅领域抽象(无框架或基础设施依赖)
  • 领域 -> 无外部依赖

工作原理

步骤1:建模用例边界

定义具有清晰输入和输出DTO的单个用例。将传输细节(Express req、GraphQL context、任务负载包装器)保持在此边界之外。

步骤2:首先定义出站端口

将每个副作用识别为端口:

  • 持久化(UserRepositoryPort)
  • 外部调用(BillingGatewayPort)
  • 横切关注点(LoggerPort、ClockPort)

端口应建模能力,而非技术。

步骤3:使用纯编排实现用例

用例类/函数通过构造函数/参数接收端口。它验证应用层不变量,协调领域规则,并返回纯数据结构。

步骤4:在边缘构建适配器
  • 入站适配器将协议输入转换为用例输入。
  • 出站适配器将应用契约映射到具体API/ORM/查询构建器。
  • 映射保持在适配器中,而非用例内部。
步骤5:在组合根中连接所有组件

实例化适配器,然后将其注入用例。保持此连接集中化,以避免隐藏的服务定位器行为。

步骤6:按边界测试
  • 使用伪造端口对用例进行单元测试。
  • 使用真实基础设施依赖对适配器进行集成测试。
  • 通过入站适配器对面向用户的流程进行端到端测试。

架构图

mermaid
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"]

建议的模块布局

使用以功能为先的组织方式,并带有显式边界:

text
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 示例

端口定义
typescript
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 }>;
}
用例
typescript
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,
    };
  }
}
出站适配器
typescript
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;
  }
}
组合根
typescript
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);
};

多语言映射

在不同生态系统中使用相同的边界规则;仅语法和连接方式发生变化。

  • TypeScript/JavaScript
    • 端口:application/ports/* 作为接口/类型。
    • 用例:带有构造函数/参数注入的类/函数。
    • 适配器:adapters/inbound/*、adapters/outbound/*。
    • 组合:显式工厂/容器模块(无隐藏全局变量)。
  • Java
    • 包:domain、application.port.in、application.port.out、application.usecase、adapter.in、adapter.out。
    • 端口:application.port.* 中的接口。
    • 用例:普通类(Spring @Service 是可选的,非必需)。
    • 组合:Spring配置或手动连接类;将连接逻辑保持在领域/用例类之外。
  • Kotlin
    • 模块/包镜像Java的拆分(domain、application.port、application.usecase、adapter)。
    • 端口:Kotlin接口。
    • 用例:带有构造函数注入的类(Koin/Dagger/Spring/手动)。
    • 组合:模块定义或专用组合函数;避免服务定位器模式。
  • Go
    • 包:internal/<feature>/domain、application、ports、adapters/inbound、adapters/outbound。
    • 端口:由消费应用包拥有的小型接口。
    • 用例:带有接口字段和显式 New... 构造函数的结构体。
    • 组合:在 cmd/<app>/main.go 中连接(或专用连接包),保持构造函数显式。

应避免的反模式

  • 领域实体导入ORM模型、Web框架类型或SDK客户端。
  • 用例直接从 req、res 或队列元数据读取。
  • 从用例直接返回数据库行,未经领域/应用映射。
  • 让适配器直接相互调用,而非通过用例端口流转。
  • 将依赖连接分散到多个文件中,使用隐藏的全局单例。

迁移手册

  1. 选择一个垂直切片(单个端点/任务),该切片频繁变更且带来痛苦。
  2. 提取具有显式输入/输出类型的用例边界。
  3. 围绕现有基础设施调用引入出站端口。
  4. 将编排逻辑从控制器/服务移动到用例中。
  5. 保留旧适配器,但使其委托给新用例。
  6. 围绕新边界添加测试(单元测试 + 适配器集成测试)。
  7. 逐个切片重复;避免完全重写。
重构现有系统
  • 绞杀者模式:保留当前端点,一次将一个用例路由到新的端口/适配器。
  • 无大爆炸式重写:按功能切片迁移,并通过特征化测试保持行为。
  • 先建外观:在替换内部实现之前,将遗留服务包装在出站端口后面。
  • 组合冻结:尽早集中连接,使新依赖不会泄漏到领域/用例层。
  • 切片选择规则:优先处理高变更频率、低影响范围的流程。
  • 回滚路径:为每个迁移的切片保留可逆开关或路由切换,直到生产行为得到验证。

测试指南(相同的六边形边界)

  • 领域测试:将实体/值对象作为纯业务规则进行测试(无模拟,无框架设置)。
  • 用例单元测试:使用出站端口的伪造/桩件测试编排;断言业务结果和端口交互。
  • 出站适配器契约测试:在端口级别定义共享契约套件,并针对每个适配器实现运行。
  • 入站适配器测试:验证协议映射(HTTP/CLI/队列负载到用例输入,以及输出/错误映射回协议)。
  • 适配器集成测试:针对真实基础设施(数据库/API/队列)运行,测试序列化、模式/查询行为、重试和超时。
  • 端到端测试:覆盖关键用户旅程,通过入站适配器 -> 用例 -> 出站适配器。
  • 重构安全性:在提取之前添加特征化测试;保持它们直到新边界行为稳定且等价。

最佳实践清单

  • 领域和应用层仅导入内部类型和端口。
  • 每个外部依赖都由一个出站端口表示。
  • 验证发生在边界处(入站适配器 + 用例不变量)。
  • 使用不可变转换(返回新值/实体,而非修改共享状态)。
  • 错误在边界间进行转换(基础设施错误 -> 应用/领域错误)。
  • 组合根是显式的且易于审计。
  • 用例可通过简单的内存伪造端口进行测试。
  • 重构从具有行为保持测试的一个垂直切片开始。
  • 语言/框架特定内容保持在适配器中,绝不进入领域规则。

© affaan-m, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in docs/zh-CN/skills/hexagonal-architecture of affaan-m/ECC.

Open the folder on GitHubat commit ef648e0

Compare with similar skills

Hexagonal Architecture next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Hexagonal Architecture compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Hexagonal Architecture this skillaffaan-m/ECC276k—~1.6kAutomated safety check: PassMIT
Build Teaql Appteaql/teaql-agent-kit2.8k—~4.6kAutomated safety check: PassMIT
Test Revieweraxelixlabs/axelix148—~3.2kAutomated safety check: PassLGPL-3.0
Test Writeraxelixlabs/axelix148—~2.2kAutomated safety check: PassLGPL-3.0
Hexagonal Architectureyamcodes/arkenv1454 repos~2.9kAutomated safety check: PassMIT
Corvus Java Evaluatorcorvus-dotnet/Corvus.JsonSchema199—~1.6kAutomated safety check: PassApache-2.0

Similar skills

  • Build Teaql App

    teaql/teaql-agent-kit

    Build or change a TeaQL application in Java, Rust, Go, Swift, Python, C/.NET, or TypeScript, including Kotlin/JVM applications that consume Java-generated libraries.

    2.8k GitHub stars~4.6k tokensUpdated 12 days ago
    MobileAuto-check passed
  • Test Reviewer

    axelixlabs/axelix

    Reviews test code in GitHub pull requests for isolation, public-API contract coverage, AAA structure, and correct exception assertions.

    148 GitHub stars~3.2k tokensUpdated yesterday
    MobileAuto-check passed
  • Test Writer

    axelixlabs/axelix

    Writes new tests for Axelix source code (Java, Kotlin, TypeScript, JavaScript) that follow the project's testing standards — public-API contract coverage, test isolation, given/when/then structure…

    148 GitHub stars~2.2k tokensUpdated yesterday
    MobileAuto-check passed
  • Hexagonal Architecture

    yamcodes/arkenv

    Design, implement, and refactor Ports & Adapters systems with clear domain boundaries, dependency inversion, and testable use-case orchestration across TypeScript, Java, Kotlin, and Go services.

    145 GitHub starsUsed in 4 repos~2.9k tokens
    MobileAuto-check passed
  • Corvus Java Evaluator

    corvus-dotnet/Corvus.JsonSchema

    Work on the Java port of the V5 standalone schema evaluator (src-java/corvus-json-schema, Maven artifact io.github.corvus-dotnet:corvus-json-schema): loader, compiler, the ASM bytecode generator…

    199 GitHub stars~1.6k tokensUpdated today
    MobileAuto-check passed
  • Simulator Audio E2E

    hyochan/react-native-nitro-sound

    Build and run repeatable react-native-nitro-sound recorder/player regression tests on an iOS Simulator or Android emulator, with explicit virtual-device selection, microphone permission, Maestro…

    961 GitHub stars~1.1k tokensUpdated 10 days ago
    MobileAuto-check passed

More from affaan-m/ECC

All 673 skills in this repo
  • Skill Stocktake

    affaan-m/ECC

    Audits your installed Claude skills and commands for quality, with a quick mode for recently changed skills and a full mode that evaluates all of them through subagents.

    276k GitHub starsUsed in 5 repos~1.9k tokens
    Auto-check passed
  • Ingests, indexes, searches, edits and monitors video, audio and live streams through the VideoDB Python SDK, returning stream links, clips and timestamps.

    276k GitHub starsUsed in 3 repos~3.5k tokens
    Auto-check: notes
  • Rules Distillation

    affaan-m/ECC

    Scans installed skills for principles that recur across them and proposes rule-file changes: append, revise, add a section, create a file or leave as covered.

    276k GitHub starsUsed in 2 repos~2.3k tokens
    Auto-check passed
  • Builds DRAFT counterparty agreements from one markdown template and a small JSON spec per party, with clauses picked by the party's role.

    276k GitHub stars~2.9k tokensUpdated 4 days ago
    Auto-check passed
  • Measures whether agents actually follow a skill, rule or agent definition by generating scenarios at three strictness levels and scoring tool-call traces.

    276k GitHub starsUsed in 1 repo~623 tokens
    Auto-check passed
  • Instinct-based learning system that observes sessions via hooks, creates atomic instincts with confidence scoring, and evolves them into skills/commands/agents.

    276k GitHub stars~3.5k tokensUpdated 4 days ago
    Auto-check passed

Categories

Questions about Hexagonal Architecture

What does Hexagonal Architecture do?

设计、实现并重构端口与适配器系统,具有清晰的领域边界、依赖反转以及跨 TypeScript、Java、Kotlin 和 Go 服务的可测试用例编排。. Hexagonal Architecture is an agent skill from affaan-m/ECC.

When should I use Hexagonal Architecture?

Hexagonal Architecture fits situations like: tasks that involve Android development.

How do I install Hexagonal Architecture in Claude Code?

Run `npx skills add affaan-m/ECC --skill hexagonal-architecture -a claude-code`. Or copy the skill folder (docs/zh-CN/skills/hexagonal-architecture in affaan-m/ECC) into .claude/skills/hexagonal-architecture in your project. Claude Code loads it when a task matches its description.

How do I install Hexagonal Architecture in Codex?

Run `npx skills add affaan-m/ECC --skill hexagonal-architecture -a codex`. Or copy the skill folder (docs/zh-CN/skills/hexagonal-architecture in affaan-m/ECC) into .agents/skills/hexagonal-architecture in your project. Codex loads it when a task matches its description.

Can I use Hexagonal Architecture in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add affaan-m/ECC --skill hexagonal-architecture -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/hexagonal-architecture, .gemini/skills/hexagonal-architecture, .github/skills/hexagonal-architecture and .opencode/skills/hexagonal-architecture in your project.

What does Hexagonal Architecture need to run?

SKILL.md names no scripts, command-line tools or credentials: Hexagonal Architecture is instructions for the agent only.

Does Hexagonal Architecture access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Hexagonal Architecture safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Hexagonal Architecture use?

Hexagonal Architecture is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Hexagonal Architecture use?

About 1.6k tokens (SKILL.md is roughly 6.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Hexagonal Architecture?

Skills that share tags, products or a category with Hexagonal Architecture: Build Teaql App (teaql/teaql-agent-kit, 2.8k stars), Test Reviewer (axelixlabs/axelix, 148 stars), Test Writer (axelixlabs/axelix, 148 stars) and Hexagonal Architecture (yamcodes/arkenv, 145 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Hexagonal Architecture?

affaan-m (a GitHub user) maintains it in affaan-m/ECC, which has 275,546 GitHub stars. The repository holds 673 skills in this directory. The repository was last updated on October 5, 2026.

Source: affaan-m/ECC on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.