opencode-metis 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -0
- package/dist/cli.cjs +63 -0
- package/dist/mcp-server.cjs +51 -0
- package/dist/plugin.cjs +4 -0
- package/dist/worker.cjs +224 -0
- package/opencode/agent/the-analyst/feature-prioritization.md +66 -0
- package/opencode/agent/the-analyst/market-research.md +77 -0
- package/opencode/agent/the-analyst/project-coordination.md +81 -0
- package/opencode/agent/the-analyst/requirements-analysis.md +77 -0
- package/opencode/agent/the-architect/compatibility-review.md +138 -0
- package/opencode/agent/the-architect/complexity-review.md +137 -0
- package/opencode/agent/the-architect/quality-review.md +67 -0
- package/opencode/agent/the-architect/security-review.md +127 -0
- package/opencode/agent/the-architect/system-architecture.md +119 -0
- package/opencode/agent/the-architect/system-documentation.md +83 -0
- package/opencode/agent/the-architect/technology-research.md +85 -0
- package/opencode/agent/the-chief.md +79 -0
- package/opencode/agent/the-designer/accessibility-implementation.md +101 -0
- package/opencode/agent/the-designer/design-foundation.md +74 -0
- package/opencode/agent/the-designer/interaction-architecture.md +75 -0
- package/opencode/agent/the-designer/user-research.md +70 -0
- package/opencode/agent/the-meta-agent.md +155 -0
- package/opencode/agent/the-platform-engineer/ci-cd-pipelines.md +109 -0
- package/opencode/agent/the-platform-engineer/containerization.md +106 -0
- package/opencode/agent/the-platform-engineer/data-architecture.md +81 -0
- package/opencode/agent/the-platform-engineer/dependency-review.md +144 -0
- package/opencode/agent/the-platform-engineer/deployment-automation.md +81 -0
- package/opencode/agent/the-platform-engineer/infrastructure-as-code.md +107 -0
- package/opencode/agent/the-platform-engineer/performance-tuning.md +82 -0
- package/opencode/agent/the-platform-engineer/pipeline-engineering.md +81 -0
- package/opencode/agent/the-platform-engineer/production-monitoring.md +105 -0
- package/opencode/agent/the-qa-engineer/exploratory-testing.md +66 -0
- package/opencode/agent/the-qa-engineer/performance-testing.md +81 -0
- package/opencode/agent/the-qa-engineer/quality-assurance.md +77 -0
- package/opencode/agent/the-qa-engineer/test-execution.md +66 -0
- package/opencode/agent/the-software-engineer/api-development.md +78 -0
- package/opencode/agent/the-software-engineer/component-development.md +79 -0
- package/opencode/agent/the-software-engineer/concurrency-review.md +141 -0
- package/opencode/agent/the-software-engineer/domain-modeling.md +66 -0
- package/opencode/agent/the-software-engineer/performance-optimization.md +113 -0
- package/opencode/command/analyze.md +149 -0
- package/opencode/command/constitution.md +178 -0
- package/opencode/command/debug.md +194 -0
- package/opencode/command/document.md +178 -0
- package/opencode/command/implement.md +225 -0
- package/opencode/command/refactor.md +207 -0
- package/opencode/command/review.md +229 -0
- package/opencode/command/simplify.md +267 -0
- package/opencode/command/specify.md +191 -0
- package/opencode/command/validate.md +224 -0
- package/opencode/skill/accessibility-design/SKILL.md +566 -0
- package/opencode/skill/accessibility-design/checklists/wcag-checklist.md +435 -0
- package/opencode/skill/agent-coordination/SKILL.md +224 -0
- package/opencode/skill/api-contract-design/SKILL.md +550 -0
- package/opencode/skill/api-contract-design/templates/graphql-schema-template.md +818 -0
- package/opencode/skill/api-contract-design/templates/rest-api-template.md +417 -0
- package/opencode/skill/architecture-design/SKILL.md +160 -0
- package/opencode/skill/architecture-design/examples/architecture-examples.md +170 -0
- package/opencode/skill/architecture-design/template.md +749 -0
- package/opencode/skill/architecture-design/validation.md +99 -0
- package/opencode/skill/architecture-selection/SKILL.md +522 -0
- package/opencode/skill/architecture-selection/examples/adrs/001-example-adr.md +71 -0
- package/opencode/skill/architecture-selection/examples/architecture-patterns.md +239 -0
- package/opencode/skill/bug-diagnosis/SKILL.md +235 -0
- package/opencode/skill/code-quality-review/SKILL.md +337 -0
- package/opencode/skill/code-quality-review/examples/anti-patterns.md +629 -0
- package/opencode/skill/code-quality-review/reference.md +322 -0
- package/opencode/skill/code-review/SKILL.md +363 -0
- package/opencode/skill/code-review/reference.md +450 -0
- package/opencode/skill/codebase-analysis/SKILL.md +139 -0
- package/opencode/skill/codebase-navigation/SKILL.md +227 -0
- package/opencode/skill/codebase-navigation/examples/exploration-patterns.md +263 -0
- package/opencode/skill/coding-conventions/SKILL.md +178 -0
- package/opencode/skill/coding-conventions/checklists/accessibility-checklist.md +176 -0
- package/opencode/skill/coding-conventions/checklists/performance-checklist.md +154 -0
- package/opencode/skill/coding-conventions/checklists/security-checklist.md +127 -0
- package/opencode/skill/constitution-validation/SKILL.md +315 -0
- package/opencode/skill/constitution-validation/examples/CONSTITUTION.md +202 -0
- package/opencode/skill/constitution-validation/reference/rule-patterns.md +328 -0
- package/opencode/skill/constitution-validation/template.md +115 -0
- package/opencode/skill/context-preservation/SKILL.md +445 -0
- package/opencode/skill/data-modeling/SKILL.md +385 -0
- package/opencode/skill/data-modeling/templates/schema-design-template.md +268 -0
- package/opencode/skill/deployment-pipeline-design/SKILL.md +579 -0
- package/opencode/skill/deployment-pipeline-design/templates/pipeline-template.md +633 -0
- package/opencode/skill/documentation-extraction/SKILL.md +259 -0
- package/opencode/skill/documentation-sync/SKILL.md +431 -0
- package/opencode/skill/domain-driven-design/SKILL.md +509 -0
- package/opencode/skill/domain-driven-design/examples/ddd-patterns.md +688 -0
- package/opencode/skill/domain-driven-design/reference.md +465 -0
- package/opencode/skill/drift-detection/SKILL.md +383 -0
- package/opencode/skill/drift-detection/reference.md +340 -0
- package/opencode/skill/error-recovery/SKILL.md +162 -0
- package/opencode/skill/error-recovery/examples/error-patterns.md +484 -0
- package/opencode/skill/feature-prioritization/SKILL.md +419 -0
- package/opencode/skill/feature-prioritization/examples/rice-template.md +139 -0
- package/opencode/skill/feature-prioritization/reference.md +256 -0
- package/opencode/skill/git-workflow/SKILL.md +453 -0
- package/opencode/skill/implementation-planning/SKILL.md +215 -0
- package/opencode/skill/implementation-planning/examples/phase-examples.md +217 -0
- package/opencode/skill/implementation-planning/template.md +220 -0
- package/opencode/skill/implementation-planning/validation.md +88 -0
- package/opencode/skill/implementation-verification/SKILL.md +272 -0
- package/opencode/skill/knowledge-capture/SKILL.md +265 -0
- package/opencode/skill/knowledge-capture/reference/knowledge-capture.md +402 -0
- package/opencode/skill/knowledge-capture/reference.md +444 -0
- package/opencode/skill/knowledge-capture/templates/domain-template.md +325 -0
- package/opencode/skill/knowledge-capture/templates/interface-template.md +255 -0
- package/opencode/skill/knowledge-capture/templates/pattern-template.md +144 -0
- package/opencode/skill/observability-design/SKILL.md +291 -0
- package/opencode/skill/observability-design/references/monitoring-patterns.md +461 -0
- package/opencode/skill/pattern-detection/SKILL.md +171 -0
- package/opencode/skill/pattern-detection/examples/common-patterns.md +359 -0
- package/opencode/skill/performance-analysis/SKILL.md +266 -0
- package/opencode/skill/performance-analysis/references/profiling-tools.md +499 -0
- package/opencode/skill/requirements-analysis/SKILL.md +139 -0
- package/opencode/skill/requirements-analysis/examples/good-prd.md +66 -0
- package/opencode/skill/requirements-analysis/template.md +177 -0
- package/opencode/skill/requirements-analysis/validation.md +69 -0
- package/opencode/skill/requirements-elicitation/SKILL.md +518 -0
- package/opencode/skill/requirements-elicitation/examples/interview-questions.md +226 -0
- package/opencode/skill/requirements-elicitation/examples/user-stories.md +414 -0
- package/opencode/skill/safe-refactoring/SKILL.md +312 -0
- package/opencode/skill/safe-refactoring/reference/code-smells.md +347 -0
- package/opencode/skill/security-assessment/SKILL.md +421 -0
- package/opencode/skill/security-assessment/checklists/security-review-checklist.md +285 -0
- package/opencode/skill/specification-management/SKILL.md +143 -0
- package/opencode/skill/specification-management/readme-template.md +32 -0
- package/opencode/skill/specification-management/reference.md +115 -0
- package/opencode/skill/specification-management/spec.py +229 -0
- package/opencode/skill/specification-validation/SKILL.md +397 -0
- package/opencode/skill/specification-validation/reference/3cs-framework.md +306 -0
- package/opencode/skill/specification-validation/reference/ambiguity-detection.md +132 -0
- package/opencode/skill/specification-validation/reference/constitution-validation.md +301 -0
- package/opencode/skill/specification-validation/reference/drift-detection.md +383 -0
- package/opencode/skill/task-delegation/SKILL.md +607 -0
- package/opencode/skill/task-delegation/examples/file-coordination.md +495 -0
- package/opencode/skill/task-delegation/examples/parallel-research.md +337 -0
- package/opencode/skill/task-delegation/examples/sequential-build.md +504 -0
- package/opencode/skill/task-delegation/reference.md +825 -0
- package/opencode/skill/tech-stack-detection/SKILL.md +89 -0
- package/opencode/skill/tech-stack-detection/references/framework-signatures.md +598 -0
- package/opencode/skill/technical-writing/SKILL.md +190 -0
- package/opencode/skill/technical-writing/templates/adr-template.md +205 -0
- package/opencode/skill/technical-writing/templates/system-doc-template.md +380 -0
- package/opencode/skill/test-design/SKILL.md +464 -0
- package/opencode/skill/test-design/examples/test-pyramid.md +724 -0
- package/opencode/skill/testing/SKILL.md +213 -0
- package/opencode/skill/testing/examples/test-pyramid.md +724 -0
- package/opencode/skill/user-insight-synthesis/SKILL.md +576 -0
- package/opencode/skill/user-insight-synthesis/templates/research-plan-template.md +217 -0
- package/opencode/skill/user-research/SKILL.md +508 -0
- package/opencode/skill/user-research/examples/interview-questions.md +265 -0
- package/opencode/skill/user-research/examples/personas.md +267 -0
- package/opencode/skill/vibe-security/SKILL.md +654 -0
- package/package.json +45 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: api-contract-design
|
|
3
|
+
description: "REST and GraphQL API design patterns, OpenAPI/Swagger specifications, versioning strategies, and authentication patterns. Use when designing APIs, reviewing API contracts, evaluating API technologies, or implementing API endpoints."
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: opencode
|
|
6
|
+
metadata:
|
|
7
|
+
category: development
|
|
8
|
+
version: "1.0"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# API Contract Design
|
|
12
|
+
|
|
13
|
+
Roleplay as an API contract design specialist that creates consistent, evolvable APIs using contract-first design principles across REST, GraphQL, and hybrid approaches.
|
|
14
|
+
|
|
15
|
+
ApiContractDesign {
|
|
16
|
+
Activation {
|
|
17
|
+
When designing new REST or GraphQL APIs from scratch
|
|
18
|
+
When reviewing existing API contracts for consistency and best practices
|
|
19
|
+
When evaluating API technologies and frameworks
|
|
20
|
+
When implementing API versioning strategies
|
|
21
|
+
When designing authentication and authorization flows
|
|
22
|
+
When creating OpenAPI/Swagger specifications
|
|
23
|
+
When building developer-friendly API documentation
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
TechnologySelection {
|
|
27
|
+
Evaluate top-to-bottom. First match wins.
|
|
28
|
+
|
|
29
|
+
| If You Need | Choose | Rationale |
|
|
30
|
+
|-------------|--------|-----------|
|
|
31
|
+
| Public API with broad client support | REST | Widest tooling, caching, simplicity |
|
|
32
|
+
| Complex nested data with varied client needs | GraphQL | Client-controlled queries, reduces over-fetching |
|
|
33
|
+
| High-performance internal service communication | gRPC | Binary protocol, code generation, streaming |
|
|
34
|
+
| Real-time bidirectional communication | WebSocket | Persistent connection, push capability |
|
|
35
|
+
| Simple webhook/event delivery | REST + callbacks | Standard HTTP, easy to implement |
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
CorePrinciples {
|
|
39
|
+
ContractFirstDesign {
|
|
40
|
+
Define the API contract before implementation
|
|
41
|
+
Enables parallel development, clearer communication, and better documentation
|
|
42
|
+
|
|
43
|
+
DesignSequence {
|
|
44
|
+
1. IDENTIFY use cases and consumer needs
|
|
45
|
+
2. MODEL resources and their relationships
|
|
46
|
+
3. DEFINE operations (CRUD + custom actions)
|
|
47
|
+
4. SPECIFY request/response schemas
|
|
48
|
+
5. DOCUMENT error scenarios
|
|
49
|
+
6. VALIDATE with consumers before implementing
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
ConsistencyOverCleverness {
|
|
54
|
+
APIs should be predictable
|
|
55
|
+
Developers should guess how an endpoint works based on patterns elsewhere
|
|
56
|
+
|
|
57
|
+
ConsistencyChecklist:
|
|
58
|
+
- Naming conventions (plural nouns, kebab-case)
|
|
59
|
+
- Response envelope structure
|
|
60
|
+
- Error format across all endpoints
|
|
61
|
+
- Pagination approach
|
|
62
|
+
- Query parameter patterns
|
|
63
|
+
- Date/time formatting (ISO 8601)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
DesignForEvolution {
|
|
67
|
+
APIs must evolve without breaking existing consumers
|
|
68
|
+
Plan for change from day one
|
|
69
|
+
|
|
70
|
+
EvolutionStrategies:
|
|
71
|
+
- Additive changes only (new fields, endpoints)
|
|
72
|
+
- Deprecation with sunset periods
|
|
73
|
+
- Version negotiation (headers, URL paths)
|
|
74
|
+
- Backward compatibility testing
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
RESTPatterns {
|
|
79
|
+
ResourceModeling {
|
|
80
|
+
Resources represent business entities
|
|
81
|
+
URLs should reflect the resource hierarchy
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
GOOD:
|
|
85
|
+
GET /users # List users
|
|
86
|
+
POST /users # Create user
|
|
87
|
+
GET /users/{id} # Get user
|
|
88
|
+
PATCH /users/{id} # Partial update
|
|
89
|
+
DELETE /users/{id} # Delete user
|
|
90
|
+
GET /users/{id}/orders # User's orders (sub-resource)
|
|
91
|
+
|
|
92
|
+
AVOID:
|
|
93
|
+
GET /getUsers # Verbs in URLs
|
|
94
|
+
POST /createNewUser # Redundant verbs
|
|
95
|
+
GET /user-list # Inconsistent naming
|
|
96
|
+
POST /users/{id}/delete # Wrong HTTP method
|
|
97
|
+
```
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
HTTPMethodSemantics {
|
|
101
|
+
| Method | Usage | Idempotent | Safe |
|
|
102
|
+
|--------|-------|------------|------|
|
|
103
|
+
| GET | Retrieve resource(s) | Yes | Yes |
|
|
104
|
+
| POST | Create resource, trigger action | No | No |
|
|
105
|
+
| PUT | Replace entire resource | Yes | No |
|
|
106
|
+
| PATCH | Partial update | Yes | No |
|
|
107
|
+
| DELETE | Remove resource | Yes | No |
|
|
108
|
+
| OPTIONS | CORS preflight, capability discovery | Yes | Yes |
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
StatusCodeSelection {
|
|
112
|
+
Success:
|
|
113
|
+
- 200 OK: Successful GET, PUT, PATCH, DELETE
|
|
114
|
+
- 201 Created: Successful POST (include Location header)
|
|
115
|
+
- 202 Accepted: Async operation started
|
|
116
|
+
- 204 No Content: Success with no response body
|
|
117
|
+
|
|
118
|
+
ClientErrors:
|
|
119
|
+
- 400 Bad Request: Malformed request, validation failure
|
|
120
|
+
- 401 Unauthorized: Missing or invalid authentication
|
|
121
|
+
- 403 Forbidden: Authenticated but not authorized
|
|
122
|
+
- 404 Not Found: Resource doesn't exist
|
|
123
|
+
- 409 Conflict: State conflict (duplicate, version mismatch)
|
|
124
|
+
- 422 Unprocessable: Semantically invalid (business rule violation)
|
|
125
|
+
- 429 Too Many: Rate limit exceeded
|
|
126
|
+
|
|
127
|
+
ServerErrors:
|
|
128
|
+
- 500 Internal: Unexpected server error
|
|
129
|
+
- 502 Bad Gateway: Upstream service failure
|
|
130
|
+
- 503 Unavailable: Temporary overload or maintenance
|
|
131
|
+
- 504 Gateway Timeout: Upstream timeout
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
ErrorResponseFormat {
|
|
135
|
+
Standardize error responses across all endpoints:
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"error": {
|
|
140
|
+
"code": "VALIDATION_ERROR",
|
|
141
|
+
"message": "Request validation failed",
|
|
142
|
+
"details": [
|
|
143
|
+
{
|
|
144
|
+
"field": "email",
|
|
145
|
+
"code": "INVALID_FORMAT",
|
|
146
|
+
"message": "Email must be a valid email address"
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
"requestId": "req_abc123",
|
|
150
|
+
"timestamp": "2025-01-15T10:30:00Z",
|
|
151
|
+
"documentation": "https://api.example.com/docs/errors#VALIDATION_ERROR"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
PaginationPatterns {
|
|
158
|
+
OffsetBased {
|
|
159
|
+
Simple, not for large datasets
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
GET /users?offset=20&limit=10
|
|
163
|
+
|
|
164
|
+
Response:
|
|
165
|
+
{
|
|
166
|
+
"data": [...],
|
|
167
|
+
"pagination": {
|
|
168
|
+
"total": 150,
|
|
169
|
+
"offset": 20,
|
|
170
|
+
"limit": 10,
|
|
171
|
+
"hasMore": true
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
CursorBased {
|
|
178
|
+
Recommended for large datasets
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
GET /users?cursor=eyJpZCI6MTAwfQ&limit=10
|
|
182
|
+
|
|
183
|
+
Response:
|
|
184
|
+
{
|
|
185
|
+
"data": [...],
|
|
186
|
+
"pagination": {
|
|
187
|
+
"nextCursor": "eyJpZCI6MTEwfQ",
|
|
188
|
+
"prevCursor": "eyJpZCI6OTB9",
|
|
189
|
+
"hasMore": true
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
FilteringAndSorting {
|
|
197
|
+
```
|
|
198
|
+
FILTERING:
|
|
199
|
+
GET /users?status=active # Exact match
|
|
200
|
+
GET /users?created_after=2025-01-01 # Date range
|
|
201
|
+
GET /users?role=admin,moderator # Multiple values
|
|
202
|
+
GET /users?search=john # Full-text search
|
|
203
|
+
|
|
204
|
+
SORTING:
|
|
205
|
+
GET /users?sort=created_at # Ascending (default)
|
|
206
|
+
GET /users?sort=-created_at # Descending (prefix -)
|
|
207
|
+
GET /users?sort=status,-created_at # Multiple fields
|
|
208
|
+
|
|
209
|
+
FIELD SELECTION:
|
|
210
|
+
GET /users?fields=id,name,email # Sparse fieldsets
|
|
211
|
+
GET /users?expand=organization # Include related
|
|
212
|
+
```
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
GraphQLPatterns {
|
|
217
|
+
SchemaDesignPrinciples {
|
|
218
|
+
```graphql
|
|
219
|
+
# Use clear, descriptive type names
|
|
220
|
+
type User {
|
|
221
|
+
id: ID!
|
|
222
|
+
email: String!
|
|
223
|
+
displayName: String!
|
|
224
|
+
createdAt: DateTime!
|
|
225
|
+
|
|
226
|
+
# Relationships with clear naming
|
|
227
|
+
organization: Organization
|
|
228
|
+
orders(first: Int, after: String): OrderConnection!
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
# Use connections for paginated lists
|
|
232
|
+
type OrderConnection {
|
|
233
|
+
edges: [OrderEdge!]!
|
|
234
|
+
pageInfo: PageInfo!
|
|
235
|
+
totalCount: Int!
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
type OrderEdge {
|
|
239
|
+
node: Order!
|
|
240
|
+
cursor: String!
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
type PageInfo {
|
|
244
|
+
hasNextPage: Boolean!
|
|
245
|
+
hasPreviousPage: Boolean!
|
|
246
|
+
startCursor: String
|
|
247
|
+
endCursor: String
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
QueryDesign {
|
|
253
|
+
```graphql
|
|
254
|
+
type Query {
|
|
255
|
+
# Single resource by ID
|
|
256
|
+
user(id: ID!): User
|
|
257
|
+
|
|
258
|
+
# List with filtering and pagination
|
|
259
|
+
users(
|
|
260
|
+
filter: UserFilter
|
|
261
|
+
first: Int
|
|
262
|
+
after: String
|
|
263
|
+
orderBy: UserOrderBy
|
|
264
|
+
): UserConnection!
|
|
265
|
+
|
|
266
|
+
# Viewer pattern for current user
|
|
267
|
+
viewer: User
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
input UserFilter {
|
|
271
|
+
status: UserStatus
|
|
272
|
+
organizationId: ID
|
|
273
|
+
searchQuery: String
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
enum UserOrderBy {
|
|
277
|
+
CREATED_AT_ASC
|
|
278
|
+
CREATED_AT_DESC
|
|
279
|
+
NAME_ASC
|
|
280
|
+
NAME_DESC
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
MutationDesign {
|
|
286
|
+
```graphql
|
|
287
|
+
type Mutation {
|
|
288
|
+
# Use input types for complex mutations
|
|
289
|
+
createUser(input: CreateUserInput!): CreateUserPayload!
|
|
290
|
+
updateUser(input: UpdateUserInput!): UpdateUserPayload!
|
|
291
|
+
deleteUser(id: ID!): DeleteUserPayload!
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
input CreateUserInput {
|
|
295
|
+
email: String!
|
|
296
|
+
displayName: String!
|
|
297
|
+
organizationId: ID
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
# Payload types for consistent responses
|
|
301
|
+
type CreateUserPayload {
|
|
302
|
+
user: User
|
|
303
|
+
errors: [UserError!]!
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
type UserError {
|
|
307
|
+
field: String
|
|
308
|
+
code: String!
|
|
309
|
+
message: String!
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
NPlusOneQueryPrevention {
|
|
315
|
+
Strategies:
|
|
316
|
+
1. DataLoader pattern for batching
|
|
317
|
+
2. Query complexity analysis and limits
|
|
318
|
+
3. Depth limiting
|
|
319
|
+
4. Field-level cost calculation
|
|
320
|
+
5. Persisted queries for production
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
VersioningStrategies {
|
|
325
|
+
URLPathVersioning {
|
|
326
|
+
```
|
|
327
|
+
GET /v1/users
|
|
328
|
+
GET /v2/users
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Pros:
|
|
332
|
+
- Explicit and visible
|
|
333
|
+
- Easy to route in infrastructure
|
|
334
|
+
- Clear in logs and monitoring
|
|
335
|
+
|
|
336
|
+
Cons:
|
|
337
|
+
- URL pollution
|
|
338
|
+
- Harder to deprecate gracefully
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
HeaderVersioning {
|
|
342
|
+
```
|
|
343
|
+
GET /users
|
|
344
|
+
Accept: application/vnd.api+json; version=2
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Pros:
|
|
348
|
+
- Clean URLs
|
|
349
|
+
- Content negotiation friendly
|
|
350
|
+
- Easier partial versioning
|
|
351
|
+
|
|
352
|
+
Cons:
|
|
353
|
+
- Less visible
|
|
354
|
+
- Harder to test in browser
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
QueryParameterVersioning {
|
|
358
|
+
```
|
|
359
|
+
GET /users?api-version=2025-01-15
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Pros:
|
|
363
|
+
- Easy to test
|
|
364
|
+
- Visible in URLs
|
|
365
|
+
- Date-based versions are intuitive
|
|
366
|
+
|
|
367
|
+
Cons:
|
|
368
|
+
- Clutters query strings
|
|
369
|
+
- Easy to forget
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
RecommendedDualApproach {
|
|
373
|
+
1. Major versions in URL path: /v1/, /v2/
|
|
374
|
+
2. Minor versions via header: API-Version: 2025-01-15
|
|
375
|
+
3. Default to latest minor within major
|
|
376
|
+
4. Sunset headers for deprecation warnings
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
AuthenticationPatterns {
|
|
381
|
+
APIKeys {
|
|
382
|
+
Usage: Server-to-server, rate limiting, analytics
|
|
383
|
+
Transport: Header (Authorization: ApiKey xxx) or query param
|
|
384
|
+
|
|
385
|
+
Security:
|
|
386
|
+
- Rotate keys regularly
|
|
387
|
+
- Different keys for environments
|
|
388
|
+
- Scope keys to specific operations
|
|
389
|
+
- Never expose in client-side code
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
OAuth2OIDC {
|
|
393
|
+
Flows:
|
|
394
|
+
- Authorization Code + PKCE: Web apps, mobile apps
|
|
395
|
+
- Client Credentials: Server-to-server
|
|
396
|
+
- Device Code: CLI tools, smart TVs
|
|
397
|
+
|
|
398
|
+
TokenHandling:
|
|
399
|
+
- Short-lived access tokens (15-60 min)
|
|
400
|
+
- Refresh tokens for session extension
|
|
401
|
+
- Token introspection for validation
|
|
402
|
+
- Token revocation endpoint
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
JWTBestPractices {
|
|
406
|
+
```
|
|
407
|
+
CLAIMS:
|
|
408
|
+
{
|
|
409
|
+
"iss": "https://auth.example.com",
|
|
410
|
+
"sub": "user_123",
|
|
411
|
+
"aud": "api.example.com",
|
|
412
|
+
"exp": 1705320000,
|
|
413
|
+
"iat": 1705316400,
|
|
414
|
+
"scope": "read:users write:users"
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Security:
|
|
419
|
+
- Use asymmetric keys (RS256, ES256)
|
|
420
|
+
- Validate all claims
|
|
421
|
+
- Check token expiration
|
|
422
|
+
- Verify audience matches
|
|
423
|
+
- Keep tokens stateless when possible
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
OpenAPIPatterns {
|
|
428
|
+
SpecificationStructure {
|
|
429
|
+
```yaml
|
|
430
|
+
openapi: 3.1.0
|
|
431
|
+
info:
|
|
432
|
+
title: Example API
|
|
433
|
+
version: 1.0.0
|
|
434
|
+
description: API description with markdown support
|
|
435
|
+
contact:
|
|
436
|
+
name: API Support
|
|
437
|
+
url: https://example.com/support
|
|
438
|
+
|
|
439
|
+
servers:
|
|
440
|
+
- url: https://api.example.com/v1
|
|
441
|
+
description: Production
|
|
442
|
+
- url: https://api.staging.example.com/v1
|
|
443
|
+
description: Staging
|
|
444
|
+
|
|
445
|
+
security:
|
|
446
|
+
- bearerAuth: []
|
|
447
|
+
|
|
448
|
+
paths:
|
|
449
|
+
/users:
|
|
450
|
+
get:
|
|
451
|
+
operationId: listUsers
|
|
452
|
+
summary: List all users
|
|
453
|
+
tags: [Users]
|
|
454
|
+
# ... operation details
|
|
455
|
+
|
|
456
|
+
components:
|
|
457
|
+
schemas:
|
|
458
|
+
User:
|
|
459
|
+
type: object
|
|
460
|
+
required: [id, email]
|
|
461
|
+
properties:
|
|
462
|
+
id:
|
|
463
|
+
type: string
|
|
464
|
+
format: uuid
|
|
465
|
+
email:
|
|
466
|
+
type: string
|
|
467
|
+
format: email
|
|
468
|
+
```
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
ReusableComponents {
|
|
472
|
+
```yaml
|
|
473
|
+
components:
|
|
474
|
+
schemas:
|
|
475
|
+
# Reusable pagination
|
|
476
|
+
PaginationMeta:
|
|
477
|
+
type: object
|
|
478
|
+
properties:
|
|
479
|
+
total:
|
|
480
|
+
type: integer
|
|
481
|
+
page:
|
|
482
|
+
type: integer
|
|
483
|
+
perPage:
|
|
484
|
+
type: integer
|
|
485
|
+
|
|
486
|
+
# Reusable error
|
|
487
|
+
Error:
|
|
488
|
+
type: object
|
|
489
|
+
required: [code, message]
|
|
490
|
+
properties:
|
|
491
|
+
code:
|
|
492
|
+
type: string
|
|
493
|
+
message:
|
|
494
|
+
type: string
|
|
495
|
+
|
|
496
|
+
parameters:
|
|
497
|
+
# Reusable query params
|
|
498
|
+
PageParam:
|
|
499
|
+
name: page
|
|
500
|
+
in: query
|
|
501
|
+
schema:
|
|
502
|
+
type: integer
|
|
503
|
+
default: 1
|
|
504
|
+
minimum: 1
|
|
505
|
+
|
|
506
|
+
responses:
|
|
507
|
+
# Reusable responses
|
|
508
|
+
NotFound:
|
|
509
|
+
description: Resource not found
|
|
510
|
+
content:
|
|
511
|
+
application/json:
|
|
512
|
+
schema:
|
|
513
|
+
$ref: '#/components/schemas/Error'
|
|
514
|
+
```
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
BestPractices {
|
|
519
|
+
Do:
|
|
520
|
+
- Design APIs for consumers, not implementation convenience
|
|
521
|
+
- Use meaningful HTTP status codes
|
|
522
|
+
- Provide idempotency keys for non-idempotent operations
|
|
523
|
+
- Include rate limit headers (X-RateLimit-Limit, X-RateLimit-Remaining)
|
|
524
|
+
- Return Location header for created resources
|
|
525
|
+
- Support CORS properly for browser clients
|
|
526
|
+
- Document all error codes with resolution steps
|
|
527
|
+
- Version your API from day one
|
|
528
|
+
- Use HTTPS exclusively
|
|
529
|
+
- Implement request validation with clear error messages
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
AntiPatterns {
|
|
533
|
+
Avoid:
|
|
534
|
+
- Exposing internal implementation details (database IDs, stack traces)
|
|
535
|
+
- Breaking changes without versioning
|
|
536
|
+
- Inconsistent naming across endpoints
|
|
537
|
+
- Deeply nested URLs (more than 2 levels)
|
|
538
|
+
- Using GET for operations with side effects
|
|
539
|
+
- Returning different structures for success/error
|
|
540
|
+
- Ignoring backward compatibility
|
|
541
|
+
- Over-fetching in GraphQL without limits
|
|
542
|
+
- Authentication via query parameters (except OAuth callbacks)
|
|
543
|
+
- Mixing REST and RPC styles in the same API
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
## References
|
|
548
|
+
|
|
549
|
+
- [rest-api-template.md](templates/rest-api-template.md) - REST API specification template
|
|
550
|
+
- [graphql-schema-template.md](templates/graphql-schema-template.md) - GraphQL schema template
|