帮助开发者设计、实现并重构六边形架构系统,确保边界清晰且易于测试。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "hexagonal-architecture" 技能: 1. 下载 https://raw.githubusercontent.com/affaan-m/ECC/main/skills/hexagonal-architecture/SKILL.md 2. 保存为 ~/.claude/skills/hexagonal-architecture/SKILL.md 3. 装好后重载技能,告诉我可以用了
请为一个电商订单服务设计六边形架构,使用 TypeScript,列出领域模型、用例、端口、适配器和目录结构,并说明依赖方向。
得到完整的六边形架构设计方案,包括核心领域边界、接口定义和项目结构建议。
下面是一段耦合数据库与业务逻辑的 Java 控制器代码。请将其重构为六边形架构,拆分为用例、仓储端口和适配器,并给出重构后的代码示例与测试策略。
得到按端口与适配器分层的重构代码,以及可执行的单元测试与集成测试建议。
请用 Kotlin 为支付流程实现一个可测试的用例编排示例,要求体现依赖反转、输入输出模型、端口接口、失败处理,并附上单元测试示例。
得到清晰的用例编排实现示例,包含端口接口、错误处理方式和配套测试代码。
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/
…
通过双评审智能体对结果进行对抗式校验,提升输出发布前的可靠性
帮助设计或评估命令行工具与开发者 SDK 的架构、兼容性和使用体验