ccjk 3.7.3 → 3.7.4
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/dist/chunks/package.mjs +1 -1
- package/package.json +54 -54
- package/templates/CLAUDE.md +0 -219
- package/templates/claude-code/CLAUDE.md +0 -250
- package/templates/claude-code/common/settings.json +0 -37
- package/templates/claude-code/en/workflow/bmad/commands/bmad-init.md +0 -165
- package/templates/claude-code/en/workflow/common/agents/get-current-datetime.md +0 -29
- package/templates/claude-code/en/workflow/common/agents/init-architect.md +0 -114
- package/templates/claude-code/en/workflow/common/commands/init-project.md +0 -53
- package/templates/claude-code/en/workflow/essential/agents/get-current-datetime.md +0 -29
- package/templates/claude-code/en/workflow/essential/agents/init-architect.md +0 -114
- package/templates/claude-code/en/workflow/essential/agents/planner.md +0 -116
- package/templates/claude-code/en/workflow/essential/agents/ui-ux-designer.md +0 -91
- package/templates/claude-code/en/workflow/essential/commands/feat.md +0 -250
- package/templates/claude-code/en/workflow/essential/commands/init-project.md +0 -53
- package/templates/claude-code/en/workflow/plan/agents/planner.md +0 -116
- package/templates/claude-code/en/workflow/plan/agents/ui-ux-designer.md +0 -91
- package/templates/claude-code/en/workflow/plan/commands/feat.md +0 -105
- package/templates/claude-code/zh-CN/workflow/bmad/commands/bmad-init.md +0 -172
- package/templates/claude-code/zh-CN/workflow/common/agents/get-current-datetime.md +0 -29
- package/templates/claude-code/zh-CN/workflow/common/agents/init-architect.md +0 -114
- package/templates/claude-code/zh-CN/workflow/common/commands/init-project.md +0 -53
- package/templates/claude-code/zh-CN/workflow/essential/agents/get-current-datetime.md +0 -29
- package/templates/claude-code/zh-CN/workflow/essential/agents/init-architect.md +0 -114
- package/templates/claude-code/zh-CN/workflow/essential/agents/planner.md +0 -116
- package/templates/claude-code/zh-CN/workflow/essential/agents/ui-ux-designer.md +0 -91
- package/templates/claude-code/zh-CN/workflow/essential/commands/feat.md +0 -248
- package/templates/claude-code/zh-CN/workflow/essential/commands/init-project.md +0 -53
- package/templates/claude-code/zh-CN/workflow/plan/agents/planner.md +0 -116
- package/templates/claude-code/zh-CN/workflow/plan/agents/ui-ux-designer.md +0 -91
- package/templates/claude-code/zh-CN/workflow/plan/commands/feat.md +0 -105
- package/templates/codex/common/config.toml +0 -0
- package/templates/common/output-styles/en/casual-friendly.md +0 -97
- package/templates/common/output-styles/en/expert-concise.md +0 -93
- package/templates/common/output-styles/en/pair-programmer.md +0 -177
- package/templates/common/output-styles/en/senior-architect.md +0 -121
- package/templates/common/output-styles/en/speed-coder.md +0 -185
- package/templates/common/output-styles/en/teaching-mode.md +0 -102
- package/templates/common/output-styles/en/technical-precise.md +0 -101
- package/templates/common/output-styles/zh-CN/pair-programmer.md +0 -177
- package/templates/common/output-styles/zh-CN/senior-architect.md +0 -297
- package/templates/common/output-styles/zh-CN/speed-coder.md +0 -185
- package/templates/common/skills/code-review.md +0 -343
- package/templates/common/skills/en/agent-browser.md +0 -258
- package/templates/common/skills/en/brainstorming.md +0 -64
- package/templates/common/skills/en/code-review.md +0 -81
- package/templates/common/skills/en/documentation-gen.md +0 -808
- package/templates/common/skills/en/executing-plans.md +0 -75
- package/templates/common/skills/en/git-commit.md +0 -216
- package/templates/common/skills/en/interview.md +0 -223
- package/templates/common/skills/en/migration-assistant.md +0 -312
- package/templates/common/skills/en/performance-profiling.md +0 -576
- package/templates/common/skills/en/pr-review.md +0 -341
- package/templates/common/skills/en/refactoring.md +0 -384
- package/templates/common/skills/en/security-audit.md +0 -462
- package/templates/common/skills/en/systematic-debugging.md +0 -82
- package/templates/common/skills/en/tdd-workflow.md +0 -93
- package/templates/common/skills/en/verification.md +0 -81
- package/templates/common/skills/en/workflow.md +0 -370
- package/templates/common/skills/en/writing-plans.md +0 -78
- package/templates/common/skills/summarize.md +0 -312
- package/templates/common/skills/translate.md +0 -202
- package/templates/common/skills/zh-CN/agent-browser.md +0 -260
- package/templates/common/skills/zh-CN/documentation-gen.md +0 -807
- package/templates/common/skills/zh-CN/migration-assistant.md +0 -318
- package/templates/common/skills/zh-CN/performance-profiling.md +0 -746
- package/templates/common/skills/zh-CN/pr-review.md +0 -341
- package/templates/common/skills/zh-CN/refactoring.md +0 -384
- package/templates/common/skills/zh-CN/security-audit.md +0 -462
- package/templates/common/smart-guide/en/smart-guide.md +0 -72
- package/templates/common/smart-guide/zh-CN/smart-guide.md +0 -72
- package/templates/common/workflow/git/en/git-cleanBranches.md +0 -102
- package/templates/common/workflow/git/en/git-commit.md +0 -205
- package/templates/common/workflow/git/en/git-rollback.md +0 -90
- package/templates/common/workflow/git/en/git-worktree.md +0 -276
- package/templates/common/workflow/git/zh-CN/git-cleanBranches.md +0 -102
- package/templates/common/workflow/git/zh-CN/git-commit.md +0 -205
- package/templates/common/workflow/git/zh-CN/git-rollback.md +0 -90
- package/templates/common/workflow/git/zh-CN/git-worktree.md +0 -276
- package/templates/common/workflow/interview/en/interview.md +0 -212
- package/templates/common/workflow/interview/zh-CN/interview.md +0 -212
- package/templates/common/workflow/sixStep/en/workflow.md +0 -357
- package/templates/common/workflow/sixStep/zh-CN/workflow.md +0 -357
- package/templates/industry/devops/en/ci-cd-pipeline.md +0 -410
- package/templates/industry/web-dev/en/api-design.md +0 -299
- package/templates/industry/web-dev/en/react-nextjs-setup.md +0 -236
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
# DevOps CI/CD Pipeline Template
|
|
2
|
-
|
|
3
|
-
## GitHub Actions Workflow
|
|
4
|
-
|
|
5
|
-
### Complete CI/CD Pipeline
|
|
6
|
-
|
|
7
|
-
```yaml
|
|
8
|
-
# .github/workflows/ci-cd.yml
|
|
9
|
-
name: CI/CD Pipeline
|
|
10
|
-
|
|
11
|
-
on:
|
|
12
|
-
push:
|
|
13
|
-
branches: [main, develop]
|
|
14
|
-
pull_request:
|
|
15
|
-
branches: [main]
|
|
16
|
-
|
|
17
|
-
env:
|
|
18
|
-
NODE_VERSION: '20'
|
|
19
|
-
REGISTRY: ghcr.io
|
|
20
|
-
IMAGE_NAME: ${{ github.repository }}
|
|
21
|
-
|
|
22
|
-
jobs:
|
|
23
|
-
# ===================
|
|
24
|
-
# Lint & Type Check
|
|
25
|
-
# ===================
|
|
26
|
-
lint:
|
|
27
|
-
name: Lint & Type Check
|
|
28
|
-
runs-on: ubuntu-latest
|
|
29
|
-
steps:
|
|
30
|
-
- uses: actions/checkout@v4
|
|
31
|
-
|
|
32
|
-
- uses: pnpm/action-setup@v2
|
|
33
|
-
with:
|
|
34
|
-
version: 8
|
|
35
|
-
|
|
36
|
-
- uses: actions/setup-node@v4
|
|
37
|
-
with:
|
|
38
|
-
node-version: ${{ env.NODE_VERSION }}
|
|
39
|
-
cache: 'pnpm'
|
|
40
|
-
|
|
41
|
-
- run: pnpm install --frozen-lockfile
|
|
42
|
-
- run: pnpm lint
|
|
43
|
-
- run: pnpm typecheck
|
|
44
|
-
|
|
45
|
-
# ===================
|
|
46
|
-
# Unit Tests
|
|
47
|
-
# ===================
|
|
48
|
-
test:
|
|
49
|
-
name: Unit Tests
|
|
50
|
-
runs-on: ubuntu-latest
|
|
51
|
-
steps:
|
|
52
|
-
- uses: actions/checkout@v4
|
|
53
|
-
|
|
54
|
-
- uses: pnpm/action-setup@v2
|
|
55
|
-
with:
|
|
56
|
-
version: 8
|
|
57
|
-
|
|
58
|
-
- uses: actions/setup-node@v4
|
|
59
|
-
with:
|
|
60
|
-
node-version: ${{ env.NODE_VERSION }}
|
|
61
|
-
cache: 'pnpm'
|
|
62
|
-
|
|
63
|
-
- run: pnpm install --frozen-lockfile
|
|
64
|
-
- run: pnpm test:coverage
|
|
65
|
-
|
|
66
|
-
- uses: codecov/codecov-action@v3
|
|
67
|
-
with:
|
|
68
|
-
files: ./coverage/lcov.info
|
|
69
|
-
|
|
70
|
-
# ===================
|
|
71
|
-
# Build
|
|
72
|
-
# ===================
|
|
73
|
-
build:
|
|
74
|
-
name: Build
|
|
75
|
-
runs-on: ubuntu-latest
|
|
76
|
-
needs: [lint, test]
|
|
77
|
-
steps:
|
|
78
|
-
- uses: actions/checkout@v4
|
|
79
|
-
|
|
80
|
-
- uses: pnpm/action-setup@v2
|
|
81
|
-
with:
|
|
82
|
-
version: 8
|
|
83
|
-
|
|
84
|
-
- uses: actions/setup-node@v4
|
|
85
|
-
with:
|
|
86
|
-
node-version: ${{ env.NODE_VERSION }}
|
|
87
|
-
cache: 'pnpm'
|
|
88
|
-
|
|
89
|
-
- run: pnpm install --frozen-lockfile
|
|
90
|
-
- run: pnpm build
|
|
91
|
-
|
|
92
|
-
- uses: actions/upload-artifact@v4
|
|
93
|
-
with:
|
|
94
|
-
name: build
|
|
95
|
-
path: dist/
|
|
96
|
-
|
|
97
|
-
# ===================
|
|
98
|
-
# Security Scan
|
|
99
|
-
# ===================
|
|
100
|
-
security:
|
|
101
|
-
name: Security Scan
|
|
102
|
-
runs-on: ubuntu-latest
|
|
103
|
-
steps:
|
|
104
|
-
- uses: actions/checkout@v4
|
|
105
|
-
|
|
106
|
-
- name: Run Trivy vulnerability scanner
|
|
107
|
-
uses: aquasecurity/trivy-action@master
|
|
108
|
-
with:
|
|
109
|
-
scan-type: 'fs'
|
|
110
|
-
scan-ref: '.'
|
|
111
|
-
severity: 'CRITICAL,HIGH'
|
|
112
|
-
|
|
113
|
-
# ===================
|
|
114
|
-
# Docker Build
|
|
115
|
-
# ===================
|
|
116
|
-
docker:
|
|
117
|
-
name: Docker Build & Push
|
|
118
|
-
runs-on: ubuntu-latest
|
|
119
|
-
needs: [build, security]
|
|
120
|
-
if: github.ref == 'refs/heads/main'
|
|
121
|
-
permissions:
|
|
122
|
-
contents: read
|
|
123
|
-
packages: write
|
|
124
|
-
|
|
125
|
-
steps:
|
|
126
|
-
- uses: actions/checkout@v4
|
|
127
|
-
|
|
128
|
-
- uses: docker/setup-buildx-action@v3
|
|
129
|
-
|
|
130
|
-
- uses: docker/login-action@v3
|
|
131
|
-
with:
|
|
132
|
-
registry: ${{ env.REGISTRY }}
|
|
133
|
-
username: ${{ github.actor }}
|
|
134
|
-
password: ${{ secrets.GITHUB_TOKEN }}
|
|
135
|
-
|
|
136
|
-
- uses: docker/metadata-action@v5
|
|
137
|
-
id: meta
|
|
138
|
-
with:
|
|
139
|
-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
140
|
-
tags: |
|
|
141
|
-
type=sha
|
|
142
|
-
type=ref,event=branch
|
|
143
|
-
type=semver,pattern={{version}}
|
|
144
|
-
|
|
145
|
-
- uses: docker/build-push-action@v5
|
|
146
|
-
with:
|
|
147
|
-
context: .
|
|
148
|
-
push: true
|
|
149
|
-
tags: ${{ steps.meta.outputs.tags }}
|
|
150
|
-
labels: ${{ steps.meta.outputs.labels }}
|
|
151
|
-
cache-from: type=gha
|
|
152
|
-
cache-to: type=gha,mode=max
|
|
153
|
-
|
|
154
|
-
# ===================
|
|
155
|
-
# Deploy Staging
|
|
156
|
-
# ===================
|
|
157
|
-
deploy-staging:
|
|
158
|
-
name: Deploy to Staging
|
|
159
|
-
runs-on: ubuntu-latest
|
|
160
|
-
needs: [docker]
|
|
161
|
-
environment: staging
|
|
162
|
-
if: github.ref == 'refs/heads/main'
|
|
163
|
-
|
|
164
|
-
steps:
|
|
165
|
-
- name: Deploy to staging
|
|
166
|
-
run: |
|
|
167
|
-
# Add deployment commands here
|
|
168
|
-
echo "Deploying to staging..."
|
|
169
|
-
|
|
170
|
-
# ===================
|
|
171
|
-
# E2E Tests
|
|
172
|
-
# ===================
|
|
173
|
-
e2e:
|
|
174
|
-
name: E2E Tests
|
|
175
|
-
runs-on: ubuntu-latest
|
|
176
|
-
needs: [deploy-staging]
|
|
177
|
-
|
|
178
|
-
steps:
|
|
179
|
-
- uses: actions/checkout@v4
|
|
180
|
-
|
|
181
|
-
- uses: pnpm/action-setup@v2
|
|
182
|
-
with:
|
|
183
|
-
version: 8
|
|
184
|
-
|
|
185
|
-
- uses: actions/setup-node@v4
|
|
186
|
-
with:
|
|
187
|
-
node-version: ${{ env.NODE_VERSION }}
|
|
188
|
-
cache: 'pnpm'
|
|
189
|
-
|
|
190
|
-
- run: pnpm install --frozen-lockfile
|
|
191
|
-
- run: pnpm exec playwright install --with-deps
|
|
192
|
-
|
|
193
|
-
- name: Run E2E tests
|
|
194
|
-
run: pnpm test:e2e
|
|
195
|
-
env:
|
|
196
|
-
BASE_URL: https://staging.example.com
|
|
197
|
-
|
|
198
|
-
- uses: actions/upload-artifact@v4
|
|
199
|
-
if: failure()
|
|
200
|
-
with:
|
|
201
|
-
name: playwright-report
|
|
202
|
-
path: playwright-report/
|
|
203
|
-
|
|
204
|
-
# ===================
|
|
205
|
-
# Deploy Production
|
|
206
|
-
# ===================
|
|
207
|
-
deploy-prod:
|
|
208
|
-
name: Deploy to Production
|
|
209
|
-
runs-on: ubuntu-latest
|
|
210
|
-
needs: [e2e]
|
|
211
|
-
environment: production
|
|
212
|
-
if: github.ref == 'refs/heads/main'
|
|
213
|
-
|
|
214
|
-
steps:
|
|
215
|
-
- name: Deploy to production
|
|
216
|
-
run: |
|
|
217
|
-
echo "Deploying to production..."
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
## Dockerfile
|
|
221
|
-
|
|
222
|
-
```dockerfile
|
|
223
|
-
# Build stage
|
|
224
|
-
FROM node:20-alpine AS builder
|
|
225
|
-
|
|
226
|
-
WORKDIR /app
|
|
227
|
-
|
|
228
|
-
# Install pnpm
|
|
229
|
-
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
230
|
-
|
|
231
|
-
# Install dependencies
|
|
232
|
-
COPY package.json pnpm-lock.yaml ./
|
|
233
|
-
RUN pnpm install --frozen-lockfile
|
|
234
|
-
|
|
235
|
-
# Build
|
|
236
|
-
COPY . .
|
|
237
|
-
RUN pnpm build
|
|
238
|
-
|
|
239
|
-
# Production stage
|
|
240
|
-
FROM node:20-alpine AS runner
|
|
241
|
-
|
|
242
|
-
WORKDIR /app
|
|
243
|
-
|
|
244
|
-
ENV NODE_ENV=production
|
|
245
|
-
|
|
246
|
-
# Create non-root user
|
|
247
|
-
RUN addgroup --system --gid 1001 nodejs && \
|
|
248
|
-
adduser --system --uid 1001 appuser
|
|
249
|
-
|
|
250
|
-
# Copy built files
|
|
251
|
-
COPY --from=builder /app/dist ./dist
|
|
252
|
-
COPY --from=builder /app/package.json ./
|
|
253
|
-
|
|
254
|
-
# Install production dependencies only
|
|
255
|
-
RUN corepack enable && \
|
|
256
|
-
corepack prepare pnpm@latest --activate && \
|
|
257
|
-
pnpm install --prod --frozen-lockfile
|
|
258
|
-
|
|
259
|
-
USER appuser
|
|
260
|
-
|
|
261
|
-
EXPOSE 3000
|
|
262
|
-
|
|
263
|
-
CMD ["node", "dist/index.js"]
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
## Docker Compose
|
|
267
|
-
|
|
268
|
-
```yaml
|
|
269
|
-
# docker-compose.yml
|
|
270
|
-
version: '3.8'
|
|
271
|
-
|
|
272
|
-
services:
|
|
273
|
-
app:
|
|
274
|
-
build: .
|
|
275
|
-
ports:
|
|
276
|
-
- '3000:3000'
|
|
277
|
-
environment:
|
|
278
|
-
- DATABASE_URL=postgres://user:pass@db:5432/app
|
|
279
|
-
- REDIS_URL=redis://cache:6379
|
|
280
|
-
depends_on:
|
|
281
|
-
db:
|
|
282
|
-
condition: service_healthy
|
|
283
|
-
cache:
|
|
284
|
-
condition: service_started
|
|
285
|
-
healthcheck:
|
|
286
|
-
test: ['CMD', 'curl', '-f', 'http://localhost:3000/health']
|
|
287
|
-
interval: 30s
|
|
288
|
-
timeout: 10s
|
|
289
|
-
retries: 3
|
|
290
|
-
|
|
291
|
-
db:
|
|
292
|
-
image: postgres:16-alpine
|
|
293
|
-
volumes:
|
|
294
|
-
- postgres_data:/var/lib/postgresql/data
|
|
295
|
-
environment:
|
|
296
|
-
- POSTGRES_USER=user
|
|
297
|
-
- POSTGRES_PASSWORD=pass
|
|
298
|
-
- POSTGRES_DB=app
|
|
299
|
-
healthcheck:
|
|
300
|
-
test: ['CMD-SHELL', 'pg_isready -U user -d app']
|
|
301
|
-
interval: 5s
|
|
302
|
-
timeout: 5s
|
|
303
|
-
retries: 5
|
|
304
|
-
|
|
305
|
-
cache:
|
|
306
|
-
image: redis:7-alpine
|
|
307
|
-
volumes:
|
|
308
|
-
- redis_data:/data
|
|
309
|
-
|
|
310
|
-
volumes:
|
|
311
|
-
postgres_data:
|
|
312
|
-
redis_data:
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
## Kubernetes Deployment
|
|
316
|
-
|
|
317
|
-
```yaml
|
|
318
|
-
# k8s/deployment.yaml
|
|
319
|
-
apiVersion: apps/v1
|
|
320
|
-
kind: Deployment
|
|
321
|
-
metadata:
|
|
322
|
-
name: app
|
|
323
|
-
labels:
|
|
324
|
-
app: app
|
|
325
|
-
spec:
|
|
326
|
-
replicas: 3
|
|
327
|
-
selector:
|
|
328
|
-
matchLabels:
|
|
329
|
-
app: app
|
|
330
|
-
template:
|
|
331
|
-
metadata:
|
|
332
|
-
labels:
|
|
333
|
-
app: app
|
|
334
|
-
spec:
|
|
335
|
-
containers:
|
|
336
|
-
- name: app
|
|
337
|
-
image: ghcr.io/org/app:latest
|
|
338
|
-
ports:
|
|
339
|
-
- containerPort: 3000
|
|
340
|
-
resources:
|
|
341
|
-
requests:
|
|
342
|
-
memory: '256Mi'
|
|
343
|
-
cpu: '100m'
|
|
344
|
-
limits:
|
|
345
|
-
memory: '512Mi'
|
|
346
|
-
cpu: '500m'
|
|
347
|
-
livenessProbe:
|
|
348
|
-
httpGet:
|
|
349
|
-
path: /health
|
|
350
|
-
port: 3000
|
|
351
|
-
initialDelaySeconds: 30
|
|
352
|
-
periodSeconds: 10
|
|
353
|
-
readinessProbe:
|
|
354
|
-
httpGet:
|
|
355
|
-
path: /ready
|
|
356
|
-
port: 3000
|
|
357
|
-
initialDelaySeconds: 5
|
|
358
|
-
periodSeconds: 5
|
|
359
|
-
env:
|
|
360
|
-
- name: DATABASE_URL
|
|
361
|
-
valueFrom:
|
|
362
|
-
secretKeyRef:
|
|
363
|
-
name: app-secrets
|
|
364
|
-
key: database-url
|
|
365
|
-
---
|
|
366
|
-
apiVersion: v1
|
|
367
|
-
kind: Service
|
|
368
|
-
metadata:
|
|
369
|
-
name: app
|
|
370
|
-
spec:
|
|
371
|
-
selector:
|
|
372
|
-
app: app
|
|
373
|
-
ports:
|
|
374
|
-
- port: 80
|
|
375
|
-
targetPort: 3000
|
|
376
|
-
type: ClusterIP
|
|
377
|
-
---
|
|
378
|
-
apiVersion: networking.k8s.io/v1
|
|
379
|
-
kind: Ingress
|
|
380
|
-
metadata:
|
|
381
|
-
name: app
|
|
382
|
-
annotations:
|
|
383
|
-
kubernetes.io/ingress.class: nginx
|
|
384
|
-
cert-manager.io/cluster-issuer: letsencrypt-prod
|
|
385
|
-
spec:
|
|
386
|
-
tls:
|
|
387
|
-
- hosts:
|
|
388
|
-
- app.example.com
|
|
389
|
-
secretName: app-tls
|
|
390
|
-
rules:
|
|
391
|
-
- host: app.example.com
|
|
392
|
-
http:
|
|
393
|
-
paths:
|
|
394
|
-
- path: /
|
|
395
|
-
pathType: Prefix
|
|
396
|
-
backend:
|
|
397
|
-
service:
|
|
398
|
-
name: app
|
|
399
|
-
port:
|
|
400
|
-
number: 80
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
## Best Practices
|
|
404
|
-
|
|
405
|
-
1. **Fast Feedback**: Run linting and unit tests first
|
|
406
|
-
2. **Parallel Jobs**: Run independent jobs in parallel
|
|
407
|
-
3. **Caching**: Cache dependencies and Docker layers
|
|
408
|
-
4. **Security**: Scan for vulnerabilities before deployment
|
|
409
|
-
5. **Environment Gates**: Use environment protection rules
|
|
410
|
-
6. **Rollback Plan**: Tag releases for easy rollback
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
# API Design Best Practices Template
|
|
2
|
-
|
|
3
|
-
## RESTful API Design
|
|
4
|
-
|
|
5
|
-
### Resource Naming Conventions
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
✅ Good:
|
|
9
|
-
GET /users # List users
|
|
10
|
-
GET /users/{id} # Get specific user
|
|
11
|
-
POST /users # Create user
|
|
12
|
-
PUT /users/{id} # Replace user
|
|
13
|
-
PATCH /users/{id} # Update user
|
|
14
|
-
DELETE /users/{id} # Delete user
|
|
15
|
-
|
|
16
|
-
GET /users/{id}/orders # User's orders
|
|
17
|
-
GET /orders/{id}/items # Order's items
|
|
18
|
-
|
|
19
|
-
❌ Bad:
|
|
20
|
-
GET /getUsers
|
|
21
|
-
GET /user/fetch/{id}
|
|
22
|
-
POST /createUser
|
|
23
|
-
GET /users/{id}/getOrders
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### Query Parameters
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
# Pagination
|
|
30
|
-
GET /users?page=2&limit=20
|
|
31
|
-
|
|
32
|
-
# Filtering
|
|
33
|
-
GET /users?status=active&role=admin
|
|
34
|
-
|
|
35
|
-
# Sorting
|
|
36
|
-
GET /users?sort=created_at:desc,name:asc
|
|
37
|
-
|
|
38
|
-
# Field selection
|
|
39
|
-
GET /users?fields=id,name,email
|
|
40
|
-
|
|
41
|
-
# Search
|
|
42
|
-
GET /users?search=john
|
|
43
|
-
|
|
44
|
-
# Combined
|
|
45
|
-
GET /users?status=active&sort=name:asc&page=1&limit=10
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Response Format
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
// Success Response
|
|
52
|
-
interface SuccessResponse<T> {
|
|
53
|
-
success: true
|
|
54
|
-
data: T
|
|
55
|
-
meta?: {
|
|
56
|
-
pagination?: {
|
|
57
|
-
page: number
|
|
58
|
-
limit: number
|
|
59
|
-
total: number
|
|
60
|
-
totalPages: number
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Error Response
|
|
66
|
-
interface ErrorResponse {
|
|
67
|
-
success: false
|
|
68
|
-
error: {
|
|
69
|
-
code: string // Machine-readable code
|
|
70
|
-
message: string // Human-readable message
|
|
71
|
-
details?: Array<{
|
|
72
|
-
field?: string
|
|
73
|
-
message: string
|
|
74
|
-
}>
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Example Responses
|
|
80
|
-
|
|
81
|
-
```json
|
|
82
|
-
// GET /users - Success
|
|
83
|
-
{
|
|
84
|
-
"success": true,
|
|
85
|
-
"data": [
|
|
86
|
-
{ "id": "1", "name": "John", "email": "john@example.com" }
|
|
87
|
-
],
|
|
88
|
-
"meta": {
|
|
89
|
-
"pagination": {
|
|
90
|
-
"page": 1,
|
|
91
|
-
"limit": 20,
|
|
92
|
-
"total": 150,
|
|
93
|
-
"totalPages": 8
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// POST /users - Validation Error
|
|
99
|
-
{
|
|
100
|
-
"success": false,
|
|
101
|
-
"error": {
|
|
102
|
-
"code": "VALIDATION_ERROR",
|
|
103
|
-
"message": "Invalid input data",
|
|
104
|
-
"details": [
|
|
105
|
-
{ "field": "email", "message": "Invalid email format" },
|
|
106
|
-
{ "field": "password", "message": "Must be at least 8 characters" }
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## HTTP Status Codes
|
|
113
|
-
|
|
114
|
-
```
|
|
115
|
-
2xx Success:
|
|
116
|
-
200 OK - GET, PUT, PATCH success
|
|
117
|
-
201 Created - POST success
|
|
118
|
-
204 No Content - DELETE success
|
|
119
|
-
|
|
120
|
-
4xx Client Error:
|
|
121
|
-
400 Bad Request - Invalid syntax
|
|
122
|
-
401 Unauthorized - No/invalid authentication
|
|
123
|
-
403 Forbidden - Authenticated but not authorized
|
|
124
|
-
404 Not Found - Resource doesn't exist
|
|
125
|
-
409 Conflict - Resource conflict (duplicate)
|
|
126
|
-
422 Unprocessable - Validation error
|
|
127
|
-
429 Too Many - Rate limit exceeded
|
|
128
|
-
|
|
129
|
-
5xx Server Error:
|
|
130
|
-
500 Internal Error - Server failure
|
|
131
|
-
502 Bad Gateway - Upstream failure
|
|
132
|
-
503 Unavailable - Service overloaded
|
|
133
|
-
504 Gateway Timeout - Upstream timeout
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
## Authentication
|
|
137
|
-
|
|
138
|
-
### JWT Token Structure
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
// Access Token (short-lived: 15min)
|
|
142
|
-
interface AccessToken {
|
|
143
|
-
sub: string // User ID
|
|
144
|
-
email: string
|
|
145
|
-
role: string
|
|
146
|
-
iat: number // Issued at
|
|
147
|
-
exp: number // Expiration
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Refresh Token (long-lived: 7 days)
|
|
151
|
-
interface RefreshToken {
|
|
152
|
-
sub: string
|
|
153
|
-
jti: string // Token ID (for revocation)
|
|
154
|
-
iat: number
|
|
155
|
-
exp: number
|
|
156
|
-
}
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### Auth Flow
|
|
160
|
-
|
|
161
|
-
```
|
|
162
|
-
1. Login
|
|
163
|
-
POST /auth/login
|
|
164
|
-
{ "email": "...", "password": "..." }
|
|
165
|
-
→ { "accessToken": "...", "refreshToken": "..." }
|
|
166
|
-
|
|
167
|
-
2. Access Protected Resource
|
|
168
|
-
GET /users
|
|
169
|
-
Authorization: Bearer <accessToken>
|
|
170
|
-
|
|
171
|
-
3. Refresh Token
|
|
172
|
-
POST /auth/refresh
|
|
173
|
-
{ "refreshToken": "..." }
|
|
174
|
-
→ { "accessToken": "...", "refreshToken": "..." }
|
|
175
|
-
|
|
176
|
-
4. Logout
|
|
177
|
-
POST /auth/logout
|
|
178
|
-
{ "refreshToken": "..." }
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
## Rate Limiting
|
|
182
|
-
|
|
183
|
-
```typescript
|
|
184
|
-
// Response Headers
|
|
185
|
-
{
|
|
186
|
-
'X-RateLimit-Limit': '100', // Max requests per window
|
|
187
|
-
'X-RateLimit-Remaining': '95', // Remaining requests
|
|
188
|
-
'X-RateLimit-Reset': '1640000000', // Window reset timestamp
|
|
189
|
-
'Retry-After': '60' // Seconds until retry (on 429)
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## Versioning
|
|
194
|
-
|
|
195
|
-
```
|
|
196
|
-
# URL Path (Recommended)
|
|
197
|
-
/api/v1/users
|
|
198
|
-
/api/v2/users
|
|
199
|
-
|
|
200
|
-
# Header
|
|
201
|
-
Accept: application/vnd.api+json;version=1
|
|
202
|
-
|
|
203
|
-
# Query Parameter
|
|
204
|
-
/api/users?version=1
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
## OpenAPI Specification
|
|
208
|
-
|
|
209
|
-
```yaml
|
|
210
|
-
openapi: 3.0.3
|
|
211
|
-
info:
|
|
212
|
-
title: My API
|
|
213
|
-
version: 1.0.0
|
|
214
|
-
description: API for managing resources
|
|
215
|
-
|
|
216
|
-
servers:
|
|
217
|
-
- url: https://api.example.com/v1
|
|
218
|
-
|
|
219
|
-
paths:
|
|
220
|
-
/users:
|
|
221
|
-
get:
|
|
222
|
-
summary: List users
|
|
223
|
-
tags: [Users]
|
|
224
|
-
parameters:
|
|
225
|
-
- name: page
|
|
226
|
-
in: query
|
|
227
|
-
schema:
|
|
228
|
-
type: integer
|
|
229
|
-
default: 1
|
|
230
|
-
- name: limit
|
|
231
|
-
in: query
|
|
232
|
-
schema:
|
|
233
|
-
type: integer
|
|
234
|
-
default: 20
|
|
235
|
-
maximum: 100
|
|
236
|
-
responses:
|
|
237
|
-
'200':
|
|
238
|
-
description: Success
|
|
239
|
-
content:
|
|
240
|
-
application/json:
|
|
241
|
-
schema:
|
|
242
|
-
$ref: '#/components/schemas/UserList'
|
|
243
|
-
|
|
244
|
-
post:
|
|
245
|
-
summary: Create user
|
|
246
|
-
tags: [Users]
|
|
247
|
-
requestBody:
|
|
248
|
-
required: true
|
|
249
|
-
content:
|
|
250
|
-
application/json:
|
|
251
|
-
schema:
|
|
252
|
-
$ref: '#/components/schemas/CreateUser'
|
|
253
|
-
responses:
|
|
254
|
-
'201':
|
|
255
|
-
description: Created
|
|
256
|
-
'422':
|
|
257
|
-
description: Validation error
|
|
258
|
-
|
|
259
|
-
components:
|
|
260
|
-
schemas:
|
|
261
|
-
User:
|
|
262
|
-
type: object
|
|
263
|
-
properties:
|
|
264
|
-
id:
|
|
265
|
-
type: string
|
|
266
|
-
name:
|
|
267
|
-
type: string
|
|
268
|
-
email:
|
|
269
|
-
type: string
|
|
270
|
-
format: email
|
|
271
|
-
required: [id, name, email]
|
|
272
|
-
|
|
273
|
-
CreateUser:
|
|
274
|
-
type: object
|
|
275
|
-
properties:
|
|
276
|
-
name:
|
|
277
|
-
type: string
|
|
278
|
-
minLength: 1
|
|
279
|
-
email:
|
|
280
|
-
type: string
|
|
281
|
-
format: email
|
|
282
|
-
password:
|
|
283
|
-
type: string
|
|
284
|
-
minLength: 8
|
|
285
|
-
required: [name, email, password]
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
## Best Practices Checklist
|
|
289
|
-
|
|
290
|
-
- [ ] Use nouns for resources, not verbs
|
|
291
|
-
- [ ] Use plural nouns (/users not /user)
|
|
292
|
-
- [ ] Use proper HTTP methods
|
|
293
|
-
- [ ] Return appropriate status codes
|
|
294
|
-
- [ ] Implement pagination for lists
|
|
295
|
-
- [ ] Support filtering and sorting
|
|
296
|
-
- [ ] Use consistent error format
|
|
297
|
-
- [ ] Implement rate limiting
|
|
298
|
-
- [ ] Version your API
|
|
299
|
-
- [ ] Document with OpenAPI
|