forgecraft-mcp 1.1.0 → 1.3.2

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.
Files changed (142) hide show
  1. package/README.md +525 -525
  2. package/dist/cli/help.js +44 -44
  3. package/dist/registry/renderer-skeletons.js +92 -92
  4. package/dist/shared/gs-score-logger.js +6 -6
  5. package/dist/tools/add-module.js +123 -123
  6. package/dist/tools/advice-registry.js +18 -18
  7. package/dist/tools/check-cascade-report.js +64 -64
  8. package/dist/tools/configure-mcp.d.ts +3 -0
  9. package/dist/tools/configure-mcp.d.ts.map +1 -1
  10. package/dist/tools/configure-mcp.js +10 -0
  11. package/dist/tools/configure-mcp.js.map +1 -1
  12. package/dist/tools/forgecraft-dispatch.d.ts.map +1 -1
  13. package/dist/tools/forgecraft-dispatch.js +3 -0
  14. package/dist/tools/forgecraft-dispatch.js.map +1 -1
  15. package/dist/tools/forgecraft-schema-params.d.ts +9 -0
  16. package/dist/tools/forgecraft-schema-params.d.ts.map +1 -1
  17. package/dist/tools/forgecraft-schema-params.js +21 -0
  18. package/dist/tools/forgecraft-schema-params.js.map +1 -1
  19. package/dist/tools/forgecraft-schema.d.ts +9 -0
  20. package/dist/tools/forgecraft-schema.d.ts.map +1 -1
  21. package/dist/tools/refresh-output.js +14 -14
  22. package/dist/tools/scaffold-spec-stubs.d.ts +43 -0
  23. package/dist/tools/scaffold-spec-stubs.d.ts.map +1 -1
  24. package/dist/tools/scaffold-spec-stubs.js +166 -24
  25. package/dist/tools/scaffold-spec-stubs.js.map +1 -1
  26. package/dist/tools/scaffold-templates.js +62 -62
  27. package/dist/tools/scaffold-writer.d.ts.map +1 -1
  28. package/dist/tools/scaffold-writer.js +11 -3
  29. package/dist/tools/scaffold-writer.js.map +1 -1
  30. package/dist/tools/setup-artifact-writers.d.ts +30 -0
  31. package/dist/tools/setup-artifact-writers.d.ts.map +1 -1
  32. package/dist/tools/setup-artifact-writers.js +120 -8
  33. package/dist/tools/setup-artifact-writers.js.map +1 -1
  34. package/dist/tools/setup-phase1.d.ts +3 -0
  35. package/dist/tools/setup-phase1.d.ts.map +1 -1
  36. package/dist/tools/setup-phase1.js +79 -35
  37. package/dist/tools/setup-phase1.js.map +1 -1
  38. package/dist/tools/setup-phase2.d.ts +2 -0
  39. package/dist/tools/setup-phase2.d.ts.map +1 -1
  40. package/dist/tools/setup-phase2.js +10 -1
  41. package/dist/tools/setup-phase2.js.map +1 -1
  42. package/dist/tools/setup-project.d.ts +18 -0
  43. package/dist/tools/setup-project.d.ts.map +1 -1
  44. package/dist/tools/setup-project.js +77 -1
  45. package/dist/tools/setup-project.js.map +1 -1
  46. package/dist/tools/spec-parser-tags.d.ts +9 -0
  47. package/dist/tools/spec-parser-tags.d.ts.map +1 -1
  48. package/dist/tools/spec-parser-tags.js +92 -0
  49. package/dist/tools/spec-parser-tags.js.map +1 -1
  50. package/package.json +89 -86
  51. package/templates/analytics/instructions.yaml +37 -37
  52. package/templates/analytics/mcp-servers.yaml +11 -11
  53. package/templates/analytics/structure.yaml +25 -25
  54. package/templates/api/instructions.yaml +231 -231
  55. package/templates/api/mcp-servers.yaml +22 -13
  56. package/templates/api/nfr.yaml +23 -23
  57. package/templates/api/review.yaml +103 -103
  58. package/templates/api/structure.yaml +34 -34
  59. package/templates/api/verification.yaml +132 -132
  60. package/templates/cli/instructions.yaml +31 -31
  61. package/templates/cli/mcp-servers.yaml +11 -11
  62. package/templates/cli/review.yaml +53 -53
  63. package/templates/cli/structure.yaml +16 -16
  64. package/templates/data-lineage/instructions.yaml +28 -28
  65. package/templates/data-lineage/mcp-servers.yaml +22 -22
  66. package/templates/data-pipeline/instructions.yaml +84 -84
  67. package/templates/data-pipeline/mcp-servers.yaml +13 -13
  68. package/templates/data-pipeline/nfr.yaml +39 -39
  69. package/templates/data-pipeline/structure.yaml +23 -23
  70. package/templates/fintech/hooks.yaml +55 -55
  71. package/templates/fintech/instructions.yaml +112 -112
  72. package/templates/fintech/mcp-servers.yaml +13 -13
  73. package/templates/fintech/nfr.yaml +46 -46
  74. package/templates/fintech/playbook.yaml +210 -210
  75. package/templates/fintech/verification.yaml +239 -239
  76. package/templates/game/instructions.yaml +289 -289
  77. package/templates/game/mcp-servers.yaml +38 -38
  78. package/templates/game/nfr.yaml +64 -64
  79. package/templates/game/playbook.yaml +214 -214
  80. package/templates/game/review.yaml +97 -97
  81. package/templates/game/structure.yaml +67 -67
  82. package/templates/game/verification.yaml +174 -174
  83. package/templates/healthcare/instructions.yaml +42 -42
  84. package/templates/healthcare/mcp-servers.yaml +13 -13
  85. package/templates/healthcare/nfr.yaml +47 -47
  86. package/templates/hipaa/instructions.yaml +41 -41
  87. package/templates/hipaa/mcp-servers.yaml +13 -13
  88. package/templates/infra/instructions.yaml +104 -104
  89. package/templates/infra/mcp-servers.yaml +20 -20
  90. package/templates/infra/nfr.yaml +46 -46
  91. package/templates/infra/review.yaml +65 -65
  92. package/templates/infra/structure.yaml +25 -25
  93. package/templates/library/instructions.yaml +36 -36
  94. package/templates/library/mcp-servers.yaml +20 -20
  95. package/templates/library/review.yaml +56 -56
  96. package/templates/library/structure.yaml +19 -19
  97. package/templates/medallion-architecture/instructions.yaml +41 -41
  98. package/templates/medallion-architecture/mcp-servers.yaml +22 -22
  99. package/templates/ml/instructions.yaml +85 -85
  100. package/templates/ml/mcp-servers.yaml +11 -11
  101. package/templates/ml/nfr.yaml +39 -39
  102. package/templates/ml/structure.yaml +25 -25
  103. package/templates/ml/verification.yaml +156 -156
  104. package/templates/mobile/instructions.yaml +44 -44
  105. package/templates/mobile/mcp-servers.yaml +11 -11
  106. package/templates/mobile/nfr.yaml +49 -49
  107. package/templates/mobile/structure.yaml +27 -27
  108. package/templates/mobile/verification.yaml +121 -121
  109. package/templates/observability-xray/instructions.yaml +40 -40
  110. package/templates/observability-xray/mcp-servers.yaml +15 -15
  111. package/templates/realtime/instructions.yaml +42 -42
  112. package/templates/realtime/mcp-servers.yaml +13 -13
  113. package/templates/soc2/instructions.yaml +41 -41
  114. package/templates/soc2/mcp-servers.yaml +24 -24
  115. package/templates/social/instructions.yaml +43 -43
  116. package/templates/social/mcp-servers.yaml +24 -24
  117. package/templates/state-machine/instructions.yaml +42 -42
  118. package/templates/state-machine/mcp-servers.yaml +11 -11
  119. package/templates/tools-registry.yaml +164 -164
  120. package/templates/universal/hooks.yaml +531 -531
  121. package/templates/universal/instructions.yaml +1692 -1681
  122. package/templates/universal/mcp-servers.yaml +50 -50
  123. package/templates/universal/nfr.yaml +197 -197
  124. package/templates/universal/reference.yaml +326 -326
  125. package/templates/universal/review.yaml +204 -204
  126. package/templates/universal/skills.yaml +262 -262
  127. package/templates/universal/structure.yaml +67 -67
  128. package/templates/universal/verification.yaml +416 -416
  129. package/templates/web-react/hooks.yaml +44 -44
  130. package/templates/web-react/instructions.yaml +207 -207
  131. package/templates/web-react/mcp-servers.yaml +20 -20
  132. package/templates/web-react/nfr.yaml +27 -27
  133. package/templates/web-react/review.yaml +94 -94
  134. package/templates/web-react/structure.yaml +46 -46
  135. package/templates/web-react/verification.yaml +126 -126
  136. package/templates/web-static/instructions.yaml +115 -115
  137. package/templates/web-static/mcp-servers.yaml +20 -20
  138. package/templates/web3/instructions.yaml +44 -44
  139. package/templates/web3/mcp-servers.yaml +11 -11
  140. package/templates/web3/verification.yaml +159 -159
  141. package/templates/zero-trust/instructions.yaml +41 -41
  142. package/templates/zero-trust/mcp-servers.yaml +15 -15
@@ -1,231 +1,231 @@
1
- tag: API
2
- section: instructions
3
- blocks:
4
- - id: api-standards
5
- tier: recommended
6
- title: "API Service Standards"
7
- content: |
8
- ## API Standards
9
-
10
- ### Contract First
11
- - Define OpenAPI/JSON Schema spec before implementing endpoints.
12
- - Generate types from spec — don't manually duplicate.
13
- - Spec is the source of truth. Implementation must match.
14
-
15
- ### Design Rules
16
- - Version from day one: /api/v1/...
17
- - Proper HTTP semantics: GET reads, POST creates, PUT replaces, PATCH updates, DELETE removes.
18
- - Pagination on ALL list endpoints. Never return unbounded results.
19
- - Consistent response envelope: { data, meta, errors }.
20
- - Async operations return job ID + polling endpoint, not blocking results.
21
- - Rate limiting on all public endpoints.
22
-
23
- ### Validation
24
- - Input validation at API boundary — reject malformed requests before they reach services.
25
- - Use schema validation (Pydantic, Zod, Joi) not manual if-checks.
26
- - Validate request body, query params, path params, and headers.
27
- - Return 422 with specific field errors, not generic 400.
28
-
29
- ### Authentication & Authorization
30
- - Auth middleware/guards at router level, not checked inside handlers.
31
- - Role-based or policy-based access control via decorators/middleware.
32
- - Never trust client-sent user identity — always verify from token/session.
33
-
34
- ### Database & Migrations
35
- - Schema changes managed through migration files (Prisma Migrate, Knex, Flyway, Alembic).
36
- - Every migration must be reversible (up + down). Test rollbacks.
37
- - Never modify a deployed migration — create a new one.
38
- - Seed data separate from migrations. Test seeds run in CI.
39
-
40
- ### Security (OWASP Top 10)
41
- - **Injection**: Parameterized queries only. No string concatenation for SQL, commands, or LDAP.
42
- - **Broken Auth**: Rate-limit login attempts. Enforce strong passwords. Rotate tokens.
43
- - **Sensitive Data Exposure**: Encrypt at rest (AES-256). Never log PII, tokens, or passwords.
44
- - **XXE/XSS**: Sanitize all user-generated HTML. Content-Security-Policy headers on all responses.
45
- - **Broken Access Control**: Enforce ownership checks — users can't access other users' resources.
46
- - **Security Misconfiguration**: No default credentials. No verbose error messages in production.
47
- Security headers: X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy.
48
- - **CSRF**: Token-based protection on all state-changing endpoints (unless using SameSite cookies + bearer tokens).
49
- - **Audit logging**: Log WHO did WHAT, WHEN, to WHICH resource. Separate from application logs.
50
- Immutable. Retained per compliance requirements.
51
-
52
- ### Graceful Shutdown
53
- - Handle SIGTERM: stop accepting new requests, drain in-flight requests, close DB connections, exit.
54
- - Kubernetes: readiness probe fails immediately, liveness continues during drain.
55
- - Shutdown timeout configurable (default: 30s). Force exit after timeout.
56
-
57
- - id: api-stack-constraints
58
- tier: core
59
- title: "API Stack Constraints"
60
- content: |
61
- ## API Stack Constraints — Approved Dependency Choices
62
-
63
- These are the **approved libraries for this API project**.
64
- Every choice has a banned alternative with a concrete reason.
65
- If you reach for a banned alternative, stop and use the approved one instead.
66
- Rationale is stated so you understand the constraint — not so you can argue around it.
67
-
68
- {{#if language_is_typescript}}
69
- ### TypeScript API — Required Packages
70
-
71
- | Concern | Use | Do NOT use | Reason |
72
- |---|---|---|---|
73
- | **Password hashing** | `argon2@^0.31` | `bcrypt`, `bcryptjs` | `bcrypt` requires a native module (`@mapbox/node-pre-gyp`) that pulls in an old `tar` CVE chain. `argon2` is pure JS, faster, OWASP-preferred. |
74
- | **HTTP framework** | `express@^4` or `fastify@^4` | `restify`, `hapi@<21`, `koa` alone | `restify` is unmaintained. `hapi` is fine at `^21+` only. |
75
- | **Input validation** | `zod@^3` | `joi` alone, `express-validator` alone | `zod` infers TypeScript types natively — no separate type declaration needed. |
76
- | **JWT** | `jsonwebtoken@^9` | `jwt-simple` (abandoned), `jsonwebtoken@<9` | Security fixes landed in v9. `jwt-simple` has no active maintainer. |
77
- | **ORM / query builder** | `@prisma/client@^5` or `kysely@^0.27` | `typeorm`, `sequelize` | `typeorm` uses decorators (not type-safe), slow migrations. `sequelize` has weak TypeScript support. |
78
- | **Logger** | `pino@^9` | `winston` alone, `console.log` in prod | `pino` is 5–10× faster than `winston` and outputs structured JSON natively. `console.log` is not structured. |
79
- | **HTTP client (outbound)** | `undici@^6` or native `fetch` (Node 18+) | `axios` for Node ≥18 | Native `fetch` is available; `axios` adds bundle weight and a dependency surface for a built-in feature. |
80
- | **ESLint** | `@typescript-eslint/eslint-plugin@^8` | `@typescript-eslint@^5` or `^6` | `^6` has a known CVE via old `minimatch` transitive dep. `^8` is the current stable. |
81
-
82
- **npm audit policy**: `npm audit` must return zero `high` or `critical` findings before the
83
- first commit. If a dependency introduces a high/critical CVE, replace it with an alternative
84
- from this table or open an ADR documenting the exception with mitigation.
85
- {{/if}}
86
-
87
- {{#if language_is_python}}
88
- ### Python API — Required Packages
89
-
90
- | Concern | Use | Do NOT use | Reason |
91
- |---|---|---|---|
92
- | **Web framework** | `fastapi@^0.110` | `flask` for new async APIs | Flask has no native `async` request handling at the framework level — blocks on every request without extra extensions. |
93
- | **Validation** | `pydantic@^2` | `pydantic@^1` | v2 is 5–50× faster. v1 is not maintained for new projects. Breaking API — pin to `^2`. |
94
- | **Password hashing** | `argon2-cffi@^23` | `hashlib` for passwords, `MD5/SHA256` for passwords | `hashlib` is not a KDF — it is trivially reversible with a GPU. `argon2` wins OWASP Password Hashing Competition. |
95
- | **JWT** | `PyJWT@^2.8` or `python-jose[cryptography]@^3.3` | `python-jwt` (unmaintained), `itsdangerous` alone | `python-jwt` has no active maintainer. `itsdangerous` is for URL-safe tokens, not JWT. |
96
- | **ORM** | `sqlalchemy@^2.0` with `asyncpg` | `sqlalchemy@^1.x` | v2 has a fundamentally better async story and type-annotated query API. |
97
- | **HTTP client** | `httpx@^0.27` | `requests` in async code | `requests` is sync-only — it will block the asyncio event loop. |
98
- | **Logger** | `structlog@^24` | bare `logging` module in production | Unstructured log lines are not machine-parseable. `structlog` wraps `logging` with structured output. |
99
- | **Linting** | `ruff@^0.4` | `flake8` + `isort` + `black` separately | `ruff` replaces all three with one tool 10–100× faster. No reason to run them separately. |
100
-
101
- **pip audit policy**: `pip audit` must return zero `high` or `critical` findings before the
102
- first commit. If a dependency introduces a high/critical CVE, replace it or open an ADR.
103
- {{/if}}
104
-
105
- - id: api-deployment
106
- tier: recommended
107
- title: "API Deployment & Hosting"
108
- content: |
109
- ## API Deployment
110
-
111
- ### Container-Based (Production)
112
- - Multi-stage Dockerfile: builder stage (install + compile) → runtime stage (minimal image, non-root).
113
- - Pin base image digests, not just tags. Scan images for CVEs in CI (Trivy, Grype).
114
- - Push to container registry (ECR, GCR, GHCR) on every merge to main.
115
- - Orchestrate with Kubernetes, ECS, or Cloud Run. Define resource limits for every container.
116
-
117
- ### PaaS / Quick Deploy
118
- - **Railway**: Git-push deploy with auto-detected Dockerfile or Nixpacks. Ideal for staging and side projects.
119
- - **Render**: Free tier + auto-deploy from Git. Native cron jobs, managed Postgres.
120
- - **Fly.io**: Edge deployment with Firecracker VMs. Good for low-latency APIs. `fly deploy` from CI.
121
- - All PaaS platforms: use platform env vars for secrets, connect managed DB add-ons, enable auto-sleep
122
- for non-production to control cost.
123
-
124
- ### Environment Management
125
- - One Dockerfile, many environments. Same image runs in dev, staging, prod.
126
- - Health check endpoint (`/health`) returns: status, version, uptime, dependency connectivity.
127
- - Database connection pooling configured per environment (dev: 5, staging: 20, prod: 50+).
128
- - Migrations run automatically on deploy (pre-deploy hook or init container). Never manually.
129
-
130
- - id: api-testing
131
- tier: recommended
132
- title: "API-Specific Testing Requirements"
133
- content: |
134
- ## API-Specific Testing Requirements
135
-
136
- ### Contract / Consumer-Driven Contract (CDC) — Mandatory
137
- CDC is not optional for API projects. The consumer writes the pact file; the provider verifies it in CI before deployment. API breakage that passes all provider-side tests but fails consumers is the exact class of defect CDC prevents.
138
- - Use Pact or Spring Cloud Contract.
139
- - Pact broker (self-hosted or pactflow.io) stores pact files and verification results.
140
- - Provider verification runs in CI on every build — a failed verification blocks deployment.
141
- - CDC covers request schema, response schema, status codes, and error shapes. It does not cover load or security — those are separate gates.
142
-
143
- ### API / Subcutaneous Tests as Primary Integration Layer
144
- The subcutaneous layer (HTTP requests to a running server with real DB and stubbed external deps) is the primary integration verification surface for API projects. Unit tests verify logic; subcutaneous tests verify contracts.
145
- - Use Supertest (Node) or httpx/pytest (Python) against a locally started server instance.
146
- - Stub external services with WireMock, msw, or responses (Python). Never call real external APIs in CI.
147
- - Every public endpoint has a subcutaneous test for: 200 happy path, 4xx validation rejection, 401/403 auth enforcement, and at least one edge case.
148
-
149
- ### DAST at Staging — Mandatory
150
- Dynamic application security testing is required before every production promotion. OWASP ZAP minimum.
151
- - Run ZAP active scan against the staging environment as a post-deploy CI step.
152
- - Define an acceptable risk threshold in the spec: which finding severities are blocking (High = always blocking; Medium/Low = tracked, not blocking by default).
153
- - ZAP scan configuration committed to the repo (`zap-config.yaml`). Not a one-off manual step.
154
-
155
- ### Rate Limiting and Throttling in Integration Layer
156
- - Rate limit behavior must be covered in the subcutaneous integration suite, not just documented.
157
- - Test: normal traffic (no throttle), burst traffic (trigger rate limit, receive 429), retry-after header present and correct.
158
- - Test quota exhaustion and quota reset behavior for API-key-based limits.
159
-
160
-
161
- ### Scaling
162
- - Horizontal scaling by default. No in-memory session state — use Redis or DB.
163
- - Auto-scaling rules based on CPU + request queue depth, not just CPU alone.
164
- - Database read replicas for read-heavy workloads. Connection pooler (PgBouncer) in front of Postgres.
165
-
166
- - id: api-smoke-testing
167
- tier: recommended
168
- title: "API Smoke Testing (Post-Deploy)"
169
- content: |
170
- ## API Smoke Testing
171
-
172
- ### Required: Playwright APIRequestContext (no browser overhead)
173
- Tag all smoke tests `@smoke` for isolated execution:
174
- ```
175
- npx playwright test --config playwright.smoke.config.ts --grep @smoke
176
- ```
177
-
178
- Minimum smoke suite for every API:
179
- - **Health check**: `GET /health` → 200, body includes `status: ok` and `version`
180
- - **Auth**: primary login endpoint with valid credentials → token returned
181
- - **Primary read**: one representative `GET` → 200, response envelope validates
182
- - **Primary write**: one representative `POST` → 2xx, verify with follow-up `GET`
183
- - **404 shape**: non-existent resource → 404, error envelope matches spec contract
184
-
185
- ```typescript
186
- // tests/smoke/api.smoke.ts
187
- import { test, expect } from '@playwright/test';
188
-
189
- test('@smoke health check', async ({ request }) => {
190
- const res = await request.get('/health');
191
- expect(res.ok()).toBeTruthy();
192
- const body = await res.json();
193
- expect(body).toMatchObject({ status: 'ok' });
194
- });
195
-
196
- test('@smoke auth returns token', async ({ request }) => {
197
- const res = await request.post('/api/v1/auth/login', {
198
- data: {
199
- email: process.env['SMOKE_USER'],
200
- password: process.env['SMOKE_PASSWORD'],
201
- },
202
- });
203
- expect(res.status()).toBe(200);
204
- const body = await res.json();
205
- expect(typeof body.token ?? body.data?.token).toBe('string');
206
- });
207
- ```
208
-
209
- ```typescript
210
- // playwright.smoke.config.ts
211
- import { defineConfig } from '@playwright/test';
212
- export default defineConfig({
213
- use: { baseURL: process.env['PLAYWRIGHT_BASE_URL'] ?? 'http://localhost:3000' },
214
- testMatch: '**/*.smoke.ts',
215
- retries: 1,
216
- timeout: 10_000,
217
- });
218
- ```
219
-
220
- Smoke tests run against the **deployed staging URL** only (`PLAYWRIGHT_BASE_URL` env var).
221
- They never run against localhost in CI — that is the integration suite's job.
222
-
223
- CI integration (post-deploy step):
224
- ```yaml
225
- - name: Smoke Tests
226
- run: npx playwright test --config playwright.smoke.config.ts
227
- env:
228
- PLAYWRIGHT_BASE_URL: ${{ env.STAGING_URL }}
229
- SMOKE_USER: ${{ secrets.SMOKE_USER }}
230
- SMOKE_PASSWORD: ${{ secrets.SMOKE_PASSWORD }}
231
- ```
1
+ tag: API
2
+ section: instructions
3
+ blocks:
4
+ - id: api-standards
5
+ tier: recommended
6
+ title: "API Service Standards"
7
+ content: |
8
+ ## API Standards
9
+
10
+ ### Contract First
11
+ - Define OpenAPI/JSON Schema spec before implementing endpoints.
12
+ - Generate types from spec — don't manually duplicate.
13
+ - Spec is the source of truth. Implementation must match.
14
+
15
+ ### Design Rules
16
+ - Version from day one: /api/v1/...
17
+ - Proper HTTP semantics: GET reads, POST creates, PUT replaces, PATCH updates, DELETE removes.
18
+ - Pagination on ALL list endpoints. Never return unbounded results.
19
+ - Consistent response envelope: { data, meta, errors }.
20
+ - Async operations return job ID + polling endpoint, not blocking results.
21
+ - Rate limiting on all public endpoints.
22
+
23
+ ### Validation
24
+ - Input validation at API boundary — reject malformed requests before they reach services.
25
+ - Use schema validation (Pydantic, Zod, Joi) not manual if-checks.
26
+ - Validate request body, query params, path params, and headers.
27
+ - Return 422 with specific field errors, not generic 400.
28
+
29
+ ### Authentication & Authorization
30
+ - Auth middleware/guards at router level, not checked inside handlers.
31
+ - Role-based or policy-based access control via decorators/middleware.
32
+ - Never trust client-sent user identity — always verify from token/session.
33
+
34
+ ### Database & Migrations
35
+ - Schema changes managed through migration files (Prisma Migrate, Knex, Flyway, Alembic).
36
+ - Every migration must be reversible (up + down). Test rollbacks.
37
+ - Never modify a deployed migration — create a new one.
38
+ - Seed data separate from migrations. Test seeds run in CI.
39
+
40
+ ### Security (OWASP Top 10)
41
+ - **Injection**: Parameterized queries only. No string concatenation for SQL, commands, or LDAP.
42
+ - **Broken Auth**: Rate-limit login attempts. Enforce strong passwords. Rotate tokens.
43
+ - **Sensitive Data Exposure**: Encrypt at rest (AES-256). Never log PII, tokens, or passwords.
44
+ - **XXE/XSS**: Sanitize all user-generated HTML. Content-Security-Policy headers on all responses.
45
+ - **Broken Access Control**: Enforce ownership checks — users can't access other users' resources.
46
+ - **Security Misconfiguration**: No default credentials. No verbose error messages in production.
47
+ Security headers: X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy.
48
+ - **CSRF**: Token-based protection on all state-changing endpoints (unless using SameSite cookies + bearer tokens).
49
+ - **Audit logging**: Log WHO did WHAT, WHEN, to WHICH resource. Separate from application logs.
50
+ Immutable. Retained per compliance requirements.
51
+
52
+ ### Graceful Shutdown
53
+ - Handle SIGTERM: stop accepting new requests, drain in-flight requests, close DB connections, exit.
54
+ - Kubernetes: readiness probe fails immediately, liveness continues during drain.
55
+ - Shutdown timeout configurable (default: 30s). Force exit after timeout.
56
+
57
+ - id: api-stack-constraints
58
+ tier: core
59
+ title: "API Stack Constraints"
60
+ content: |
61
+ ## API Stack Constraints — Approved Dependency Choices
62
+
63
+ These are the **approved libraries for this API project**.
64
+ Every choice has a banned alternative with a concrete reason.
65
+ If you reach for a banned alternative, stop and use the approved one instead.
66
+ Rationale is stated so you understand the constraint — not so you can argue around it.
67
+
68
+ {{#if language_is_typescript}}
69
+ ### TypeScript API — Required Packages
70
+
71
+ | Concern | Use | Do NOT use | Reason |
72
+ |---|---|---|---|
73
+ | **Password hashing** | `argon2@^0.31` | `bcrypt`, `bcryptjs` | `bcrypt` requires a native module (`@mapbox/node-pre-gyp`) that pulls in an old `tar` CVE chain. `argon2` is pure JS, faster, OWASP-preferred. |
74
+ | **HTTP framework** | `express@^4` or `fastify@^4` | `restify`, `hapi@<21`, `koa` alone | `restify` is unmaintained. `hapi` is fine at `^21+` only. |
75
+ | **Input validation** | `zod@^3` | `joi` alone, `express-validator` alone | `zod` infers TypeScript types natively — no separate type declaration needed. |
76
+ | **JWT** | `jsonwebtoken@^9` | `jwt-simple` (abandoned), `jsonwebtoken@<9` | Security fixes landed in v9. `jwt-simple` has no active maintainer. |
77
+ | **ORM / query builder** | `@prisma/client@^5` or `kysely@^0.27` | `typeorm`, `sequelize` | `typeorm` uses decorators (not type-safe), slow migrations. `sequelize` has weak TypeScript support. |
78
+ | **Logger** | `pino@^9` | `winston` alone, `console.log` in prod | `pino` is 5–10× faster than `winston` and outputs structured JSON natively. `console.log` is not structured. |
79
+ | **HTTP client (outbound)** | `undici@^6` or native `fetch` (Node 18+) | `axios` for Node ≥18 | Native `fetch` is available; `axios` adds bundle weight and a dependency surface for a built-in feature. |
80
+ | **ESLint** | `@typescript-eslint/eslint-plugin@^8` | `@typescript-eslint@^5` or `^6` | `^6` has a known CVE via old `minimatch` transitive dep. `^8` is the current stable. |
81
+
82
+ **npm audit policy**: `npm audit` must return zero `high` or `critical` findings before the
83
+ first commit. If a dependency introduces a high/critical CVE, replace it with an alternative
84
+ from this table or open an ADR documenting the exception with mitigation.
85
+ {{/if}}
86
+
87
+ {{#if language_is_python}}
88
+ ### Python API — Required Packages
89
+
90
+ | Concern | Use | Do NOT use | Reason |
91
+ |---|---|---|---|
92
+ | **Web framework** | `fastapi@^0.110` | `flask` for new async APIs | Flask has no native `async` request handling at the framework level — blocks on every request without extra extensions. |
93
+ | **Validation** | `pydantic@^2` | `pydantic@^1` | v2 is 5–50× faster. v1 is not maintained for new projects. Breaking API — pin to `^2`. |
94
+ | **Password hashing** | `argon2-cffi@^23` | `hashlib` for passwords, `MD5/SHA256` for passwords | `hashlib` is not a KDF — it is trivially reversible with a GPU. `argon2` wins OWASP Password Hashing Competition. |
95
+ | **JWT** | `PyJWT@^2.8` or `python-jose[cryptography]@^3.3` | `python-jwt` (unmaintained), `itsdangerous` alone | `python-jwt` has no active maintainer. `itsdangerous` is for URL-safe tokens, not JWT. |
96
+ | **ORM** | `sqlalchemy@^2.0` with `asyncpg` | `sqlalchemy@^1.x` | v2 has a fundamentally better async story and type-annotated query API. |
97
+ | **HTTP client** | `httpx@^0.27` | `requests` in async code | `requests` is sync-only — it will block the asyncio event loop. |
98
+ | **Logger** | `structlog@^24` | bare `logging` module in production | Unstructured log lines are not machine-parseable. `structlog` wraps `logging` with structured output. |
99
+ | **Linting** | `ruff@^0.4` | `flake8` + `isort` + `black` separately | `ruff` replaces all three with one tool 10–100× faster. No reason to run them separately. |
100
+
101
+ **pip audit policy**: `pip audit` must return zero `high` or `critical` findings before the
102
+ first commit. If a dependency introduces a high/critical CVE, replace it or open an ADR.
103
+ {{/if}}
104
+
105
+ - id: api-deployment
106
+ tier: recommended
107
+ title: "API Deployment & Hosting"
108
+ content: |
109
+ ## API Deployment
110
+
111
+ ### Container-Based (Production)
112
+ - Multi-stage Dockerfile: builder stage (install + compile) → runtime stage (minimal image, non-root).
113
+ - Pin base image digests, not just tags. Scan images for CVEs in CI (Trivy, Grype).
114
+ - Push to container registry (ECR, GCR, GHCR) on every merge to main.
115
+ - Orchestrate with Kubernetes, ECS, or Cloud Run. Define resource limits for every container.
116
+
117
+ ### PaaS / Quick Deploy
118
+ - **Railway**: Git-push deploy with auto-detected Dockerfile or Nixpacks. Ideal for staging and side projects.
119
+ - **Render**: Free tier + auto-deploy from Git. Native cron jobs, managed Postgres.
120
+ - **Fly.io**: Edge deployment with Firecracker VMs. Good for low-latency APIs. `fly deploy` from CI.
121
+ - All PaaS platforms: use platform env vars for secrets, connect managed DB add-ons, enable auto-sleep
122
+ for non-production to control cost.
123
+
124
+ ### Environment Management
125
+ - One Dockerfile, many environments. Same image runs in dev, staging, prod.
126
+ - Health check endpoint (`/health`) returns: status, version, uptime, dependency connectivity.
127
+ - Database connection pooling configured per environment (dev: 5, staging: 20, prod: 50+).
128
+ - Migrations run automatically on deploy (pre-deploy hook or init container). Never manually.
129
+
130
+ - id: api-testing
131
+ tier: recommended
132
+ title: "API-Specific Testing Requirements"
133
+ content: |
134
+ ## API-Specific Testing Requirements
135
+
136
+ ### Contract / Consumer-Driven Contract (CDC) — Mandatory
137
+ CDC is not optional for API projects. The consumer writes the pact file; the provider verifies it in CI before deployment. API breakage that passes all provider-side tests but fails consumers is the exact class of defect CDC prevents.
138
+ - Use Pact or Spring Cloud Contract.
139
+ - Pact broker (self-hosted or pactflow.io) stores pact files and verification results.
140
+ - Provider verification runs in CI on every build — a failed verification blocks deployment.
141
+ - CDC covers request schema, response schema, status codes, and error shapes. It does not cover load or security — those are separate gates.
142
+
143
+ ### API / Subcutaneous Tests as Primary Integration Layer
144
+ The subcutaneous layer (HTTP requests to a running server with real DB and stubbed external deps) is the primary integration verification surface for API projects. Unit tests verify logic; subcutaneous tests verify contracts.
145
+ - Use Supertest (Node) or httpx/pytest (Python) against a locally started server instance.
146
+ - Stub external services with WireMock, msw, or responses (Python). Never call real external APIs in CI.
147
+ - Every public endpoint has a subcutaneous test for: 200 happy path, 4xx validation rejection, 401/403 auth enforcement, and at least one edge case.
148
+
149
+ ### DAST at Staging — Mandatory
150
+ Dynamic application security testing is required before every production promotion. OWASP ZAP minimum.
151
+ - Run ZAP active scan against the staging environment as a post-deploy CI step.
152
+ - Define an acceptable risk threshold in the spec: which finding severities are blocking (High = always blocking; Medium/Low = tracked, not blocking by default).
153
+ - ZAP scan configuration committed to the repo (`zap-config.yaml`). Not a one-off manual step.
154
+
155
+ ### Rate Limiting and Throttling in Integration Layer
156
+ - Rate limit behavior must be covered in the subcutaneous integration suite, not just documented.
157
+ - Test: normal traffic (no throttle), burst traffic (trigger rate limit, receive 429), retry-after header present and correct.
158
+ - Test quota exhaustion and quota reset behavior for API-key-based limits.
159
+
160
+
161
+ ### Scaling
162
+ - Horizontal scaling by default. No in-memory session state — use Redis or DB.
163
+ - Auto-scaling rules based on CPU + request queue depth, not just CPU alone.
164
+ - Database read replicas for read-heavy workloads. Connection pooler (PgBouncer) in front of Postgres.
165
+
166
+ - id: api-smoke-testing
167
+ tier: recommended
168
+ title: "API Smoke Testing (Post-Deploy)"
169
+ content: |
170
+ ## API Smoke Testing
171
+
172
+ ### Required: Playwright APIRequestContext (no browser overhead)
173
+ Tag all smoke tests `@smoke` for isolated execution:
174
+ ```
175
+ npx playwright test --config playwright.smoke.config.ts --grep @smoke
176
+ ```
177
+
178
+ Minimum smoke suite for every API:
179
+ - **Health check**: `GET /health` → 200, body includes `status: ok` and `version`
180
+ - **Auth**: primary login endpoint with valid credentials → token returned
181
+ - **Primary read**: one representative `GET` → 200, response envelope validates
182
+ - **Primary write**: one representative `POST` → 2xx, verify with follow-up `GET`
183
+ - **404 shape**: non-existent resource → 404, error envelope matches spec contract
184
+
185
+ ```typescript
186
+ // tests/smoke/api.smoke.ts
187
+ import { test, expect } from '@playwright/test';
188
+
189
+ test('@smoke health check', async ({ request }) => {
190
+ const res = await request.get('/health');
191
+ expect(res.ok()).toBeTruthy();
192
+ const body = await res.json();
193
+ expect(body).toMatchObject({ status: 'ok' });
194
+ });
195
+
196
+ test('@smoke auth returns token', async ({ request }) => {
197
+ const res = await request.post('/api/v1/auth/login', {
198
+ data: {
199
+ email: process.env['SMOKE_USER'],
200
+ password: process.env['SMOKE_PASSWORD'],
201
+ },
202
+ });
203
+ expect(res.status()).toBe(200);
204
+ const body = await res.json();
205
+ expect(typeof body.token ?? body.data?.token).toBe('string');
206
+ });
207
+ ```
208
+
209
+ ```typescript
210
+ // playwright.smoke.config.ts
211
+ import { defineConfig } from '@playwright/test';
212
+ export default defineConfig({
213
+ use: { baseURL: process.env['PLAYWRIGHT_BASE_URL'] ?? 'http://localhost:3000' },
214
+ testMatch: '**/*.smoke.ts',
215
+ retries: 1,
216
+ timeout: 10_000,
217
+ });
218
+ ```
219
+
220
+ Smoke tests run against the **deployed staging URL** only (`PLAYWRIGHT_BASE_URL` env var).
221
+ They never run against localhost in CI — that is the integration suite's job.
222
+
223
+ CI integration (post-deploy step):
224
+ ```yaml
225
+ - name: Smoke Tests
226
+ run: npx playwright test --config playwright.smoke.config.ts
227
+ env:
228
+ PLAYWRIGHT_BASE_URL: ${{ env.STAGING_URL }}
229
+ SMOKE_USER: ${{ secrets.SMOKE_USER }}
230
+ SMOKE_PASSWORD: ${{ secrets.SMOKE_PASSWORD }}
231
+ ```
@@ -1,13 +1,22 @@
1
- tag: API
2
- section: mcp-servers
3
- servers:
4
- - name: postman
5
- description: "API testing and collection management via Postman workspace"
6
- command: npx
7
- args: ["-y", "@anthropic/mcp-server-postman"]
8
- tags: [API]
9
- category: testing
10
- tier: recommended
11
- url: "https://github.com/anthropics/anthropic-quickstarts/tree/main/mcp-server-postman"
12
- env:
13
- POSTMAN_API_KEY: ""
1
+ tag: API
2
+ section: mcp-servers
3
+ servers:
4
+ - name: postman
5
+ description: "API testing and collection management via Postman workspace"
6
+ command: npx
7
+ args: ["-y", "@anthropic/mcp-server-postman"]
8
+ tags: [API]
9
+ category: testing
10
+ tier: recommended
11
+ url: "https://github.com/anthropics/anthropic-quickstarts/tree/main/mcp-server-postman"
12
+ env:
13
+ POSTMAN_API_KEY: ""
14
+
15
+ - name: playwright
16
+ description: "Browser automation for API + E2E testing, request interception, and response validation"
17
+ command: npx
18
+ args: ["-y", "@anthropic/mcp-server-playwright"]
19
+ tags: [API]
20
+ category: testing
21
+ tier: recommended
22
+ url: "https://github.com/anthropics/anthropic-quickstarts/tree/main/mcp-server-playwright"
@@ -1,23 +1,23 @@
1
- tag: API
2
- section: nfr
3
- blocks:
4
- - id: api-performance
5
- tier: recommended
6
- title: "API Performance"
7
- content: |
8
- ## NFR: API Performance
9
-
10
- ### Response Time Targets
11
- - p50: < {{p50_target | default: 50ms}}
12
- - p95: < {{p95_target | default: 200ms}}
13
- - p99: < {{p99_target | default: 500ms}}
14
-
15
- ### Throughput
16
- - Target requests/sec: {{target_rps}}
17
- - Load test before launch at 2x expected peak.
18
- - Auto-scaling configured with appropriate min/max.
19
-
20
- ### Rate Limiting
21
- - Per-client rate limits on all endpoints.
22
- - Graduated response: 429 with Retry-After header before hard block.
23
- - Rate limit bypass for internal services via separate auth.
1
+ tag: API
2
+ section: nfr
3
+ blocks:
4
+ - id: api-performance
5
+ tier: recommended
6
+ title: "API Performance"
7
+ content: |
8
+ ## NFR: API Performance
9
+
10
+ ### Response Time Targets
11
+ - p50: < {{p50_target | default: 50ms}}
12
+ - p95: < {{p95_target | default: 200ms}}
13
+ - p99: < {{p99_target | default: 500ms}}
14
+
15
+ ### Throughput
16
+ - Target requests/sec: {{target_rps}}
17
+ - Load test before launch at 2x expected peak.
18
+ - Auto-scaling configured with appropriate min/max.
19
+
20
+ ### Rate Limiting
21
+ - Per-client rate limits on all endpoints.
22
+ - Graduated response: 429 with Retry-After header before hard block.
23
+ - Rate limit bypass for internal services via separate auth.