帮助开发者理解六边形架构,分离业务边界并管理外部依赖关系。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "hexagonal-architecture" 技能: 1. 下载 https://raw.githubusercontent.com/affaan-m/ECC/main/docs/ja-JP/skills/hexagonal-architecture/SKILL.md 2. 保存为 ~/.claude/skills/hexagonal-architecture/SKILL.md 3. 装好后重载技能,告诉我可以用了
请用六边形架构为一个电商订单系统设计核心领域、输入输出端口,以及数据库和支付网关适配器,并说明各层职责。
一份清晰的架构设计说明,包含领域模型、端口定义、适配器划分与职责边界。
我有一个把业务逻辑、数据库访问和第三方 API 调用混在一起的用户服务。请给出按六边形架构重构的步骤、目录结构和示例代码。
一套可执行的重构方案,展示如何拆分核心业务、端口接口与外部适配器。
基于六边形架构,为一个库存管理系统制定测试方案,覆盖领域层单元测试、端口契约测试和适配器集成测试。
一份分层测试方案,说明不同测试类型的目标、范围和示例用例。
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.
Use this skill when the request involves boundaries, domain-centric design, refactoring tightly coupled services, or decoupling application logic from specific libraries.
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:
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.
Identify every side effect as a port:
UserRepositoryPort)BillingGatewayPort)LoggerPort, ClockPort)Ports should model capabilities, not technologies.
Use case class/function receives ports via constructor/arguments. It validates application-level invariants, coordinates domain rules, and returns plain data structures.
Instantiate adapters, then inject them into use cases. Keep this wiring centralized to avoid hidden service-locator behavior.
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"]
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/
…
帮助开发者为代码代理配置性能优化、安全防护与研究优先工作流。
提供数据库迁移、回滚与零停机发布的最佳实践指导,适用于多种 ORM 与 SQL 数据库。
通过双评审智能体对结果进行对抗式校验,提升输出发布前的可靠性
帮助你掌握地道 Rust 模式、所有权与并发实践,编写安全高性能应用。
基于 C++ Core Guidelines 编写、审查并重构更安全现代的 C++ 代码。
为 Claude Code 会话提供系统化校验流程,帮助检查结果正确性与质量。