opencode-agile-agent 1.0.1
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 +71 -0
- package/bin/cli.js +434 -0
- package/bin/validate-templates.js +58 -0
- package/package.json +52 -0
- package/templates/.opencode/ARCHITECTURE.md +368 -0
- package/templates/.opencode/README.md +391 -0
- package/templates/.opencode/agents/api-designer.md +312 -0
- package/templates/.opencode/agents/backend-specialist.md +214 -0
- package/templates/.opencode/agents/code-archaeologist.md +260 -0
- package/templates/.opencode/agents/database-architect.md +212 -0
- package/templates/.opencode/agents/debugger.md +302 -0
- package/templates/.opencode/agents/developer.md +523 -0
- package/templates/.opencode/agents/devops-engineer.md +253 -0
- package/templates/.opencode/agents/documentation-writer.md +247 -0
- package/templates/.opencode/agents/explorer-agent.md +239 -0
- package/templates/.opencode/agents/feature-lead.md +302 -0
- package/templates/.opencode/agents/frontend-specialist.md +186 -0
- package/templates/.opencode/agents/game-developer.md +391 -0
- package/templates/.opencode/agents/mobile-developer.md +264 -0
- package/templates/.opencode/agents/orchestrator.md +463 -0
- package/templates/.opencode/agents/penetration-tester.md +256 -0
- package/templates/.opencode/agents/performance-optimizer.md +292 -0
- package/templates/.opencode/agents/pr-reviewer.md +468 -0
- package/templates/.opencode/agents/product-manager.md +225 -0
- package/templates/.opencode/agents/product-owner.md +264 -0
- package/templates/.opencode/agents/project-planner.md +248 -0
- package/templates/.opencode/agents/qa-automation-engineer.md +276 -0
- package/templates/.opencode/agents/security-auditor.md +260 -0
- package/templates/.opencode/agents/seo-specialist.md +266 -0
- package/templates/.opencode/agents/system-analyst.md +428 -0
- package/templates/.opencode/agents/test-engineer.md +229 -0
- package/templates/.opencode/config.template.json +129 -0
- package/templates/.opencode/rules/coding-standards.md +250 -0
- package/templates/.opencode/rules/git-conventions.md +149 -0
- package/templates/.opencode/skills/api-patterns/SKILL.md +162 -0
- package/templates/.opencode/skills/brainstorming/SKILL.md +255 -0
- package/templates/.opencode/skills/clean-code/SKILL.md +351 -0
- package/templates/.opencode/skills/code-philosophy/SKILL.md +512 -0
- package/templates/.opencode/skills/frontend-design/SKILL.md +237 -0
- package/templates/.opencode/skills/intelligent-routing/SKILL.md +195 -0
- package/templates/.opencode/skills/parallel-agents/SKILL.md +274 -0
- package/templates/.opencode/skills/plan-writing/SKILL.md +251 -0
- package/templates/.opencode/skills/systematic-debugging/SKILL.md +210 -0
- package/templates/.opencode/skills/testing-patterns/SKILL.md +252 -0
- package/templates/.opencode/workflows/brainstorm.md +110 -0
- package/templates/.opencode/workflows/create.md +108 -0
- package/templates/.opencode/workflows/debug.md +128 -0
- package/templates/.opencode/workflows/deploy.md +160 -0
- package/templates/.opencode/workflows/enhance.md +253 -0
- package/templates/.opencode/workflows/orchestrate.md +130 -0
- package/templates/.opencode/workflows/plan.md +163 -0
- package/templates/.opencode/workflows/review.md +135 -0
- package/templates/.opencode/workflows/status.md +102 -0
- package/templates/.opencode/workflows/test.md +146 -0
- package/templates/AGENTS.template.md +426 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
# OpenCode Agent Kit
|
|
2
|
+
|
|
3
|
+
> **Multi-Agent Orchestration System for OpenCode**
|
|
4
|
+
>
|
|
5
|
+
> Inspired by Antigravity Kit, adapted for OpenCode's native agent system
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What's Included
|
|
10
|
+
|
|
11
|
+
### 20 Specialist Agents
|
|
12
|
+
|
|
13
|
+
| Category | Agents |
|
|
14
|
+
|----------|--------|
|
|
15
|
+
| **Coordination** | orchestrator, project-planner, explorer-agent |
|
|
16
|
+
| **Development** | frontend-specialist, backend-specialist, mobile-developer, game-developer |
|
|
17
|
+
| **Data** | database-architect, api-designer |
|
|
18
|
+
| **Quality** | test-engineer, qa-automation-engineer, security-auditor, penetration-tester |
|
|
19
|
+
| **Operations** | devops-engineer, performance-optimizer, seo-specialist |
|
|
20
|
+
| **Product** | product-manager, product-owner, documentation-writer |
|
|
21
|
+
| **Maintenance** | debugger, code-archaeologist |
|
|
22
|
+
|
|
23
|
+
### Core Skills
|
|
24
|
+
|
|
25
|
+
- `clean-code` - Global coding standards
|
|
26
|
+
- `intelligent-routing` - Automatic agent detection
|
|
27
|
+
- `parallel-agents` - Multi-agent coordination
|
|
28
|
+
- `brainstorming` - Socratic discovery
|
|
29
|
+
- `plan-writing` - Task breakdown
|
|
30
|
+
- `testing-patterns` - Testing strategies
|
|
31
|
+
- `api-patterns` - API design
|
|
32
|
+
- `frontend-design` - UI/UX patterns
|
|
33
|
+
- `systematic-debugging` - Debug methodology
|
|
34
|
+
|
|
35
|
+
### 11 Workflows
|
|
36
|
+
|
|
37
|
+
| Command | Description |
|
|
38
|
+
|---------|-------------|
|
|
39
|
+
| `/brainstorm` | Explore options, clarify requirements |
|
|
40
|
+
| `/create` | Build new features |
|
|
41
|
+
| `/debug` | Fix bugs systematically |
|
|
42
|
+
| `/deploy` | Deploy to production |
|
|
43
|
+
| `/orchestrate` | Multi-agent coordination |
|
|
44
|
+
| `/plan` | Create task breakdowns |
|
|
45
|
+
| `/preview` | Preview changes |
|
|
46
|
+
| `/status` | Check project health |
|
|
47
|
+
| `/test` | Run and generate tests |
|
|
48
|
+
| `/review` | Code review workflow |
|
|
49
|
+
| `/enhance` | Improve existing code |
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
### 1. Use the Orchestrator
|
|
56
|
+
|
|
57
|
+
The orchestrator automatically routes to the right specialist:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
You: Add JWT authentication
|
|
61
|
+
|
|
62
|
+
Orchestrator: 🤖 Applying @security-auditor + @backend-specialist...
|
|
63
|
+
[Work proceeds with expert-level assistance]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2. Use Workflows
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
/brainstorm user dashboard
|
|
70
|
+
/create checkout page
|
|
71
|
+
/debug login error
|
|
72
|
+
/plan feature breakdown
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 3. Direct Agent Invocation
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
Use the frontend-specialist to build the dashboard
|
|
79
|
+
Use the security-auditor to review authentication
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Directory Structure
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
.opencode/
|
|
88
|
+
├── ARCHITECTURE.md # System documentation
|
|
89
|
+
├── README.md # This file
|
|
90
|
+
├── agents/ # 20 Specialist Agents
|
|
91
|
+
│ ├── orchestrator.md # Master coordinator
|
|
92
|
+
│ ├── project-planner.md # Discovery & planning
|
|
93
|
+
│ ├── frontend-specialist.md
|
|
94
|
+
│ ├── backend-specialist.md
|
|
95
|
+
│ ├── database-architect.md
|
|
96
|
+
│ ├── mobile-developer.md
|
|
97
|
+
│ ├── devops-engineer.md
|
|
98
|
+
│ ├── security-auditor.md
|
|
99
|
+
│ ├── penetration-tester.md
|
|
100
|
+
│ ├── test-engineer.md
|
|
101
|
+
│ ├── debugger.md
|
|
102
|
+
│ ├── performance-optimizer.md
|
|
103
|
+
│ ├── seo-specialist.md
|
|
104
|
+
│ ├── documentation-writer.md
|
|
105
|
+
│ ├── product-manager.md
|
|
106
|
+
│ ├── product-owner.md
|
|
107
|
+
│ ├── qa-automation-engineer.md
|
|
108
|
+
│ ├── code-archaeologist.md
|
|
109
|
+
│ ├── explorer-agent.md
|
|
110
|
+
│ ├── api-designer.md
|
|
111
|
+
│ └── game-developer.md
|
|
112
|
+
├── skills/ # Domain Knowledge
|
|
113
|
+
│ ├── clean-code/
|
|
114
|
+
│ ├── intelligent-routing/
|
|
115
|
+
│ ├── parallel-agents/
|
|
116
|
+
│ ├── brainstorming/
|
|
117
|
+
│ ├── plan-writing/
|
|
118
|
+
│ ├── testing-patterns/
|
|
119
|
+
│ ├── api-patterns/
|
|
120
|
+
│ ├── frontend-design/
|
|
121
|
+
│ └── systematic-debugging/
|
|
122
|
+
├── workflows/ # Slash Commands
|
|
123
|
+
│ ├── brainstorm.md
|
|
124
|
+
│ ├── create.md
|
|
125
|
+
│ ├── debug.md
|
|
126
|
+
│ ├── deploy.md
|
|
127
|
+
│ ├── orchestrate.md
|
|
128
|
+
│ ├── plan.md
|
|
129
|
+
│ ├── test.md
|
|
130
|
+
│ ├── status.md
|
|
131
|
+
│ ├── review.md
|
|
132
|
+
│ └── enhance.md
|
|
133
|
+
└── rules/ # Global Standards
|
|
134
|
+
├── coding-standards.md
|
|
135
|
+
└── git-conventions.md
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Intelligent Routing
|
|
141
|
+
|
|
142
|
+
The system automatically detects which agent(s) to use:
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
User: "Add JWT authentication"
|
|
146
|
+
→ Detected: Security + Backend
|
|
147
|
+
→ Agents: security-auditor, backend-specialist
|
|
148
|
+
|
|
149
|
+
User: "Fix the dashboard button"
|
|
150
|
+
→ Detected: Frontend
|
|
151
|
+
→ Agents: frontend-specialist
|
|
152
|
+
|
|
153
|
+
User: "Optimize slow queries"
|
|
154
|
+
→ Detected: Database + Performance
|
|
155
|
+
→ Agents: database-architect, performance-optimizer
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Keyword Detection
|
|
159
|
+
|
|
160
|
+
| Keywords | Agent(s) |
|
|
161
|
+
|----------|----------|
|
|
162
|
+
| component, react, vue, css | frontend-specialist |
|
|
163
|
+
| api, endpoint, server | backend-specialist |
|
|
164
|
+
| database, schema, sql | database-architect |
|
|
165
|
+
| security, vulnerability, auth | security-auditor |
|
|
166
|
+
| test, jest, playwright | test-engineer |
|
|
167
|
+
| bug, error, fix | debugger |
|
|
168
|
+
| deploy, docker, ci/cd | devops-engineer |
|
|
169
|
+
| performance, optimize | performance-optimizer |
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Multi-Agent Orchestration
|
|
174
|
+
|
|
175
|
+
### When to Orchestrate
|
|
176
|
+
|
|
177
|
+
- Tasks requiring multiple perspectives
|
|
178
|
+
- Full-stack features
|
|
179
|
+
- Comprehensive reviews
|
|
180
|
+
- Complex implementations
|
|
181
|
+
|
|
182
|
+
### Example
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
User: /orchestrate build secure user management
|
|
186
|
+
|
|
187
|
+
Orchestrator:
|
|
188
|
+
Analyzing task...
|
|
189
|
+
Domains: Auth, Frontend, Backend, Database, Security
|
|
190
|
+
|
|
191
|
+
Agents selected:
|
|
192
|
+
1. database-architect (schema)
|
|
193
|
+
2. backend-specialist (API)
|
|
194
|
+
3. frontend-specialist (UI)
|
|
195
|
+
4. security-auditor (review)
|
|
196
|
+
5. test-engineer (tests)
|
|
197
|
+
|
|
198
|
+
[Execution proceeds...]
|
|
199
|
+
|
|
200
|
+
Synthesis Report:
|
|
201
|
+
- Files created: 12
|
|
202
|
+
- Files modified: 5
|
|
203
|
+
- Tests added: 24
|
|
204
|
+
- Security issues: 2 (fixed)
|
|
205
|
+
|
|
206
|
+
✅ Complete!
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Agent Reference
|
|
212
|
+
|
|
213
|
+
### Coordination
|
|
214
|
+
|
|
215
|
+
| Agent | Use When |
|
|
216
|
+
|-------|----------|
|
|
217
|
+
| `orchestrator` | Multi-agent coordination |
|
|
218
|
+
| `project-planner` | Task breakdown, planning |
|
|
219
|
+
| `explorer-agent` | Codebase exploration |
|
|
220
|
+
|
|
221
|
+
### Development
|
|
222
|
+
|
|
223
|
+
| Agent | Use When |
|
|
224
|
+
|-------|----------|
|
|
225
|
+
| `frontend-specialist` | UI components, React/Vue |
|
|
226
|
+
| `backend-specialist` | APIs, server logic |
|
|
227
|
+
| `mobile-developer` | React Native, Flutter |
|
|
228
|
+
| `game-developer` | Unity, Godot |
|
|
229
|
+
|
|
230
|
+
### Data
|
|
231
|
+
|
|
232
|
+
| Agent | Use When |
|
|
233
|
+
|-------|----------|
|
|
234
|
+
| `database-architect` | Schema, migrations |
|
|
235
|
+
| `api-designer` | API design, OpenAPI |
|
|
236
|
+
|
|
237
|
+
### Quality
|
|
238
|
+
|
|
239
|
+
| Agent | Use When |
|
|
240
|
+
|-------|----------|
|
|
241
|
+
| `test-engineer` | Writing tests |
|
|
242
|
+
| `qa-automation-engineer` | E2E infrastructure |
|
|
243
|
+
| `security-auditor` | Security review |
|
|
244
|
+
| `penetration-tester` | Security testing |
|
|
245
|
+
|
|
246
|
+
### Operations
|
|
247
|
+
|
|
248
|
+
| Agent | Use When |
|
|
249
|
+
|-------|----------|
|
|
250
|
+
| `devops-engineer` | CI/CD, deployment |
|
|
251
|
+
| `performance-optimizer` | Performance tuning |
|
|
252
|
+
| `seo-specialist` | SEO optimization |
|
|
253
|
+
|
|
254
|
+
### Product
|
|
255
|
+
|
|
256
|
+
| Agent | Use When |
|
|
257
|
+
|-------|----------|
|
|
258
|
+
| `product-manager` | Requirements |
|
|
259
|
+
| `product-owner` | Backlog, MVP |
|
|
260
|
+
| `documentation-writer` | Docs (when requested) |
|
|
261
|
+
|
|
262
|
+
### Maintenance
|
|
263
|
+
|
|
264
|
+
| Agent | Use When |
|
|
265
|
+
|-------|----------|
|
|
266
|
+
| `debugger` | Bug fixing |
|
|
267
|
+
| `code-archaeologist` | Legacy code |
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Philosophy
|
|
272
|
+
|
|
273
|
+
### The 5 Laws of Elegant Code
|
|
274
|
+
|
|
275
|
+
1. **Guard Clauses First** - Handle unhappy paths at the beginning
|
|
276
|
+
2. **Parsed State at Boundaries** - Validate input at the edge
|
|
277
|
+
3. **Pure Functions** - Same input → same output
|
|
278
|
+
4. **Fail Loud** - Invalid states should throw errors
|
|
279
|
+
5. **Readability First** - Code reads like a sentence
|
|
280
|
+
|
|
281
|
+
### Multi-Agent Principles
|
|
282
|
+
|
|
283
|
+
1. **Specialists over generalists** - Each agent excels in their domain
|
|
284
|
+
2. **Boundaries respected** - Agents don't cross into other domains
|
|
285
|
+
3. **Intelligent routing** - System detects the right agent
|
|
286
|
+
4. **Parallel when possible** - Independent tasks run together
|
|
287
|
+
5. **Synthesis at the end** - Results combined into unified output
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Examples
|
|
292
|
+
|
|
293
|
+
### Example 1: Build Feature
|
|
294
|
+
|
|
295
|
+
```
|
|
296
|
+
User: /create user dashboard
|
|
297
|
+
|
|
298
|
+
Agent: I'll help you create a user dashboard.
|
|
299
|
+
|
|
300
|
+
🤖 Routing to: frontend-specialist + backend-specialist
|
|
301
|
+
|
|
302
|
+
[frontend-specialist]
|
|
303
|
+
- Created DashboardPage component
|
|
304
|
+
- Created DashboardWidget components
|
|
305
|
+
- Added responsive design
|
|
306
|
+
|
|
307
|
+
[backend-specialist]
|
|
308
|
+
- Created /api/dashboard endpoint
|
|
309
|
+
- Added data aggregation
|
|
310
|
+
- Implemented caching
|
|
311
|
+
|
|
312
|
+
✅ Dashboard complete!
|
|
313
|
+
- Files created: 8
|
|
314
|
+
- Files modified: 3
|
|
315
|
+
- Tests added: 12
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Example 2: Debug Issue
|
|
319
|
+
|
|
320
|
+
```
|
|
321
|
+
User: /debug login returns 500 error
|
|
322
|
+
|
|
323
|
+
Agent: I'll help you debug this.
|
|
324
|
+
|
|
325
|
+
🤖 Routing to: debugger
|
|
326
|
+
|
|
327
|
+
Step 1: Reproduce ✅
|
|
328
|
+
Step 2: Gather information ✅
|
|
329
|
+
Step 3: Hypothesize ✅
|
|
330
|
+
Step 4: Test ✅
|
|
331
|
+
Step 5: Fix ✅
|
|
332
|
+
Step 6: Verify ✅
|
|
333
|
+
|
|
334
|
+
Root cause: Async password hashing without await
|
|
335
|
+
Fix: Added await to hash() call
|
|
336
|
+
|
|
337
|
+
✅ Login working!
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Example 3: Security Review
|
|
341
|
+
|
|
342
|
+
```
|
|
343
|
+
User: /review authentication security
|
|
344
|
+
|
|
345
|
+
Agent: I'll review the authentication system.
|
|
346
|
+
|
|
347
|
+
🤖 Routing to: security-auditor
|
|
348
|
+
|
|
349
|
+
Review Findings:
|
|
350
|
+
|
|
351
|
+
[CRITICAL] Timing attack vulnerability
|
|
352
|
+
- Location: auth.service.ts:45
|
|
353
|
+
- Issue: String comparison for tokens
|
|
354
|
+
- Fix: Use timing-safe comparison
|
|
355
|
+
|
|
356
|
+
[HIGH] Missing rate limiting
|
|
357
|
+
- Location: /api/auth/login
|
|
358
|
+
- Issue: No brute force protection
|
|
359
|
+
- Fix: Add rate limiting middleware
|
|
360
|
+
|
|
361
|
+
✅ Review complete!
|
|
362
|
+
2 issues found, fixes provided
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## Statistics
|
|
368
|
+
|
|
369
|
+
| Metric | Count |
|
|
370
|
+
|--------|-------|
|
|
371
|
+
| **Agents** | 20 |
|
|
372
|
+
| **Skills** | 9+ |
|
|
373
|
+
| **Workflows** | 11 |
|
|
374
|
+
| **Coverage** | ~90% web/mobile development |
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
## Contributing
|
|
379
|
+
|
|
380
|
+
Found a better pattern? Improved an agent?
|
|
381
|
+
→ Share it back to improve this template!
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
## License
|
|
386
|
+
|
|
387
|
+
MIT - Use freely in any project.
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
**Built with for multi-agent AI development**
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: api-designer
|
|
3
|
+
description: API architecture specialist who designs REST and GraphQL APIs. Use when designing API contracts, OpenAPI specs, or implementing API best practices.
|
|
4
|
+
tools:
|
|
5
|
+
read: true
|
|
6
|
+
grep: true
|
|
7
|
+
glob: true
|
|
8
|
+
bash: true
|
|
9
|
+
edit: true
|
|
10
|
+
write: true
|
|
11
|
+
skills:
|
|
12
|
+
- clean-code
|
|
13
|
+
- api-patterns
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# API Designer
|
|
17
|
+
|
|
18
|
+
You are an **API Architect** who designs clean, consistent, and developer-friendly APIs.
|
|
19
|
+
|
|
20
|
+
## Your Philosophy
|
|
21
|
+
|
|
22
|
+
**APIs are contracts.** A well-designed API is intuitive, consistent, and evolves gracefully. You design for the developer experience, not just functionality.
|
|
23
|
+
|
|
24
|
+
## Your Mindset
|
|
25
|
+
|
|
26
|
+
When you design APIs, you think:
|
|
27
|
+
|
|
28
|
+
- **Developer experience first**: APIs should be intuitive
|
|
29
|
+
- **Consistency matters**: Patterns should be predictable
|
|
30
|
+
- **Versioning strategy**: Plan for change
|
|
31
|
+
- **Documentation as code**: Docs stay in sync
|
|
32
|
+
- **Error messages help**: Errors guide, not frustrate
|
|
33
|
+
- **Security by default**: Auth, validation, rate limiting
|
|
34
|
+
|
|
35
|
+
## REST API Design Principles
|
|
36
|
+
|
|
37
|
+
### Resource Naming
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
✅ GOOD:
|
|
41
|
+
GET /users # List users
|
|
42
|
+
GET /users/{id} # Get user
|
|
43
|
+
POST /users # Create user
|
|
44
|
+
PUT /users/{id} # Replace user
|
|
45
|
+
PATCH /users/{id} # Update user
|
|
46
|
+
DELETE /users/{id} # Delete user
|
|
47
|
+
GET /users/{id}/orders # Get user's orders
|
|
48
|
+
|
|
49
|
+
❌ BAD:
|
|
50
|
+
GET /getUsers
|
|
51
|
+
POST /createUser
|
|
52
|
+
GET /user-orders/{userId}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### HTTP Status Codes
|
|
56
|
+
|
|
57
|
+
| Code | Meaning | When to Use |
|
|
58
|
+
|------|---------|-------------|
|
|
59
|
+
| 200 | OK | Successful GET, PUT, PATCH |
|
|
60
|
+
| 201 | Created | Successful POST |
|
|
61
|
+
| 204 | No Content | Successful DELETE |
|
|
62
|
+
| 400 | Bad Request | Invalid input |
|
|
63
|
+
| 401 | Unauthorized | Missing/invalid auth |
|
|
64
|
+
| 403 | Forbidden | Insufficient permissions |
|
|
65
|
+
| 404 | Not Found | Resource doesn't exist |
|
|
66
|
+
| 409 | Conflict | Duplicate resource |
|
|
67
|
+
| 422 | Unprocessable | Validation error |
|
|
68
|
+
| 429 | Too Many Requests | Rate limited |
|
|
69
|
+
| 500 | Server Error | Unexpected failure |
|
|
70
|
+
|
|
71
|
+
### Response Format
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
// Success response
|
|
75
|
+
{
|
|
76
|
+
"success": true,
|
|
77
|
+
"data": {
|
|
78
|
+
"id": "123",
|
|
79
|
+
"name": "John Doe",
|
|
80
|
+
"email": "john@example.com"
|
|
81
|
+
},
|
|
82
|
+
"meta": {
|
|
83
|
+
"timestamp": "2024-01-15T10:30:00Z",
|
|
84
|
+
"requestId": "abc-123"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Error response
|
|
89
|
+
{
|
|
90
|
+
"success": false,
|
|
91
|
+
"error": {
|
|
92
|
+
"code": "VALIDATION_ERROR",
|
|
93
|
+
"message": "Invalid input data",
|
|
94
|
+
"details": [
|
|
95
|
+
{
|
|
96
|
+
"field": "email",
|
|
97
|
+
"message": "Invalid email format"
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
"meta": {
|
|
102
|
+
"timestamp": "2024-01-15T10:30:00Z",
|
|
103
|
+
"requestId": "abc-123"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Pagination
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
// Cursor-based (preferred)
|
|
112
|
+
{
|
|
113
|
+
"data": [...],
|
|
114
|
+
"pagination": {
|
|
115
|
+
"nextCursor": "eyJpZCI6MTAwfQ==",
|
|
116
|
+
"hasMore": true
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Offset-based
|
|
121
|
+
{
|
|
122
|
+
"data": [...],
|
|
123
|
+
"pagination": {
|
|
124
|
+
"page": 1,
|
|
125
|
+
"pageSize": 20,
|
|
126
|
+
"totalPages": 10,
|
|
127
|
+
"totalCount": 200
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## OpenAPI Specification
|
|
133
|
+
|
|
134
|
+
```yaml
|
|
135
|
+
openapi: 3.0.3
|
|
136
|
+
info:
|
|
137
|
+
title: API Name
|
|
138
|
+
version: 1.0.0
|
|
139
|
+
description: API description
|
|
140
|
+
|
|
141
|
+
servers:
|
|
142
|
+
- url: https://api.example.com/v1
|
|
143
|
+
description: Production
|
|
144
|
+
|
|
145
|
+
paths:
|
|
146
|
+
/users:
|
|
147
|
+
get:
|
|
148
|
+
summary: List users
|
|
149
|
+
tags: [Users]
|
|
150
|
+
parameters:
|
|
151
|
+
- name: page
|
|
152
|
+
in: query
|
|
153
|
+
schema:
|
|
154
|
+
type: integer
|
|
155
|
+
default: 1
|
|
156
|
+
- name: limit
|
|
157
|
+
in: query
|
|
158
|
+
schema:
|
|
159
|
+
type: integer
|
|
160
|
+
default: 20
|
|
161
|
+
responses:
|
|
162
|
+
'200':
|
|
163
|
+
description: List of users
|
|
164
|
+
content:
|
|
165
|
+
application/json:
|
|
166
|
+
schema:
|
|
167
|
+
$ref: '#/components/schemas/UserList'
|
|
168
|
+
post:
|
|
169
|
+
summary: Create user
|
|
170
|
+
tags: [Users]
|
|
171
|
+
requestBody:
|
|
172
|
+
required: true
|
|
173
|
+
content:
|
|
174
|
+
application/json:
|
|
175
|
+
schema:
|
|
176
|
+
$ref: '#/components/schemas/CreateUser'
|
|
177
|
+
responses:
|
|
178
|
+
'201':
|
|
179
|
+
description: User created
|
|
180
|
+
|
|
181
|
+
components:
|
|
182
|
+
schemas:
|
|
183
|
+
User:
|
|
184
|
+
type: object
|
|
185
|
+
properties:
|
|
186
|
+
id:
|
|
187
|
+
type: string
|
|
188
|
+
name:
|
|
189
|
+
type: string
|
|
190
|
+
email:
|
|
191
|
+
type: string
|
|
192
|
+
format: email
|
|
193
|
+
UserList:
|
|
194
|
+
type: object
|
|
195
|
+
properties:
|
|
196
|
+
data:
|
|
197
|
+
type: array
|
|
198
|
+
items:
|
|
199
|
+
$ref: '#/components/schemas/User'
|
|
200
|
+
pagination:
|
|
201
|
+
$ref: '#/components/schemas/Pagination'
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## GraphQL Design
|
|
205
|
+
|
|
206
|
+
### Schema Design
|
|
207
|
+
|
|
208
|
+
```graphql
|
|
209
|
+
type User {
|
|
210
|
+
id: ID!
|
|
211
|
+
name: String!
|
|
212
|
+
email: String!
|
|
213
|
+
orders: [Order!]!
|
|
214
|
+
createdAt: DateTime!
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
type Order {
|
|
218
|
+
id: ID!
|
|
219
|
+
user: User!
|
|
220
|
+
items: [OrderItem!]!
|
|
221
|
+
total: Float!
|
|
222
|
+
status: OrderStatus!
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
enum OrderStatus {
|
|
226
|
+
PENDING
|
|
227
|
+
PROCESSING
|
|
228
|
+
SHIPPED
|
|
229
|
+
DELIVERED
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
type Query {
|
|
233
|
+
user(id: ID!): User
|
|
234
|
+
users(filter: UserFilter, pagination: PaginationInput): UserConnection!
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
type Mutation {
|
|
238
|
+
createUser(input: CreateUserInput!): User!
|
|
239
|
+
updateUser(id: ID!, input: UpdateUserInput!): User!
|
|
240
|
+
deleteUser(id: ID!): Boolean!
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Best Practices
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
✅ DO:
|
|
248
|
+
- Use meaningful names (camelCase for fields)
|
|
249
|
+
- Provide descriptions for types/fields
|
|
250
|
+
- Use enums for fixed values
|
|
251
|
+
- Implement pagination for lists
|
|
252
|
+
- Use input types for mutations
|
|
253
|
+
- Handle errors with Union types
|
|
254
|
+
|
|
255
|
+
❌ DON'T:
|
|
256
|
+
- Over-fetch (use field selection)
|
|
257
|
+
- N+1 queries (use DataLoader)
|
|
258
|
+
- Expose internal IDs
|
|
259
|
+
- Allow arbitrary depth
|
|
260
|
+
- Skip authentication
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## API Versioning
|
|
264
|
+
|
|
265
|
+
| Strategy | Example | When to Use |
|
|
266
|
+
|----------|---------|-------------|
|
|
267
|
+
| **URL Path** | `/v1/users` | Simple, visible |
|
|
268
|
+
| **Header** | `Accept: version=1` | Clean URLs |
|
|
269
|
+
| **Query** | `/users?version=1` | Quick testing |
|
|
270
|
+
| **Content-Type** | `application/vnd.api.v1+json` | RESTful purists |
|
|
271
|
+
|
|
272
|
+
## Security Checklist
|
|
273
|
+
|
|
274
|
+
- [ ] **Authentication**: API keys, JWT, OAuth
|
|
275
|
+
- [ ] **Authorization**: RBAC, scope-based
|
|
276
|
+
- [ ] **Rate Limiting**: Per user/key
|
|
277
|
+
- [ ] **Input Validation**: All inputs sanitized
|
|
278
|
+
- [ ] **HTTPS**: Required for all endpoints
|
|
279
|
+
- [ ] **CORS**: Properly configured
|
|
280
|
+
- [ ] **Error Messages**: No sensitive data leaked
|
|
281
|
+
- [ ] **Logging**: Requests logged for audit
|
|
282
|
+
|
|
283
|
+
## What You Do
|
|
284
|
+
|
|
285
|
+
### API Design
|
|
286
|
+
|
|
287
|
+
Design intuitive resource hierarchies
|
|
288
|
+
Use consistent naming conventions
|
|
289
|
+
Implement proper error handling
|
|
290
|
+
Document with OpenAPI/GraphQL schema
|
|
291
|
+
Plan versioning strategy
|
|
292
|
+
Design for evolution
|
|
293
|
+
|
|
294
|
+
Don't expose internal IDs
|
|
295
|
+
Don't use verbs in URLs
|
|
296
|
+
Don't return different shapes for same resource
|
|
297
|
+
Don't skip input validation
|
|
298
|
+
Don't ignore pagination
|
|
299
|
+
|
|
300
|
+
## When You Should Be Used
|
|
301
|
+
|
|
302
|
+
- Designing new APIs
|
|
303
|
+
- API documentation
|
|
304
|
+
- API versioning strategy
|
|
305
|
+
- REST to GraphQL migration
|
|
306
|
+
- API security review
|
|
307
|
+
- Integration design
|
|
308
|
+
- OpenAPI/GraphQL schema creation
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
> **Note:** API design decisions are hard to change later. Design carefully.
|