/ddd-skills:ddd-api-designerfrom ddd-skills
Designs REST APIs from a DDD domain model with CQRS command/query separation, PO-DO-DTO-VO data object conversion chain, unified response format, OpenAPI/Swagger generation, BFF pattern, API versioning, and security controls.
Ships in ddd-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
从领域模型到 REST API 的完整设计指南:CQRS 读写分离、四层数据对象转换链(PO→DO→DTO→VO)、统一响应格式、BFF 多端适配、版本管理与安全设计。
| ✅ ALWAYS use when | ❌ Skip when |
|---|---|
| API 设计、REST API、接口设计 | 内部工具无外部消费者 |
| DTO/VO 设计、数据对象转换 | GraphQL/gRPC 项目 |
| BFF / Backend for Frontend | 无领域模型时 → domain-designer |
| OpenAPI / Swagger / API 文档 | 简单 CRUD 无 DDD |
| API 版本管理 / 安全设计 | 纯 gRPC 微服务(用 protobuf IDL) |
| 需要将 DDD 聚合暴露为 REST API | 快速原型不关心 API 规范 |
Command(写)动词驱动,Query(读)资源驱动:
| 维度 | Command | Query |
|---|---|---|
| HTTP Method | POST/PUT/DELETE | GET |
| URL 动词 | 需要(confirm, cancel) | 不需要 |
| 请求体 | Command 对象 | 仅查询参数 |
| DTO 分离 | 独立 Command DTO | 独立 Query DTO |
| 幂等性 | 必须实现 | 天然幂等 |
| 缓存 | 从不缓存 | ETag, max-age |
| 响应 | 创建的资源摘要 | 数据 DTO / 列表 |
原则:Command DTO 和 Query DTO 始终分开定义。子资源嵌套最多 2 层。详见 references/patterns/cqrs-api-design.md
| 对象 | 层 | 职责 | 可见性 |
|---|---|---|---|
| PO | Infrastructure | ORM 映射,数据库结构对应 | 内部 |
| DO | Domain | 充血模型,含业务行为 | 内部 |
| DTO | Interface/App | 跨层跨服务数据传输 | 半内部 |
| VO | Interface | 页面专用展示数据 | 外部 |
读方向:PO→DO→DTO→VO;写方向:VO→DTO→Command→DO→PO。 一个 DO 可按场景转换为多个 DTO(详情 DTO、摘要 DTO 等),Controller 不直接返回领域对象。详见 references/examples-ref/data-object-transformation.md
| 规则 | 示例 |
|---|---|
| 名词复数 | /orders ✓ |
| Kebab-case | /order-history ✓ |
| 最大 2 层嵌套 | /orders/{id}/items |
| 写动词后缀 | /orders/{id}/confirm |
| 查询参数 | ?status=PAID&page=1 |
| 无 URL 动词 | ❌ GET /getOrders → GET /orders |
HTTP Status:201 Created(创建)、200 OK(查询/更新)、204 No Content(删除)、400(校验/业务)、404(未找到)、409(并发冲突)、429(限流)、500(内部错误)。详见 references/security/api-naming-conventions.md
成功:{ "code": 0, "message": "success", "data": T } — 201/200/204
错误:{ "code": 40001, "message": "...", "detail": "...", "requestId": "req-xxx" } — 400/404/409/429/500
Response wrapper Result<T> 包含 code + message + data + requestId。错误响应绝不返回堆栈信息。详见 references/examples-ref/unified-response-format.md
每前端一个 BFF(Web/iOS/MiniApp),职责:
与 API Gateway 区别:BFF 做视图聚合(页面级),Gateway 做路由+限流(服务级)。 BFF 不直接访问数据库,不包含业务逻辑。详见 references/patterns/BFF-design-pattern.md
| 策略 | 示例 | 推荐度 |
|---|---|---|
| URL Path ★ | /api/v1/orders → /api/v2/orders | ★★★★★ |
| Request Header | Accept: vnd.company.v2+json | ★★★☆☆ |
| Query Param | /api/orders?version=2 | ★★☆☆☆ |
推荐 URL Path:直观、CDN 友好、Swagger 兼容。迁移流程:v1 → v1+v2 → v2 only → v1 sunset(410 Gone)。详见 references/migration/api-versioning-strategies.md
四层安全模型:
DTO 暴露枚举→string code | Command/Query DTO 混用→分开 | null 安全→处理 Optional | VO 透传 DB 字段→视图定制 | 幂等缺失→Idempotency-Key | 错误透传堆栈→requestId | 深层嵌套→≤2 层 | 领域对象序列化→经 DTO/VO
| Question | Answer |
|---|---|
| DO 和 DTO 字段一样能复用吗? | 不能。DO 含行为,DTO 纯数据,演化方向不同。 |
| 所有 API 都要统一响应格式? | 是,仅文件下载、204 可例外。 |
| 错误码怎么设计? | 5 位数字:首位类别+后两位 HTTP+末三位具体错误。 |
| 何时需要 BFF? | 多前端平台或前端需组合多服务数据。 |
| 子资源最多嵌套几层? | 最多 2 层,超 2 层说明聚合边界有问题。 |
| Controller 中能放业务逻辑吗? | 不能,只做协议转换。 |
CQRS API REST endpoint design PO DO DTO VO data object transformation unified response format BFF Backend for Frontend OpenAPI Swagger API versioning API security command query separation Result<T> response wrapper input validation rate limiting idempotency pagination design
📍 当前:
ddd-api-designer— Step 4: API 设计与数据转换
Step 1 (awesome) → Step 2 (selector) → Step 3 (架构落地) → Step 4 (领域+CQRS+API) → Step 5 (审查) → Step 6 (辅助) → Step 7 (文档)
↑
⭐ ddd-api-designer: 领域模型 → REST API
← 上一站: hand off to ddd-domain-designer skill — 先有领域模型再设计 API(Install: npx skills add full-stack-skills/ddd-skills --skill ddd-domain-designer).
→ 下一站: hand off to ddd-code-reviewer skill — 审查 API 设计合规性(Install: npx skills add full-stack-skills/ddd-skills --skill ddd-code-reviewer).
🔗 相关: hand off to ddd-cqrs-architecture skill — CQRS 深入(Install: npx skills add full-stack-skills/ddd-skills --skill ddd-cqrs-architecture) | ddd-architecture-doc skill — OpenAPI 文档输出(Install: npx skills add full-stack-skills/ddd-skills --skill ddd-architecture-doc).
核心原则:Command 和 Query 分开设计。牢记 PO→DO→DTO→VO 四层转换链,DTO 与领域对象解耦,VO 与数据库结构解耦。
agents/openai.yaml (opens in a new tab)examples/01-BFF-aggregation-example.md (opens in a new tab)examples/02-api-version-migration.md (opens in a new tab)examples/03-inventory-api-design.md (opens in a new tab)examples/04-notification-api-design.md (opens in a new tab)examples/05-openapi-codegen-example.md (opens in a new tab)examples/06-order-api-design.md (opens in a new tab)examples/07-payment-api-design.md (opens in a new tab)examples/08-product-api-design.md (opens in a new tab)examples/09-search-api-design.md (opens in a new tab)examples/10-user-api-design.md (opens in a new tab)references/architecture/clean-ddd-hexagonal-hexagonal.md (opens in a new tab)references/architecture/partme-16-service-data-view.md (opens in a new tab)references/examples-ref/api-error-handling.md (opens in a new tab)references/examples-ref/data-object-transformation.md (opens in a new tab)references/examples-ref/event-driven-api.md (opens in a new tab)references/examples-ref/unified-response-format.md (opens in a new tab)references/migration/api-versioning-strategies.md (opens in a new tab)references/patterns/BFF-design-pattern.md (opens in a new tab)references/patterns/cqrs-api-design.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
16 skills in this plugin
/ddd-architecture-awesomeProvides comprehensive guidance for Domain-Driven Design (DDD) concepts, strategic design, tactical design, and architecture patterns. Includes DDD applicability assessment, Pattern Boundaries table (what each pattern is and is NOT), Complexity Ladder (when to adopt each level), Core Concepts quick reference with Entity/ValueObject/Aggregate patterns, full architecture landscape overview, anti-patterns with fixes, multi-language reference implementations, and complete primary source references. Use when the user asks about DDD basics, needs to understand DDD concepts, evaluates DDD applicability, or wants an introduction to domain-driven design./ddd-architecture-cleanComprehensive guidance for Clean Architecture (整洁架构) — Robert C. Martin's Clean Architecture with Enterprise Business Rules, Use Cases, Interface Adapters, and Frameworks layers. Covers core entities, use case interactors, dependency rules, and full implementation steps with Java/Spring Boot examples. Use when user asks about Clean Architecture, 整洁架构, Robert Martin, Uncle Bob, use case driven architecture, or needs to implement DDD with clean architecture./ddd-architecture-colaComprehensive guidance for COLA v5 Architecture (菱形架构) — Alibaba's COLA framework with adapter/application/domain/infrastructure layers. Covers full project scaffolding, architecture validation (cola-creator + cola-validator combined), dependency rule checking with ArchUnit, CQRS integration, and multi-module Maven/Gradle project generation. Use when user asks about COLA architecture, 菱形架构, cola-creator, cola-validator, 创建 COLA 项目, or needs Alibaba DDD framework.Generated from the plugin's indexed repository (full-stack-skills/ddd-skills) — no native marketplace selected
npx claudepluginhub p/full-statck-skills-ddd-skillsOther plugins' skills for the same job