musubi-sdd 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/LICENSE +21 -0
- package/README.ja.md +531 -0
- package/README.md +531 -0
- package/bin/musubi-init.js +321 -0
- package/bin/musubi.js +359 -0
- package/package.json +55 -0
- package/src/agents/registry.js +242 -0
- package/src/templates/agents/claude-code/CLAUDE.md +232 -0
- package/src/templates/agents/claude-code/commands/sdd-design.md +673 -0
- package/src/templates/agents/claude-code/commands/sdd-implement.md +777 -0
- package/src/templates/agents/claude-code/commands/sdd-requirements.md +438 -0
- package/src/templates/agents/claude-code/commands/sdd-steering.md +334 -0
- package/src/templates/agents/claude-code/commands/sdd-tasks.md +582 -0
- package/src/templates/agents/claude-code/commands/sdd-validate.md +710 -0
- package/src/templates/agents/claude-code/skills/ai-ml-engineer/SKILL.md +3055 -0
- package/src/templates/agents/claude-code/skills/api-designer/SKILL.md +1364 -0
- package/src/templates/agents/claude-code/skills/bug-hunter/SKILL.md +482 -0
- package/src/templates/agents/claude-code/skills/change-impact-analyzer/SKILL.md +397 -0
- package/src/templates/agents/claude-code/skills/cloud-architect/SKILL.md +1468 -0
- package/src/templates/agents/claude-code/skills/code-reviewer/SKILL.md +906 -0
- package/src/templates/agents/claude-code/skills/constitution-enforcer/SKILL.md +466 -0
- package/src/templates/agents/claude-code/skills/database-administrator/SKILL.md +3522 -0
- package/src/templates/agents/claude-code/skills/database-schema-designer/SKILL.md +1158 -0
- package/src/templates/agents/claude-code/skills/devops-engineer/SKILL.md +647 -0
- package/src/templates/agents/claude-code/skills/orchestrator/SKILL.md +574 -0
- package/src/templates/agents/claude-code/skills/performance-optimizer/SKILL.md +464 -0
- package/src/templates/agents/claude-code/skills/project-manager/SKILL.md +769 -0
- package/src/templates/agents/claude-code/skills/quality-assurance/SKILL.md +1059 -0
- package/src/templates/agents/claude-code/skills/release-coordinator/SKILL.md +653 -0
- package/src/templates/agents/claude-code/skills/requirements-analyst/SKILL.md +1287 -0
- package/src/templates/agents/claude-code/skills/security-auditor/SKILL.md +1107 -0
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/SKILL.md +404 -0
- package/src/templates/agents/claude-code/skills/software-developer/SKILL.md +1254 -0
- package/src/templates/agents/claude-code/skills/steering/SKILL.md +383 -0
- package/src/templates/agents/claude-code/skills/system-architect/SKILL.md +1288 -0
- package/src/templates/agents/claude-code/skills/technical-writer/SKILL.md +712 -0
- package/src/templates/agents/claude-code/skills/test-engineer/SKILL.md +1262 -0
- package/src/templates/agents/claude-code/skills/traceability-auditor/SKILL.md +298 -0
- package/src/templates/agents/claude-code/skills/ui-ux-designer/SKILL.md +1009 -0
- package/src/templates/agents/codex/AGENTS.md +138 -0
- package/src/templates/agents/codex/commands/sdd-design.md +673 -0
- package/src/templates/agents/codex/commands/sdd-implement.md +777 -0
- package/src/templates/agents/codex/commands/sdd-requirements.md +438 -0
- package/src/templates/agents/codex/commands/sdd-steering.md +334 -0
- package/src/templates/agents/codex/commands/sdd-tasks.md +582 -0
- package/src/templates/agents/codex/commands/sdd-validate.md +710 -0
- package/src/templates/agents/cursor/AGENTS.md +138 -0
- package/src/templates/agents/cursor/commands/sdd-design.md +673 -0
- package/src/templates/agents/cursor/commands/sdd-implement.md +777 -0
- package/src/templates/agents/cursor/commands/sdd-requirements.md +438 -0
- package/src/templates/agents/cursor/commands/sdd-steering.md +334 -0
- package/src/templates/agents/cursor/commands/sdd-tasks.md +582 -0
- package/src/templates/agents/cursor/commands/sdd-validate.md +710 -0
- package/src/templates/agents/gemini-cli/GEMINI.md +128 -0
- package/src/templates/agents/gemini-cli/commands/sdd-design.toml +359 -0
- package/src/templates/agents/gemini-cli/commands/sdd-implement.toml +484 -0
- package/src/templates/agents/gemini-cli/commands/sdd-requirements.toml +291 -0
- package/src/templates/agents/gemini-cli/commands/sdd-steering.toml +209 -0
- package/src/templates/agents/gemini-cli/commands/sdd-tasks.toml +441 -0
- package/src/templates/agents/gemini-cli/commands/sdd-validate.toml +553 -0
- package/src/templates/agents/github-copilot/AGENTS.md +138 -0
- package/src/templates/agents/github-copilot/commands/sdd-design.md +673 -0
- package/src/templates/agents/github-copilot/commands/sdd-implement.md +777 -0
- package/src/templates/agents/github-copilot/commands/sdd-requirements.md +438 -0
- package/src/templates/agents/github-copilot/commands/sdd-steering.md +334 -0
- package/src/templates/agents/github-copilot/commands/sdd-tasks.md +582 -0
- package/src/templates/agents/github-copilot/commands/sdd-validate.md +710 -0
- package/src/templates/agents/qwen-code/QWEN.md +128 -0
- package/src/templates/agents/qwen-code/commands/sdd-design.md +673 -0
- package/src/templates/agents/qwen-code/commands/sdd-implement.md +777 -0
- package/src/templates/agents/qwen-code/commands/sdd-requirements.md +438 -0
- package/src/templates/agents/qwen-code/commands/sdd-steering.md +334 -0
- package/src/templates/agents/qwen-code/commands/sdd-tasks.md +582 -0
- package/src/templates/agents/qwen-code/commands/sdd-validate.md +710 -0
- package/src/templates/agents/windsurf/AGENTS.md +138 -0
- package/src/templates/agents/windsurf/commands/sdd-design.md +673 -0
- package/src/templates/agents/windsurf/commands/sdd-implement.md +777 -0
- package/src/templates/agents/windsurf/commands/sdd-requirements.md +438 -0
- package/src/templates/agents/windsurf/commands/sdd-steering.md +334 -0
- package/src/templates/agents/windsurf/commands/sdd-tasks.md +582 -0
- package/src/templates/agents/windsurf/commands/sdd-validate.md +710 -0
- package/src/templates/shared/constitution/constitution.md +408 -0
- package/src/templates/shared/constitution/ears-format.md +613 -0
- package/src/templates/shared/constitution/workflow.md +653 -0
- package/src/templates/shared/documents/design.md +737 -0
- package/src/templates/shared/documents/requirements.md +329 -0
- package/src/templates/shared/documents/research.md +494 -0
- package/src/templates/shared/documents/tasks.md +781 -0
- package/src/templates/shared/steering/product.md +544 -0
- package/src/templates/shared/steering/structure.md +405 -0
- package/src/templates/shared/steering/tech.md +537 -0
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
# Technical Design: {{FEATURE_NAME}}
|
|
2
|
+
|
|
3
|
+
**Project**: {{PROJECT_NAME}}
|
|
4
|
+
**Version**: 1.0
|
|
5
|
+
**Status**: Draft
|
|
6
|
+
**Date**: {{DATE}}
|
|
7
|
+
**Author**: {{AUTHOR}}
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Document Control
|
|
12
|
+
|
|
13
|
+
| Version | Date | Author | Changes |
|
|
14
|
+
|---------|------|--------|---------|
|
|
15
|
+
| 1.0 | {{DATE}} | {{AUTHOR}} | Initial draft |
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
### Purpose
|
|
22
|
+
|
|
23
|
+
[Describe the technical design for implementing the requirements]
|
|
24
|
+
|
|
25
|
+
### Scope
|
|
26
|
+
|
|
27
|
+
This design covers:
|
|
28
|
+
- Architecture and component design
|
|
29
|
+
- API contracts
|
|
30
|
+
- Database schema
|
|
31
|
+
- Integration points
|
|
32
|
+
- Deployment architecture
|
|
33
|
+
|
|
34
|
+
### Requirements Reference
|
|
35
|
+
|
|
36
|
+
This design implements requirements from: [requirements.md](requirements.md)
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Steering Context
|
|
41
|
+
|
|
42
|
+
**IMPORTANT**: This design aligns with project steering context:
|
|
43
|
+
|
|
44
|
+
- **Architecture Patterns**: [steering/structure.md](../../steering/structure.md)
|
|
45
|
+
- **Technology Stack**: [steering/tech.md](../../steering/tech.md)
|
|
46
|
+
- **Product Context**: [steering/product.md](../../steering/product.md)
|
|
47
|
+
|
|
48
|
+
**Key Alignments**:
|
|
49
|
+
- Architecture pattern: [e.g., microservices, monolith, library-first]
|
|
50
|
+
- Primary language: [e.g., TypeScript, Python, Go]
|
|
51
|
+
- Framework: [e.g., Next.js, FastAPI, Express]
|
|
52
|
+
- Database: [e.g., PostgreSQL, MongoDB, MySQL]
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Architecture Design
|
|
57
|
+
|
|
58
|
+
### C4 Model: Context Diagram
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
[Diagram showing system in context with external systems and users]
|
|
62
|
+
|
|
63
|
+
+------------------+
|
|
64
|
+
| |
|
|
65
|
+
| External User |
|
|
66
|
+
| |
|
|
67
|
+
+--------+---------+
|
|
68
|
+
|
|
|
69
|
+
| HTTPS
|
|
70
|
+
v
|
|
71
|
+
+------------------+ +------------------+
|
|
72
|
+
| | | |
|
|
73
|
+
| {{SYSTEM}} +---->+ External API |
|
|
74
|
+
| | | |
|
|
75
|
+
+--------+---------+ +------------------+
|
|
76
|
+
|
|
|
77
|
+
| SQL
|
|
78
|
+
v
|
|
79
|
+
+------------------+
|
|
80
|
+
| |
|
|
81
|
+
| Database |
|
|
82
|
+
| |
|
|
83
|
+
+------------------+
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**External Dependencies**:
|
|
87
|
+
- [External System 1]: [Purpose]
|
|
88
|
+
- [External System 2]: [Purpose]
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
### C4 Model: Container Diagram
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
[Diagram showing major containers/deployable units]
|
|
96
|
+
|
|
97
|
+
+--------------------------------------+
|
|
98
|
+
| {{SYSTEM}} |
|
|
99
|
+
| |
|
|
100
|
+
| +-------------+ +-------------+ |
|
|
101
|
+
| | | | | |
|
|
102
|
+
| | Web App +-->+ API Server | |
|
|
103
|
+
| | (Next.js) | | (Node.js) | |
|
|
104
|
+
| | | | | |
|
|
105
|
+
| +-------------+ +------+------+ |
|
|
106
|
+
| | |
|
|
107
|
+
+---------------------------+----------+
|
|
108
|
+
|
|
|
109
|
+
| SQL
|
|
110
|
+
v
|
|
111
|
+
+--------+--------+
|
|
112
|
+
| |
|
|
113
|
+
| PostgreSQL |
|
|
114
|
+
| |
|
|
115
|
+
+-----------------+
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Containers**:
|
|
119
|
+
1. **Web Application**: [Technology, purpose]
|
|
120
|
+
2. **API Server**: [Technology, purpose]
|
|
121
|
+
3. **Database**: [Technology, purpose]
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
### C4 Model: Component Diagram
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
[Diagram showing internal components of a container]
|
|
129
|
+
|
|
130
|
+
+-------------------------------------------+
|
|
131
|
+
| API Server Container |
|
|
132
|
+
| |
|
|
133
|
+
| +---------------+ +----------------+ |
|
|
134
|
+
| | | | | |
|
|
135
|
+
| | Auth | | {{COMPONENT}} | |
|
|
136
|
+
| | Controller +-->+ Service | |
|
|
137
|
+
| | | | | |
|
|
138
|
+
| +-------+-------+ +-------+--------+ |
|
|
139
|
+
| | | |
|
|
140
|
+
| v v |
|
|
141
|
+
| +-------+-------------------+--------+ |
|
|
142
|
+
| | | |
|
|
143
|
+
| | Database Repository Layer | |
|
|
144
|
+
| | | |
|
|
145
|
+
| +------------------------------------+ |
|
|
146
|
+
| |
|
|
147
|
+
+-------------------------------------------+
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Components**:
|
|
151
|
+
1. **{{COMPONENT}} Controller**: REST API endpoints
|
|
152
|
+
2. **{{COMPONENT}} Service**: Business logic
|
|
153
|
+
3. **{{COMPONENT}} Repository**: Data access
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Requirements Mapping
|
|
158
|
+
|
|
159
|
+
### Architecture → Requirements Matrix
|
|
160
|
+
|
|
161
|
+
| Component | Requirements Implemented | Design Rationale |
|
|
162
|
+
|-----------|-------------------------|------------------|
|
|
163
|
+
| {{COMPONENT}} Service | REQ-{{COMPONENT}}-001, REQ-{{COMPONENT}}-002 | Business logic encapsulation |
|
|
164
|
+
| {{COMPONENT}} Controller | REQ-{{COMPONENT}}-003 | API exposure |
|
|
165
|
+
| Database Schema | REQ-{{COMPONENT}}-004 | Data persistence |
|
|
166
|
+
| Authentication Middleware | REQ-SEC-001 | Security enforcement |
|
|
167
|
+
| Caching Layer | REQ-PERF-001 | Performance optimization |
|
|
168
|
+
|
|
169
|
+
**Coverage**:
|
|
170
|
+
- ✅ All functional requirements mapped
|
|
171
|
+
- ✅ All non-functional requirements addressed
|
|
172
|
+
- ✅ 100% requirements coverage
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## API Design
|
|
177
|
+
|
|
178
|
+
### RESTful API Endpoints
|
|
179
|
+
|
|
180
|
+
#### POST /api/{{resource}}
|
|
181
|
+
|
|
182
|
+
**Purpose**: [Create new resource]
|
|
183
|
+
|
|
184
|
+
**Maps to Requirements**: REQ-{{COMPONENT}}-001
|
|
185
|
+
|
|
186
|
+
**Request**:
|
|
187
|
+
```http
|
|
188
|
+
POST /api/{{resource}}
|
|
189
|
+
Content-Type: application/json
|
|
190
|
+
Authorization: Bearer {token}
|
|
191
|
+
|
|
192
|
+
{
|
|
193
|
+
"field1": "value1",
|
|
194
|
+
"field2": "value2"
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Request Schema**:
|
|
199
|
+
```typescript
|
|
200
|
+
interface CreateResourceRequest {
|
|
201
|
+
field1: string; // Required, max 255 chars
|
|
202
|
+
field2: number; // Required, positive integer
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**Response (Success)**:
|
|
207
|
+
```http
|
|
208
|
+
HTTP/1.1 201 Created
|
|
209
|
+
Content-Type: application/json
|
|
210
|
+
|
|
211
|
+
{
|
|
212
|
+
"id": "uuid",
|
|
213
|
+
"field1": "value1",
|
|
214
|
+
"field2": "value2",
|
|
215
|
+
"createdAt": "2025-11-16T10:00:00Z"
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**Response (Error)**:
|
|
220
|
+
```http
|
|
221
|
+
HTTP/1.1 400 Bad Request
|
|
222
|
+
Content-Type: application/json
|
|
223
|
+
|
|
224
|
+
{
|
|
225
|
+
"error": "Validation failed",
|
|
226
|
+
"details": [
|
|
227
|
+
{
|
|
228
|
+
"field": "field1",
|
|
229
|
+
"message": "Field1 is required"
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Status Codes**:
|
|
236
|
+
- 201: Resource created successfully
|
|
237
|
+
- 400: Invalid request (validation failed)
|
|
238
|
+
- 401: Unauthorized (missing/invalid token)
|
|
239
|
+
- 409: Conflict (resource already exists)
|
|
240
|
+
- 500: Internal server error
|
|
241
|
+
|
|
242
|
+
**Acceptance Criteria** (from REQ-{{COMPONENT}}-001):
|
|
243
|
+
- ✅ Validates request schema
|
|
244
|
+
- ✅ Returns 201 on success
|
|
245
|
+
- ✅ Returns resource ID
|
|
246
|
+
- ✅ Persists to database
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
#### GET /api/{{resource}}/:id
|
|
251
|
+
|
|
252
|
+
**Purpose**: [Retrieve resource by ID]
|
|
253
|
+
|
|
254
|
+
**Maps to Requirements**: REQ-{{COMPONENT}}-002
|
|
255
|
+
|
|
256
|
+
**Request**:
|
|
257
|
+
```http
|
|
258
|
+
GET /api/{{resource}}/550e8400-e29b-41d4-a716-446655440000
|
|
259
|
+
Authorization: Bearer {token}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**Response (Success)**:
|
|
263
|
+
```http
|
|
264
|
+
HTTP/1.1 200 OK
|
|
265
|
+
Content-Type: application/json
|
|
266
|
+
|
|
267
|
+
{
|
|
268
|
+
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
269
|
+
"field1": "value1",
|
|
270
|
+
"field2": "value2",
|
|
271
|
+
"createdAt": "2025-11-16T10:00:00Z",
|
|
272
|
+
"updatedAt": "2025-11-16T10:00:00Z"
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**Response (Not Found)**:
|
|
277
|
+
```http
|
|
278
|
+
HTTP/1.1 404 Not Found
|
|
279
|
+
Content-Type: application/json
|
|
280
|
+
|
|
281
|
+
{
|
|
282
|
+
"error": "Resource not found",
|
|
283
|
+
"id": "550e8400-e29b-41d4-a716-446655440000"
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**Status Codes**:
|
|
288
|
+
- 200: Resource found
|
|
289
|
+
- 401: Unauthorized
|
|
290
|
+
- 404: Resource not found
|
|
291
|
+
- 500: Internal server error
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
### OpenAPI Specification
|
|
296
|
+
|
|
297
|
+
See [openapi.yaml](./openapi.yaml) for complete API specification.
|
|
298
|
+
|
|
299
|
+
**Generation Command**:
|
|
300
|
+
```bash
|
|
301
|
+
# Generate OpenAPI spec
|
|
302
|
+
@api-designer generate openapi for {{FEATURE_NAME}}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Database Design
|
|
308
|
+
|
|
309
|
+
### Entity-Relationship Diagram
|
|
310
|
+
|
|
311
|
+
```
|
|
312
|
+
+-------------------+ +-------------------+
|
|
313
|
+
| users | | {{resource}} |
|
|
314
|
+
+-------------------+ +-------------------+
|
|
315
|
+
| id (PK) | | id (PK) |
|
|
316
|
+
| email | | user_id (FK) |
|
|
317
|
+
| password_hash | | field1 |
|
|
318
|
+
| created_at | | field2 |
|
|
319
|
+
| updated_at | | created_at |
|
|
320
|
+
+-------------------+ | updated_at |
|
|
321
|
+
| +-------------------+
|
|
322
|
+
| |
|
|
323
|
+
+------------------------------+
|
|
324
|
+
1:N
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
### Schema Definition
|
|
330
|
+
|
|
331
|
+
#### Table: {{resource}}
|
|
332
|
+
|
|
333
|
+
**Maps to Requirements**: REQ-{{COMPONENT}}-004
|
|
334
|
+
|
|
335
|
+
**Columns**:
|
|
336
|
+
|
|
337
|
+
| Column | Type | Constraints | Description |
|
|
338
|
+
|--------|------|-------------|-------------|
|
|
339
|
+
| id | UUID | PRIMARY KEY | Unique identifier |
|
|
340
|
+
| user_id | UUID | FOREIGN KEY (users.id), NOT NULL | Owner reference |
|
|
341
|
+
| field1 | VARCHAR(255) | NOT NULL | [Description] |
|
|
342
|
+
| field2 | INTEGER | NOT NULL, CHECK (field2 > 0) | [Description] |
|
|
343
|
+
| created_at | TIMESTAMP | NOT NULL, DEFAULT NOW() | Creation timestamp |
|
|
344
|
+
| updated_at | TIMESTAMP | NOT NULL, DEFAULT NOW() | Update timestamp |
|
|
345
|
+
|
|
346
|
+
**Indexes**:
|
|
347
|
+
- PRIMARY KEY: `id`
|
|
348
|
+
- INDEX: `user_id` (for lookups by user)
|
|
349
|
+
- INDEX: `created_at` (for sorting)
|
|
350
|
+
- UNIQUE: `user_id, field1` (business constraint)
|
|
351
|
+
|
|
352
|
+
**DDL**:
|
|
353
|
+
```sql
|
|
354
|
+
CREATE TABLE {{resource}} (
|
|
355
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
356
|
+
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
357
|
+
field1 VARCHAR(255) NOT NULL,
|
|
358
|
+
field2 INTEGER NOT NULL CHECK (field2 > 0),
|
|
359
|
+
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
|
360
|
+
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
CREATE INDEX idx_{{resource}}_user_id ON {{resource}}(user_id);
|
|
364
|
+
CREATE INDEX idx_{{resource}}_created_at ON {{resource}}(created_at);
|
|
365
|
+
CREATE UNIQUE INDEX idx_{{resource}}_user_field1 ON {{resource}}(user_id, field1);
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
### Migration Strategy
|
|
371
|
+
|
|
372
|
+
**Maps to Requirements**: REQ-MAINT-001
|
|
373
|
+
|
|
374
|
+
**Initial Migration** (Greenfield):
|
|
375
|
+
```sql
|
|
376
|
+
-- migrations/001_create_{{resource}}_table.sql
|
|
377
|
+
[DDL from above]
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
**Migration Tools**:
|
|
381
|
+
- [e.g., Prisma Migrate, TypeORM migrations, Alembic]
|
|
382
|
+
|
|
383
|
+
**Rollback Strategy**:
|
|
384
|
+
```sql
|
|
385
|
+
-- migrations/001_create_{{resource}}_table.down.sql
|
|
386
|
+
DROP TABLE {{resource}};
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
## Component Design
|
|
392
|
+
|
|
393
|
+
### {{COMPONENT}} Service
|
|
394
|
+
|
|
395
|
+
**Maps to Requirements**: REQ-{{COMPONENT}}-001, REQ-{{COMPONENT}}-002
|
|
396
|
+
|
|
397
|
+
**Responsibilities**:
|
|
398
|
+
- Business logic for {{resource}} operations
|
|
399
|
+
- Validation
|
|
400
|
+
- Error handling
|
|
401
|
+
|
|
402
|
+
**Interface**:
|
|
403
|
+
```typescript
|
|
404
|
+
interface {{COMPONENT}}Service {
|
|
405
|
+
create(data: CreateResourceDTO): Promise<Resource>;
|
|
406
|
+
findById(id: string): Promise<Resource | null>;
|
|
407
|
+
update(id: string, data: UpdateResourceDTO): Promise<Resource>;
|
|
408
|
+
delete(id: string): Promise<void>;
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
**Implementation**:
|
|
413
|
+
```typescript
|
|
414
|
+
// src/services/{{component}}.service.ts
|
|
415
|
+
|
|
416
|
+
export class {{COMPONENT}}Service implements {{COMPONENT}}Service {
|
|
417
|
+
constructor(private repository: {{COMPONENT}}Repository) {}
|
|
418
|
+
|
|
419
|
+
async create(data: CreateResourceDTO): Promise<Resource> {
|
|
420
|
+
// REQ-{{COMPONENT}}-001: Validate input
|
|
421
|
+
this.validateCreateInput(data);
|
|
422
|
+
|
|
423
|
+
// REQ-{{COMPONENT}}-001: Check for duplicates
|
|
424
|
+
const existing = await this.repository.findByUserAndField1(
|
|
425
|
+
data.userId,
|
|
426
|
+
data.field1
|
|
427
|
+
);
|
|
428
|
+
if (existing) {
|
|
429
|
+
throw new ConflictError('Resource already exists');
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// REQ-{{COMPONENT}}-001: Create resource
|
|
433
|
+
return this.repository.create(data);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Additional methods...
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
---
|
|
441
|
+
|
|
442
|
+
### {{COMPONENT}} Repository
|
|
443
|
+
|
|
444
|
+
**Maps to Requirements**: REQ-{{COMPONENT}}-004
|
|
445
|
+
|
|
446
|
+
**Responsibilities**:
|
|
447
|
+
- Data access layer
|
|
448
|
+
- Database queries
|
|
449
|
+
- Transaction management
|
|
450
|
+
|
|
451
|
+
**Interface**:
|
|
452
|
+
```typescript
|
|
453
|
+
interface {{COMPONENT}}Repository {
|
|
454
|
+
create(data: CreateResourceDTO): Promise<Resource>;
|
|
455
|
+
findById(id: string): Promise<Resource | null>;
|
|
456
|
+
findByUserAndField1(userId: string, field1: string): Promise<Resource | null>;
|
|
457
|
+
update(id: string, data: UpdateResourceDTO): Promise<Resource>;
|
|
458
|
+
delete(id: string): Promise<void>;
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
## Integration Points
|
|
465
|
+
|
|
466
|
+
### External API Integration
|
|
467
|
+
|
|
468
|
+
**Service**: [External API Name]
|
|
469
|
+
**Purpose**: [Integration purpose]
|
|
470
|
+
**Maps to Requirements**: REQ-{{COMPONENT}}-005
|
|
471
|
+
|
|
472
|
+
**Endpoint**: `https://api.external.com/v1/endpoint`
|
|
473
|
+
**Authentication**: API Key in header
|
|
474
|
+
**Rate Limit**: 1000 requests/hour
|
|
475
|
+
|
|
476
|
+
**Request**:
|
|
477
|
+
```http
|
|
478
|
+
GET /v1/endpoint
|
|
479
|
+
X-API-Key: {api_key}
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
**Error Handling**:
|
|
483
|
+
- Retry with exponential backoff (3 attempts)
|
|
484
|
+
- Circuit breaker after 5 consecutive failures
|
|
485
|
+
- Fallback to cached data if available
|
|
486
|
+
|
|
487
|
+
---
|
|
488
|
+
|
|
489
|
+
## Security Design
|
|
490
|
+
|
|
491
|
+
**Maps to Requirements**: REQ-SEC-001
|
|
492
|
+
|
|
493
|
+
### Authentication
|
|
494
|
+
|
|
495
|
+
- **Method**: JWT (JSON Web Tokens)
|
|
496
|
+
- **Token Expiry**: 24 hours
|
|
497
|
+
- **Refresh Token**: 7 days
|
|
498
|
+
- **Storage**: HTTP-only cookies
|
|
499
|
+
|
|
500
|
+
### Authorization
|
|
501
|
+
|
|
502
|
+
- **Method**: Role-Based Access Control (RBAC)
|
|
503
|
+
- **Roles**: admin, user, guest
|
|
504
|
+
- **Permissions**: read, write, delete
|
|
505
|
+
|
|
506
|
+
### Data Protection
|
|
507
|
+
|
|
508
|
+
- **Encryption at Rest**: AES-256
|
|
509
|
+
- **Encryption in Transit**: TLS 1.3
|
|
510
|
+
- **Password Hashing**: bcrypt (cost factor 12)
|
|
511
|
+
- **Sensitive Data**: PII encrypted in database
|
|
512
|
+
|
|
513
|
+
### Input Validation
|
|
514
|
+
|
|
515
|
+
- **XSS Prevention**: Output encoding
|
|
516
|
+
- **SQL Injection Prevention**: Parameterized queries (ORM)
|
|
517
|
+
- **CSRF Protection**: CSRF tokens
|
|
518
|
+
- **Rate Limiting**: 100 requests/minute per IP
|
|
519
|
+
|
|
520
|
+
---
|
|
521
|
+
|
|
522
|
+
## Performance Design
|
|
523
|
+
|
|
524
|
+
**Maps to Requirements**: REQ-PERF-001
|
|
525
|
+
|
|
526
|
+
### Caching Strategy
|
|
527
|
+
|
|
528
|
+
- **Layer**: Redis
|
|
529
|
+
- **TTL**: 5 minutes
|
|
530
|
+
- **Invalidation**: On write operations
|
|
531
|
+
|
|
532
|
+
### Database Optimization
|
|
533
|
+
|
|
534
|
+
- **Indexes**: See database schema section
|
|
535
|
+
- **Connection Pooling**: 20 connections max
|
|
536
|
+
- **Query Optimization**: N+1 prevention with eager loading
|
|
537
|
+
|
|
538
|
+
### API Performance
|
|
539
|
+
|
|
540
|
+
- **Response Time Target**: < 200ms (95th percentile)
|
|
541
|
+
- **Pagination**: Limit 100 items per page
|
|
542
|
+
- **Compression**: gzip for responses > 1KB
|
|
543
|
+
|
|
544
|
+
---
|
|
545
|
+
|
|
546
|
+
## Deployment Architecture
|
|
547
|
+
|
|
548
|
+
**Maps to Requirements**: REQ-AVAIL-001
|
|
549
|
+
|
|
550
|
+
### Infrastructure
|
|
551
|
+
|
|
552
|
+
```
|
|
553
|
+
[Load Balancer] --> [App Server 1]
|
|
554
|
+
--> [App Server 2]
|
|
555
|
+
--> [App Server 3]
|
|
556
|
+
|
|
|
557
|
+
v
|
|
558
|
+
[Database Primary]
|
|
559
|
+
|
|
|
560
|
+
v
|
|
561
|
+
[Database Replica]
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
### Containers
|
|
565
|
+
|
|
566
|
+
**Docker Image**: `{{org}}/{{project}}:{{version}}`
|
|
567
|
+
|
|
568
|
+
**Dockerfile**:
|
|
569
|
+
```dockerfile
|
|
570
|
+
FROM node:20-alpine
|
|
571
|
+
WORKDIR /app
|
|
572
|
+
COPY package*.json ./
|
|
573
|
+
RUN npm ci --production
|
|
574
|
+
COPY . .
|
|
575
|
+
EXPOSE 3000
|
|
576
|
+
CMD ["npm", "start"]
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### Environment Variables
|
|
580
|
+
|
|
581
|
+
| Variable | Description | Example |
|
|
582
|
+
|----------|-------------|---------|
|
|
583
|
+
| DATABASE_URL | PostgreSQL connection string | postgresql://user:pass@host:5432/db |
|
|
584
|
+
| REDIS_URL | Redis connection string | redis://host:6379 |
|
|
585
|
+
| JWT_SECRET | JWT signing secret | [secret] |
|
|
586
|
+
| API_KEY | External API key | [key] |
|
|
587
|
+
|
|
588
|
+
---
|
|
589
|
+
|
|
590
|
+
## Monitoring and Observability
|
|
591
|
+
|
|
592
|
+
**Maps to Requirements**: REQ-AVAIL-001
|
|
593
|
+
|
|
594
|
+
### Metrics
|
|
595
|
+
|
|
596
|
+
- **Response Time**: 95th/99th percentile
|
|
597
|
+
- **Error Rate**: 4xx/5xx responses
|
|
598
|
+
- **Throughput**: Requests per second
|
|
599
|
+
- **Database Query Time**: Slow query log
|
|
600
|
+
|
|
601
|
+
### Logging
|
|
602
|
+
|
|
603
|
+
- **Format**: JSON
|
|
604
|
+
- **Level**: INFO (production), DEBUG (development)
|
|
605
|
+
- **Fields**: timestamp, level, message, context, trace_id
|
|
606
|
+
|
|
607
|
+
### Alerting
|
|
608
|
+
|
|
609
|
+
- **Response Time**: Alert if 95th percentile > 500ms
|
|
610
|
+
- **Error Rate**: Alert if error rate > 1%
|
|
611
|
+
- **Database**: Alert if connection pool exhausted
|
|
612
|
+
|
|
613
|
+
---
|
|
614
|
+
|
|
615
|
+
## Constitutional Compliance
|
|
616
|
+
|
|
617
|
+
This design complies with:
|
|
618
|
+
|
|
619
|
+
### Article I: Library-First Principle
|
|
620
|
+
|
|
621
|
+
- ✅ {{COMPONENT}} implemented as library: `lib/{{component}}/`
|
|
622
|
+
- ✅ Independent test suite: `lib/{{component}}/tests/`
|
|
623
|
+
- ✅ CLI interface: `lib/{{component}}/cli.ts`
|
|
624
|
+
|
|
625
|
+
### Article II: CLI Interface Mandate
|
|
626
|
+
|
|
627
|
+
- ✅ CLI commands:
|
|
628
|
+
- `{{component}} create --field1=value --field2=value`
|
|
629
|
+
- `{{component}} get --id=uuid`
|
|
630
|
+
- `{{component}} list --user-id=uuid`
|
|
631
|
+
|
|
632
|
+
### Article VI: Project Memory
|
|
633
|
+
|
|
634
|
+
- ✅ Architecture aligns with `steering/structure.md`
|
|
635
|
+
- ✅ Technology stack matches `steering/tech.md`
|
|
636
|
+
- ✅ Product context from `steering/product.md`
|
|
637
|
+
|
|
638
|
+
### Article VII: Simplicity Gate
|
|
639
|
+
|
|
640
|
+
- ✅ Project count: [N] (≤ 3 or Phase -1 Gate approved)
|
|
641
|
+
|
|
642
|
+
### Article VIII: Anti-Abstraction Gate
|
|
643
|
+
|
|
644
|
+
- ✅ Framework APIs used directly (no custom wrappers)
|
|
645
|
+
- OR
|
|
646
|
+
- ⚠️ Custom abstraction requires Phase -1 Gate approval: [justification]
|
|
647
|
+
|
|
648
|
+
---
|
|
649
|
+
|
|
650
|
+
## Architecture Decision Records (ADR)
|
|
651
|
+
|
|
652
|
+
### ADR-001: Use PostgreSQL for Database
|
|
653
|
+
|
|
654
|
+
**Status**: Accepted
|
|
655
|
+
**Date**: {{DATE}}
|
|
656
|
+
|
|
657
|
+
**Context**:
|
|
658
|
+
We need a database for storing {{resource}} data with ACID guarantees.
|
|
659
|
+
|
|
660
|
+
**Decision**:
|
|
661
|
+
Use PostgreSQL 15+ as the primary database.
|
|
662
|
+
|
|
663
|
+
**Consequences**:
|
|
664
|
+
- ✅ ACID transactions
|
|
665
|
+
- ✅ Rich data types (JSONB, UUID)
|
|
666
|
+
- ✅ Strong ecosystem
|
|
667
|
+
- ❌ Requires relational schema design
|
|
668
|
+
|
|
669
|
+
**Alternatives Considered**:
|
|
670
|
+
- MongoDB: Rejected (ACID guarantees less strict)
|
|
671
|
+
- MySQL: Rejected (less feature-rich than PostgreSQL)
|
|
672
|
+
|
|
673
|
+
---
|
|
674
|
+
|
|
675
|
+
### ADR-002: Use JWT for Authentication
|
|
676
|
+
|
|
677
|
+
**Status**: Accepted
|
|
678
|
+
**Date**: {{DATE}}
|
|
679
|
+
|
|
680
|
+
**Context**:
|
|
681
|
+
We need stateless authentication for API.
|
|
682
|
+
|
|
683
|
+
**Decision**:
|
|
684
|
+
Use JWT tokens stored in HTTP-only cookies.
|
|
685
|
+
|
|
686
|
+
**Consequences**:
|
|
687
|
+
- ✅ Stateless authentication
|
|
688
|
+
- ✅ Scalable (no session storage)
|
|
689
|
+
- ❌ Token revocation requires blocklist
|
|
690
|
+
|
|
691
|
+
**Alternatives Considered**:
|
|
692
|
+
- Session-based auth: Rejected (requires session storage)
|
|
693
|
+
- OAuth 2.0: Deferred to future iteration
|
|
694
|
+
|
|
695
|
+
---
|
|
696
|
+
|
|
697
|
+
## Risk Assessment
|
|
698
|
+
|
|
699
|
+
| Risk | Probability | Impact | Mitigation |
|
|
700
|
+
|------|-------------|--------|------------|
|
|
701
|
+
| Database performance degradation | Medium | High | Implement caching, indexing, monitoring |
|
|
702
|
+
| External API unavailability | High | Medium | Circuit breaker, fallback to cache |
|
|
703
|
+
| Security vulnerability | Low | Critical | Regular security audits, OWASP Top 10 |
|
|
704
|
+
|
|
705
|
+
---
|
|
706
|
+
|
|
707
|
+
## Open Questions
|
|
708
|
+
|
|
709
|
+
- [ ] [Question 1]
|
|
710
|
+
- [ ] [Question 2]
|
|
711
|
+
|
|
712
|
+
---
|
|
713
|
+
|
|
714
|
+
## References
|
|
715
|
+
|
|
716
|
+
- [Requirements Specification](requirements.md)
|
|
717
|
+
- [Steering Context](../../steering/)
|
|
718
|
+
- [API Documentation](./api-docs.md)
|
|
719
|
+
- [Database Schema](./schema.sql)
|
|
720
|
+
|
|
721
|
+
---
|
|
722
|
+
|
|
723
|
+
## Validation
|
|
724
|
+
|
|
725
|
+
**Constitutional Validation**:
|
|
726
|
+
```bash
|
|
727
|
+
@constitution-enforcer validate design.md
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
**Requirements Coverage Validation**:
|
|
731
|
+
```bash
|
|
732
|
+
@traceability-auditor validate requirements.md design.md
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
---
|
|
736
|
+
|
|
737
|
+
**Powered by MUSUBI** - Specification Driven Development
|