Loading...
Loading...
Compare original and translation side by side
cat skills/_shared/protocols/ux-protocol.md 2>/dev/null || truecat skills/_shared/protocols/input-validation.md 2>/dev/null || truecat skills/_shared/protocols/tool-efficiency.md 2>/dev/null || truecat .production-grade.yaml 2>/dev/null || echo "No config — using defaults"cat .forgewright/codebase-context.md 2>/dev/null || truecat skills/_shared/protocols/ux-protocol.md 2>/dev/null || truecat skills/_shared/protocols/input-validation.md 2>/dev/null || truecat skills/_shared/protocols/tool-efficiency.md 2>/dev/null || truecat .production-grade.yaml 2>/dev/null || echo "No config — using defaults"cat .forgewright/codebase-context.md 2>/dev/null || truecat .forgewright/settings.md 2>/dev/null || echo "No settings — using Standard"| Mode | Behavior |
|---|---|
| Express | Fully autonomous. Design APIs using best practices. Report decisions in output. |
| Standard | Surface API style choice (REST vs GraphQL vs gRPC), pagination strategy, and versioning approach. Auto-resolve everything else. |
| Thorough | Present full API design document before implementation. Walk through resource modeling and endpoint design. Show error code taxonomy. Ask about consumer needs. |
| Meticulous | Walk through each resource individually. User reviews endpoint signatures, request/response schemas, and error responses. Show API mock for consumer validation. |
cat .forgewright/settings.md 2>/dev/null || echo "No settings — using Standard"| 模式 | 行为 |
|---|---|
| 快速模式 | 完全自主操作,采用最佳实践设计API,在输出中说明决策依据。 |
| 标准模式 | 明确API风格选择(REST vs GraphQL vs gRPC)、分页策略和版本控制方案,自动解决其他所有问题。 |
| 全面模式 | 在实施前提交完整的API设计文档,讲解资源建模和端点设计,展示错误代码分类体系,并询问消费者需求。 |
| 精细模式 | 逐个讲解每个资源,由用户审核端点签名、请求/响应架构和错误响应,提供API模拟版本供消费者验证。 |
.forgewright/codebase-context.mdbrownfield.forgewright/codebase-context.mdbrownfieldsolution-architectsolution-architect| Category | Inputs | Behavior if Missing |
|---|---|---|
| Critical | Domain entities, user stories, or feature requirements | STOP — cannot design API without knowing the domain |
| Degraded | Existing API patterns (brownfield), consumer requirements, scale expectations | WARN — will design using best practices as defaults |
| Optional | Authentication strategy (from | Continue — use sensible defaults |
| 类别 | 输入内容 | 缺失时的行为 |
|---|---|---|
| 关键项 | 领域实体、用户故事或功能需求 | 停止工作——不了解领域则无法设计API |
| 降级项 | 现有API模式(遗留系统)、消费者需求、规模预期 | 发出警告——将采用最佳实践作为默认方案进行设计 |
| 可选项 | 认证策略(来自 | 继续工作——使用合理的默认值 |
digraph api_designer {
rankdir=TB;
"API Request" [shape=doublecircle];
"Phase 1: Domain Modeling" [shape=box];
"Phase 2: Resource Design" [shape=box];
"Phase 3: Endpoint Specification" [shape=box];
"Phase 4: Error & Edge Cases" [shape=box];
"Phase 5: Documentation & Governance" [shape=box];
"Done" [shape=doublecircle];
"API Request" -> "Phase 1: Domain Modeling";
"Phase 1: Domain Modeling" -> "Phase 2: Resource Design";
"Phase 2: Resource Design" -> "Phase 3: Endpoint Specification";
"Phase 3: Endpoint Specification" -> "Phase 4: Error & Edge Cases";
"Phase 4: Error & Edge Cases" -> "Phase 5: Documentation & Governance";
"Phase 5: Documentation & Governance" -> "Done";
}digraph api_designer {
rankdir=TB;
"API Request" [shape=doublecircle];
"Phase 1: Domain Modeling" [shape=box];
"Phase 2: Resource Design" [shape=box];
"Phase 3: Endpoint Specification" [shape=box];
"Phase 4: Error & Edge Cases" [shape=box];
"Phase 5: Documentation & Governance" [shape=box];
"Done" [shape=doublecircle];
"API Request" -> "Phase 1: Domain Modeling";
"Phase 1: Domain Modeling" -> "Phase 2: Resource Design";
"Phase 2: Resource Design" -> "Phase 3: Endpoint Specification";
"Phase 3: Endpoint Specification" -> "Phase 4: Error & Edge Cases";
"Phase 4: Error & Edge Cases" -> "Phase 5: Documentation & Governance";
"Phase 5: Documentation & Governance" -> "Done";
}Execute sequentially: Design REST/GraphQL endpoint specifications following Phase 3. Write to api/openapi/.
Execute sequentially: Design error taxonomy and edge cases following Phase 4. Write to api/errors/.Execute sequentially: Design REST/GraphQL endpoint specifications following Phase 3. Write to api/openapi/.
Execute sequentially: Design error taxonomy and edge cases following Phase 4. Write to api/errors/./users/orders/orders/{id}/items/countries/categories/orders/{id}/cancelIdempotency-Key/users/orders/orders/{id}/items/countries/categories/orders/{id}/cancelIdempotency-Key/users/orders/user/order/line-items/lineItems/line_items/orders/{id}/cancel/cancelOrder/users/{id}/orders/users/{id}/orders/{oid}/items/{iid}/reviews/orders?status=pending&sort=-created_at{
"data": { ... }, // Single resource or array
"meta": { // Pagination, totals
"total": 150,
"page": 1,
"perPage": 20
},
"links": { // HATEOAS navigation
"self": "/api/v1/orders?page=1",
"next": "/api/v1/orders?page=2"
}
}| Strategy | Pros | Cons | Use When |
|---|---|---|---|
| Cursor-based | Consistent with concurrent writes, efficient | Can't jump to page N | Default for production APIs. Most common pattern. |
| Offset/Limit | Simple, familiar, can jump to any page | Inconsistent with concurrent writes, slow at large offsets | Admin dashboards, internal tools |
| Keyset | Efficient for large datasets, consistent | Requires sortable unique column | Time-series data, logs |
?cursor=abc123&limit=20next_cursor/users/orders/user/order/line-items/lineItems/line_items/orders/{id}/cancel/cancelOrder/users/{id}/orders/users/{id}/orders/{oid}/items/{iid}/reviews/orders?status=pending&sort=-created_at{
"data": { ... }, // 单个资源或数组
"meta": { // 分页、总数信息
"total": 150,
"page": 1,
"perPage": 20
},
"links": { // HATEOAS导航
"self": "/api/v1/orders?page=1",
"next": "/api/v1/orders?page=2"
}
}| 策略 | 优势 | 劣势 | 使用场景 |
|---|---|---|---|
| 基于游标 | 与并发写入兼容,性能高效 | 无法直接跳转到第N页 | 生产API的默认方案,最常用模式 |
| 偏移量/限制 | 简单易懂,可跳转到任意页面 | 与并发写入不兼容,大偏移量时性能慢 | 管理后台、内部工具 |
| 基于键集 | 大数据集下性能高效,一致性好 | 需要可排序的唯一列 | 时间序列数据、日志 |
?cursor=abc123&limit=20next_cursorIdempotency-Key| Header | Direction | Purpose |
|---|---|---|
| Request | Bearer token or API key |
| Request | Client-generated request tracking ID |
| Request | Prevent duplicate mutations |
| Both | |
| Response | Requests allowed per window |
| Response | Requests remaining in window |
| Response | Window reset time (Unix timestamp) |
| Response | Echo or server-generated trace ID |
/api/v1/users/api/v2/usersSunsetapi/openapi/Idempotency-Key| 请求头 | 方向 | 用途 |
|---|---|---|
| 请求 | Bearer令牌或API密钥 |
| 请求 | 客户端生成的请求跟踪ID |
| 请求 | 防止重复变更操作 |
| 双向 | |
| 响应 | 窗口期内允许的请求次数 |
| 响应 | 窗口期内剩余的请求次数 |
| 响应 | 窗口期重置时间(Unix时间戳) |
| 响应 | 回显或服务端生成的跟踪ID |
/api/v1/users/api/v2/usersSunsetapi/openapi/{
"error": {
"code": "VALIDATION_ERROR",
"message": "The request body contains invalid fields.",
"details": [
{
"field": "email",
"issue": "must be a valid email address",
"value": "not-an-email"
}
],
"requestId": "req_abc123",
"documentation": "https://docs.example.com/errors/VALIDATION_ERROR"
}
}| HTTP Status | Error Code | When |
|---|---|---|
| 400 | | Malformed JSON, missing required params |
| 400 | | Field validation failures (with |
| 401 | | Missing or invalid auth token |
| 403 | | Valid auth but insufficient permissions |
| 404 | | Resource doesn't exist |
| 409 | | Duplicate creation, stale update (optimistic locking) |
| 422 | | Valid format but business rule violation |
| 429 | | Too many requests (include |
| 500 | | Unexpected server error (never expose stack traces) |
| 503 | | Temporary outage (include |
ETagIf-Match{
"error": {
"code": "VALIDATION_ERROR",
"message": "请求体包含无效字段。",
"details": [
{
"field": "email",
"issue": "必须是有效的邮箱地址",
"value": "not-an-email"
}
],
"requestId": "req_abc123",
"documentation": "https://docs.example.com/errors/VALIDATION_ERROR"
}
}| HTTP状态码 | 错误代码 | 使用场景 |
|---|---|---|
| 400 | | JSON格式错误、缺失必填参数 |
| 400 | | 字段校验失败(包含 |
| 401 | | 缺失或无效的认证令牌 |
| 403 | | 认证有效但权限不足 |
| 404 | | 资源不存在 |
| 409 | | 重复创建、过期更新(乐观锁) |
| 422 | | 格式有效但违反业务规则 |
| 429 | | 请求次数过多(包含 |
| 500 | | 意外服务错误(绝不暴露堆栈跟踪) |
| 503 | | 临时服务中断(包含 |
ETagIf-Matchdocs/api/style-guide.md| Breaking ✗ | Non-Breaking ✓ |
|---|---|
| Removing a field from response | Adding a new optional field to response |
| Changing a field type | Adding a new endpoint |
| Removing an endpoint | Adding a new optional query parameter |
| Making an optional field required | Adding a new error code |
| Changing URL structure | Adding a new header |
CHANGELOG.mddocs/api/style-guide.md| 破坏性变更 ✗ | 非破坏性变更 ✓ |
|---|---|
| 从响应中移除字段 | 向响应中新增可选字段 |
| 变更字段类型 | 新增端点 |
| 移除端点 | 新增可选查询参数 |
| 将可选字段设为必填 | 新增错误代码 |
| 变更URL结构 | 新增请求头 |
CHANGELOG.mdapi/
├── openapi/
│ ├── openapi.yaml # Main OpenAPI 3.1 spec
│ └── components/
│ ├── schemas/ # Reusable JSON schemas
│ ├── responses/ # Standard error responses
│ └── parameters/ # Common query parameters
├── errors/
│ └── error-taxonomy.md # Error code reference
└── graphql/ # (if GraphQL chosen)
├── schema.graphql
└── resolvers.md
docs/api/
├── style-guide.md # API conventions and standards
├── versioning-policy.md # How versions are managed
└── migration-guides/ # Per-version migration docsapi/
├── openapi/
│ ├── openapi.yaml # 主OpenAPI 3.1规范
│ └── components/
│ ├── schemas/ # 可复用JSON架构
│ ├── responses/ # 标准错误响应
│ └── parameters/ # 通用查询参数
├── errors/
│ └── error-taxonomy.md # 错误代码参考文档
└── graphql/ # (若选择GraphQL)
├── schema.graphql
└── resolvers.md
docs/api/
├── style-guide.md # API规范与标准
├── versioning-policy.md # 版本管理策略
└── migration-guides/ # 各版本迁移文档.forgewright/api-designer/
├── domain-model.md # Entity relationship analysis
├── resource-inventory.md # URL inventory with methods
└── design-decisions.md # API design rationale.forgewright/api-designer/
├── domain-model.md # 实体关系分析
├── resource-inventory.md # URL清单及对应方法
└── design-decisions.md # API设计依据| Mistake | Fix |
|---|---|
Verbs in URLs ( | Use nouns + HTTP methods: |
Inconsistent naming ( | Pick one convention (camelCase recommended) and enforce everywhere |
| No pagination on list endpoints | EVERY list endpoint must paginate. Default: cursor-based, 20 items. |
| Generic error messages ("Something went wrong") | Specific codes + details: |
| Exposing internal IDs (auto-increment) | Use UUIDs or opaque IDs. Auto-increment leaks data volume. |
| No versioning from the start | Add |
| Inconsistent response envelope | Same wrapper for all endpoints: |
| Missing idempotency for mutations | Support |
| Deeply nested URLs (> 3 levels) | Flatten with query params: |
| No rate limiting | Every API needs rate limits. Document them. Return |
| 错误 | 修复方案 |
|---|---|
URL中使用动词( | 使用名词+HTTP方法: |
命名不一致( | 选择一种规范(推荐camelCase)并全局执行 |
| 列表端点未实现分页 | 所有列表端点必须分页,默认采用基于游标分页,每页20条 |
| 通用错误信息(“发生未知错误”) | 使用具体代码+详细信息:如 |
| 暴露内部ID(自增ID) | 使用UUID或不透明ID,自增ID会泄露数据量信息 |
| 初始阶段未做版本控制 | 从第一天起就添加 |
| 响应信封不一致 | 所有端点使用统一包装: |
| 变更操作未实现幂等性 | 对POST/PATCH端点支持 |
| URL嵌套过深(超过3级) | 使用查询参数扁平化: |
| 未设置速率限制 | 所有API都需要速率限制,需记录相关规则,返回 |