create-sdd-project 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +204 -0
- package/bin/cli.js +44 -0
- package/lib/config.js +106 -0
- package/lib/generator.js +313 -0
- package/lib/wizard.js +224 -0
- package/package.json +41 -0
- package/template/.claude/agents/backend-developer.md +60 -0
- package/template/.claude/agents/backend-planner.md +65 -0
- package/template/.claude/agents/code-review-specialist.md +65 -0
- package/template/.claude/agents/database-architect.md +68 -0
- package/template/.claude/agents/frontend-developer.md +68 -0
- package/template/.claude/agents/frontend-planner.md +65 -0
- package/template/.claude/agents/production-code-validator.md +102 -0
- package/template/.claude/agents/qa-engineer.md +70 -0
- package/template/.claude/agents/spec-creator.md +72 -0
- package/template/.claude/commands/.gitkeep +0 -0
- package/template/.claude/hooks/quick-scan.sh +111 -0
- package/template/.claude/settings.json +29 -0
- package/template/.claude/skills/bug-workflow/SKILL.md +108 -0
- package/template/.claude/skills/development-workflow/SKILL.md +194 -0
- package/template/.claude/skills/development-workflow/references/branching-strategy.md +59 -0
- package/template/.claude/skills/development-workflow/references/complexity-guide.md +89 -0
- package/template/.claude/skills/development-workflow/references/failure-handling.md +174 -0
- package/template/.claude/skills/development-workflow/references/pr-template.md +80 -0
- package/template/.claude/skills/development-workflow/references/sprint-init-template.md +82 -0
- package/template/.claude/skills/development-workflow/references/ticket-template.md +71 -0
- package/template/.claude/skills/development-workflow/references/workflow-example.md +87 -0
- package/template/.claude/skills/project-memory/SKILL.md +152 -0
- package/template/.claude/skills/project-memory/references/bugs_template.md +41 -0
- package/template/.claude/skills/project-memory/references/decisions_template.md +67 -0
- package/template/.claude/skills/project-memory/references/key_facts_template.md +81 -0
- package/template/.env.example +17 -0
- package/template/.gemini/agents/backend-developer.md +31 -0
- package/template/.gemini/agents/backend-planner.md +34 -0
- package/template/.gemini/agents/code-review-specialist.md +44 -0
- package/template/.gemini/agents/database-architect.md +35 -0
- package/template/.gemini/agents/frontend-developer.md +31 -0
- package/template/.gemini/agents/frontend-planner.md +34 -0
- package/template/.gemini/agents/production-code-validator.md +32 -0
- package/template/.gemini/agents/qa-engineer.md +23 -0
- package/template/.gemini/agents/spec-creator.md +24 -0
- package/template/.gemini/settings.json +5 -0
- package/template/.gemini/styles/default.md +19 -0
- package/template/AGENTS.md +67 -0
- package/template/CLAUDE.md +19 -0
- package/template/GEMINI.md +10 -0
- package/template/ai-specs/specs/backend-standards.mdc +214 -0
- package/template/ai-specs/specs/base-standards.mdc +157 -0
- package/template/ai-specs/specs/documentation-standards.mdc +68 -0
- package/template/ai-specs/specs/frontend-standards.mdc +226 -0
- package/template/docs/project_notes/bugs.md +18 -0
- package/template/docs/project_notes/decisions.md +18 -0
- package/template/docs/project_notes/key_facts.md +52 -0
- package/template/docs/project_notes/pending-improvements.md +50 -0
- package/template/docs/project_notes/sprint-0-tracker.md +66 -0
- package/template/docs/specs/api-spec.yaml +114 -0
- package/template/docs/specs/ui-components.md +77 -0
- package/template/docs/tickets/.gitkeep +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Frontend Developer
|
|
2
|
+
|
|
3
|
+
**Role**: Frontend TDD implementation (component architecture)
|
|
4
|
+
**When to Use**: Implement frontend tasks following the approved plan
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
|
|
8
|
+
Implement the task following the Implementation Plan in the ticket. Use strict TDD (Red-Green-Refactor). Follow logical order: Types > Services > Stores > Components > Pages.
|
|
9
|
+
|
|
10
|
+
## Before Implementing
|
|
11
|
+
|
|
12
|
+
1. Read ticket (including Spec and Implementation Plan)
|
|
13
|
+
2. Read `ai-specs/specs/frontend-standards.mdc`
|
|
14
|
+
3. Read `docs/specs/ui-components.md` for current UI component specs
|
|
15
|
+
4. Read `docs/specs/api-spec.yaml` for API endpoints to consume
|
|
16
|
+
5. Read `docs/project_notes/key_facts.md` and `bugs.md`
|
|
17
|
+
|
|
18
|
+
## Documentation Updates (MANDATORY — in real time)
|
|
19
|
+
|
|
20
|
+
- If adding/modifying a component → update `docs/specs/ui-components.md` BEFORE continuing
|
|
21
|
+
- New environment variables → `.env.example`
|
|
22
|
+
|
|
23
|
+
## Rules
|
|
24
|
+
|
|
25
|
+
- ALWAYS follow TDD — write tests before implementation
|
|
26
|
+
- ALWAYS follow the Implementation Plan
|
|
27
|
+
- ALWAYS use explicit types (no `any`)
|
|
28
|
+
- ALWAYS use `'use client'` for components with hooks
|
|
29
|
+
- ALWAYS handle loading and error states
|
|
30
|
+
- NEVER modify code outside the scope of the current ticket
|
|
31
|
+
- ALWAYS verify implementation matches the approved spec. If deviation needed, document in sprint tracker's Active Session and ask for approval
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Frontend Planner
|
|
2
|
+
|
|
3
|
+
**Role**: Frontend implementation planner (component architecture)
|
|
4
|
+
**When to Use**: Before implementing frontend tasks — create implementation plan
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
|
|
8
|
+
Generate a detailed Implementation Plan and write it into the ticket's `## Implementation Plan` section. The plan must be detailed enough for the frontend-developer to implement autonomously.
|
|
9
|
+
|
|
10
|
+
## Before Planning
|
|
11
|
+
|
|
12
|
+
1. Read `docs/project_notes/key_facts.md`
|
|
13
|
+
2. Read the ticket file (including `## Spec` section)
|
|
14
|
+
3. Read `docs/specs/ui-components.md` for current UI component specs
|
|
15
|
+
4. Read `docs/specs/api-spec.yaml` for API endpoints to consume
|
|
16
|
+
5. Explore existing components, services, stores, pages
|
|
17
|
+
6. Read `ai-specs/specs/frontend-standards.mdc`
|
|
18
|
+
|
|
19
|
+
**Reuse over recreate.** Only propose new components when existing ones don't fit.
|
|
20
|
+
|
|
21
|
+
## Output Sections
|
|
22
|
+
|
|
23
|
+
- Existing Code to Reuse
|
|
24
|
+
- Files to Create
|
|
25
|
+
- Files to Modify
|
|
26
|
+
- Implementation Order (Types > Services > Stores > Components > Pages > Tests)
|
|
27
|
+
- Testing Strategy
|
|
28
|
+
- Key Patterns
|
|
29
|
+
|
|
30
|
+
## Rules
|
|
31
|
+
|
|
32
|
+
- NEVER write implementation code — only the plan
|
|
33
|
+
- ALWAYS check existing code before proposing new files
|
|
34
|
+
- ALWAYS save the plan into the ticket
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Production Code Validator
|
|
2
|
+
|
|
3
|
+
**Role**: Pre-commit code quality scanner
|
|
4
|
+
**When to Use**: Before every commit — catches debug code, TODOs, secrets, hardcoded values, spec drift
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
|
|
8
|
+
Scan code systematically for issues that should never reach production:
|
|
9
|
+
|
|
10
|
+
1. **Placeholder Code**: "lorem ipsum", "foo", "bar", stub implementations
|
|
11
|
+
2. **TODO/FIXME**: Development notes, questions in comments
|
|
12
|
+
3. **Hardcoded Values**: API keys, localhost URLs, credentials, feature flags
|
|
13
|
+
4. **Debug Artifacts**: console.log, debugger statements, debug flags
|
|
14
|
+
5. **Security Red Flags**: Disabled SSL, CORS *, hardcoded credentials
|
|
15
|
+
6. **Error Handling**: Empty catch blocks, swallowed errors
|
|
16
|
+
7. **Code Quality**: Unused imports, missing types, overly long functions
|
|
17
|
+
8. **Spec Drift**: Routes not in api-spec.yaml, components not in ui-components.md, schema mismatches with Zod schemas in `shared/src/schemas/`
|
|
18
|
+
|
|
19
|
+
## Output Format
|
|
20
|
+
|
|
21
|
+
For each issue:
|
|
22
|
+
```
|
|
23
|
+
[SEVERITY: CRITICAL|HIGH|MEDIUM|LOW]
|
|
24
|
+
File: <filename>
|
|
25
|
+
Line: <line>
|
|
26
|
+
Issue: <description>
|
|
27
|
+
Recommendation: <how to fix>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Summary
|
|
31
|
+
|
|
32
|
+
Provide: issues by severity, production-readiness assessment (READY / NEEDS REVIEW / NOT READY), top 3 critical items.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# QA Engineer
|
|
2
|
+
|
|
3
|
+
**Role**: QA Automation Engineer
|
|
4
|
+
**When to Use**: After implementation and code review — hunt for edge cases
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
|
|
8
|
+
You assume the happy path works (checked by Developer). Hunt for edge cases, security flaws, and spec deviations. Verify implementation against `docs/specs/`.
|
|
9
|
+
|
|
10
|
+
## Workflow
|
|
11
|
+
|
|
12
|
+
1. Read ticket, specs (`api-spec.yaml`, `ui-components.md`), implementation code, and existing tests
|
|
13
|
+
2. Identify missing test cases and spec deviations
|
|
14
|
+
3. Run full test suite for regressions
|
|
15
|
+
4. Create new edge-case tests (e.g., `*.edge-cases.test.ts`)
|
|
16
|
+
5. Report findings (QA Verified or Issues Found)
|
|
17
|
+
|
|
18
|
+
## Rules
|
|
19
|
+
|
|
20
|
+
- NEVER modify implementation code — only write tests
|
|
21
|
+
- ALWAYS write tests to expose bugs before reporting them
|
|
22
|
+
- ALWAYS validate against spec definitions
|
|
23
|
+
- ALWAYS run the full test suite to check for regressions
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Spec Creator
|
|
2
|
+
|
|
3
|
+
**Role**: Systems Analyst and API Designer
|
|
4
|
+
**When to Use**: Before planning — draft or update specifications
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
|
|
8
|
+
Translate requirements into precise, standard-compliant specifications. Update global spec files AND the ticket's `## Spec` section.
|
|
9
|
+
|
|
10
|
+
## Workflow
|
|
11
|
+
|
|
12
|
+
1. Read the ticket or user request
|
|
13
|
+
2. Read existing specs in `docs/specs/` (api-spec.yaml, ui-components.md) and `shared/src/schemas/` (if exists)
|
|
14
|
+
3. Read relevant standards in `ai-specs/specs/`
|
|
15
|
+
4. Propose spec changes to global files
|
|
16
|
+
5. Write spec summary into ticket's `## Spec` section (Description, API Changes, Data Model Changes, UI Changes, Edge Cases)
|
|
17
|
+
6. Ask for user review before finalizing
|
|
18
|
+
|
|
19
|
+
## Rules
|
|
20
|
+
|
|
21
|
+
- NEVER write implementation code — only specifications
|
|
22
|
+
- ALWAYS follow existing patterns in spec files
|
|
23
|
+
- ALWAYS update BOTH global spec files AND ticket's `## Spec` section
|
|
24
|
+
- ALWAYS ask: "Does this spec look correct?"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Default Gemini Style
|
|
2
|
+
|
|
3
|
+
## Communication
|
|
4
|
+
|
|
5
|
+
- Be concise and direct
|
|
6
|
+
- Use English for all technical artifacts
|
|
7
|
+
- Explain reasoning behind recommendations
|
|
8
|
+
- Ask for user approval at checkpoints
|
|
9
|
+
|
|
10
|
+
## Code Style
|
|
11
|
+
|
|
12
|
+
- TypeScript with strict mode
|
|
13
|
+
- Explicit types (no `any`)
|
|
14
|
+
- Conventional commits for git messages
|
|
15
|
+
- TDD methodology (Red-Green-Refactor)
|
|
16
|
+
|
|
17
|
+
## Workflow
|
|
18
|
+
|
|
19
|
+
Follow the Spec-Driven Development workflow defined in `ai-specs/specs/base-standards.mdc`.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# AGENTS.md — Universal Project Instructions
|
|
2
|
+
|
|
3
|
+
> This file is read by all AI coding tools (Claude Code, Gemini, Cursor, Copilot, Windsurf, etc.).
|
|
4
|
+
> Tool-specific config goes in `CLAUDE.md` / `GEMINI.md`. Methodology goes in `ai-specs/specs/base-standards.mdc`.
|
|
5
|
+
|
|
6
|
+
## Project Structure
|
|
7
|
+
|
|
8
|
+
<!-- CONFIG: Adjust directories to match your monorepo layout -->
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
project/
|
|
12
|
+
├── backend/ ← Backend (has its own package.json)
|
|
13
|
+
├── frontend/ ← Frontend (has its own package.json)
|
|
14
|
+
├── shared/ ← Shared Zod schemas (optional — see base-standards.mdc § Shared Types)
|
|
15
|
+
└── docs/ ← Documentation (no package.json)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Critical**: NEVER install dependencies in the root directory.
|
|
19
|
+
|
|
20
|
+
| Action | Correct | Wrong |
|
|
21
|
+
|--------|---------|-------|
|
|
22
|
+
| Install backend dep | `cd backend && npm install pkg` | `npm install pkg` |
|
|
23
|
+
| Run backend tests | `cd backend && npm test` | `npm test` |
|
|
24
|
+
| Install frontend dep | `cd frontend && npm install pkg` | `npm install pkg` |
|
|
25
|
+
|
|
26
|
+
## Project Memory
|
|
27
|
+
|
|
28
|
+
Institutional knowledge lives in `docs/project_notes/`:
|
|
29
|
+
|
|
30
|
+
- **sprint-X-tracker.md** — Sprint progress, **Active Session** (current task, next actions, open questions), completion log
|
|
31
|
+
- **bugs.md** — Bug log with solutions and prevention notes
|
|
32
|
+
- **decisions.md** — Architectural Decision Records (ADRs)
|
|
33
|
+
- **key_facts.md** — Project configuration, ports, URLs, branching strategy
|
|
34
|
+
|
|
35
|
+
## Session Recovery
|
|
36
|
+
|
|
37
|
+
After context loss, new session, or context compaction — BEFORE continuing work:
|
|
38
|
+
|
|
39
|
+
1. **Read sprint tracker** (`docs/project_notes/sprint-X-tracker.md`) → **Active Session** section
|
|
40
|
+
2. If there is an active task → read the referenced ticket in `docs/tickets/`
|
|
41
|
+
3. Respect the configured autonomy level — do NOT skip checkpoints
|
|
42
|
+
|
|
43
|
+
## Anti-Patterns (Avoid)
|
|
44
|
+
|
|
45
|
+
- Installing dependencies in root directory
|
|
46
|
+
- Skipping approvals at configured autonomy level
|
|
47
|
+
- Using `any` type without justification
|
|
48
|
+
- Creating files when existing ones can be extended
|
|
49
|
+
- Adding features not explicitly requested
|
|
50
|
+
- Committing without updating ticket acceptance criteria
|
|
51
|
+
- Forgetting to update sprint tracker's Active Session after step changes
|
|
52
|
+
|
|
53
|
+
## Automated Hooks (Claude Code)
|
|
54
|
+
|
|
55
|
+
The project includes pre-configured hooks in `.claude/settings.json`:
|
|
56
|
+
|
|
57
|
+
- **Quick Scan** (`SubagentStop`): After `backend-developer` or `frontend-developer` finishes, a fast grep-based scan (~2s, no additional API calls) checks for `console.log`, `debugger`, `TODO/FIXME`, hardcoded secrets, and localhost references. Critical issues block; warnings are non-blocking (full review happens in Step 5).
|
|
58
|
+
- **Compaction Recovery** (`SessionStart → compact`): After context compaction, injects a reminder to read the sprint tracker Active Session for context recovery.
|
|
59
|
+
|
|
60
|
+
Personal notification hooks (macOS/Linux) are in `.claude/settings.local.json` — see that file for examples.
|
|
61
|
+
|
|
62
|
+
## Standards References
|
|
63
|
+
|
|
64
|
+
- [Base Standards](./ai-specs/specs/base-standards.mdc) — Constitution, methodology, workflow, agents
|
|
65
|
+
- [Backend Standards](./ai-specs/specs/backend-standards.mdc) — Backend patterns (DDD, Express, Prisma)
|
|
66
|
+
- [Frontend Standards](./ai-specs/specs/frontend-standards.mdc) — Frontend patterns (Next.js, Tailwind, Radix)
|
|
67
|
+
- [Documentation Standards](./ai-specs/specs/documentation-standards.mdc) — Doc guidelines
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!-- See AGENTS.md for universal project instructions (structure, commands, memory, anti-patterns). -->
|
|
2
|
+
<!-- See ai-specs/specs/base-standards.mdc for methodology (constitution, workflow, agents, git). -->
|
|
3
|
+
|
|
4
|
+
## Claude-Specific Configuration
|
|
5
|
+
|
|
6
|
+
<!-- CONFIG: Set your preferred autonomy level (1-4). See base-standards.mdc § Autonomy Levels for definitions. -->
|
|
7
|
+
**Autonomy Level: 2 (Trusted)**
|
|
8
|
+
|
|
9
|
+
<!-- CONFIG: Set branching strategy in docs/project_notes/key_facts.md (github-flow or gitflow) -->
|
|
10
|
+
|
|
11
|
+
## Session Recovery (Claude Code)
|
|
12
|
+
|
|
13
|
+
After context compaction or new session — BEFORE continuing work:
|
|
14
|
+
|
|
15
|
+
1. Read sprint tracker (`docs/project_notes/sprint-X-tracker.md`) → **Active Session**
|
|
16
|
+
2. If active task → read referenced ticket in `docs/tickets/`
|
|
17
|
+
3. Read the active skill file (`.claude/skills/*/SKILL.md`)
|
|
18
|
+
4. Do NOT proceed past any checkpoint without user confirmation (respect autonomy level)
|
|
19
|
+
5. If Active Session shows a pending checkpoint, ask before continuing
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<!-- See AGENTS.md for universal project instructions (structure, commands, memory, anti-patterns). -->
|
|
2
|
+
<!-- See ai-specs/specs/base-standards.mdc for methodology (constitution, workflow, agents, git). -->
|
|
3
|
+
<!-- Note: Gemini agent files (.gemini/agents/) are intentionally concise. Full methodology details live in ai-specs/specs/ and AGENTS.md. -->
|
|
4
|
+
|
|
5
|
+
## Gemini-Specific Configuration
|
|
6
|
+
|
|
7
|
+
<!-- CONFIG: Set your preferred autonomy level (1-4). See base-standards.mdc § Autonomy Levels for definitions. -->
|
|
8
|
+
**Autonomy Level: 2 (Trusted)**
|
|
9
|
+
|
|
10
|
+
<!-- CONFIG: Set branching strategy in docs/project_notes/key_facts.md (github-flow or gitflow) -->
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Backend development standards, best practices, and conventions. Covers DDD architecture, API design, testing, security, and deployment patterns.
|
|
3
|
+
globs: ["backend/src/**/*.ts", "backend/prisma/**/*.{prisma,ts}", "backend/jest.config.*", "backend/tsconfig.json", "backend/package.json"]
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<!-- CONFIG: This file defaults to Node.js/Express/Prisma/PostgreSQL. Adjust for your stack. -->
|
|
8
|
+
|
|
9
|
+
# Backend Standards
|
|
10
|
+
|
|
11
|
+
## Technology Stack
|
|
12
|
+
|
|
13
|
+
- **Runtime**: Node.js with TypeScript (strict mode)
|
|
14
|
+
- **Framework**: Express.js
|
|
15
|
+
- **ORM**: Prisma (PostgreSQL)
|
|
16
|
+
- **Validation**: Zod
|
|
17
|
+
- **Testing**: Jest (90% coverage threshold)
|
|
18
|
+
- **Logging**: Pino (structured JSON logs)
|
|
19
|
+
|
|
20
|
+
## Architecture — DDD Layered
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
backend/src/
|
|
24
|
+
├── domain/ # Business logic (pure, no dependencies)
|
|
25
|
+
│ ├── entities/ # Domain entities
|
|
26
|
+
│ ├── errors/ # Domain-specific errors
|
|
27
|
+
│ └── repositories/ # Repository interfaces
|
|
28
|
+
├── application/ # Use cases and orchestration
|
|
29
|
+
│ ├── services/ # Application services
|
|
30
|
+
│ └── validators/ # Input validation (Zod schemas)
|
|
31
|
+
├── infrastructure/ # External integrations
|
|
32
|
+
│ ├── repositories/ # Prisma repository implementations
|
|
33
|
+
│ ├── prismaClient.ts # Prisma client setup
|
|
34
|
+
│ └── logger.ts # Logging utilities
|
|
35
|
+
├── presentation/ # HTTP layer
|
|
36
|
+
│ ├── controllers/ # Request handlers
|
|
37
|
+
│ ├── routes/ # Express route definitions
|
|
38
|
+
│ └── middleware/ # Express middleware
|
|
39
|
+
├── index.ts # Application entry point
|
|
40
|
+
└── server.ts # Server setup
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Layer Rules
|
|
44
|
+
|
|
45
|
+
- **Domain**: No imports from other layers. Pure business logic.
|
|
46
|
+
- **Application**: Imports from Domain only. Orchestrates use cases.
|
|
47
|
+
- **Infrastructure**: Implements Domain interfaces. Prisma, external APIs.
|
|
48
|
+
- **Presentation**: Imports from Application only. HTTP concerns.
|
|
49
|
+
|
|
50
|
+
## Naming Conventions
|
|
51
|
+
|
|
52
|
+
- **Variables/Functions**: camelCase (`findById`, `candidateId`)
|
|
53
|
+
- **Classes/Interfaces**: PascalCase (`UserService`, `IUserRepository`)
|
|
54
|
+
- **Constants**: UPPER_SNAKE_CASE (`MAX_PAGE_SIZE`)
|
|
55
|
+
- **Files**: camelCase (`userService.ts`, `userController.ts`)
|
|
56
|
+
- **Error files**: PascalCase (`UserError.ts`, `AuthError.ts`)
|
|
57
|
+
|
|
58
|
+
## API Design
|
|
59
|
+
|
|
60
|
+
### REST Endpoints
|
|
61
|
+
```
|
|
62
|
+
GET /resource # List (with pagination)
|
|
63
|
+
GET /resource/:id # Get by ID
|
|
64
|
+
POST /resource # Create
|
|
65
|
+
PUT /resource/:id # Full update
|
|
66
|
+
PATCH /resource/:id # Partial update
|
|
67
|
+
DELETE /resource/:id # Delete
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Response Format
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"success": true,
|
|
74
|
+
"data": { ... },
|
|
75
|
+
"message": "Operation completed successfully"
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Error Response Format
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"success": false,
|
|
83
|
+
"error": {
|
|
84
|
+
"message": "Validation failed",
|
|
85
|
+
"code": "VALIDATION_ERROR",
|
|
86
|
+
"details": [...]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### HTTP Status Codes
|
|
92
|
+
- `200` Success
|
|
93
|
+
- `201` Created
|
|
94
|
+
- `400` Bad Request (validation errors)
|
|
95
|
+
- `401` Unauthorized
|
|
96
|
+
- `403` Forbidden
|
|
97
|
+
- `404` Not Found
|
|
98
|
+
- `409` Conflict
|
|
99
|
+
- `500` Internal Server Error
|
|
100
|
+
|
|
101
|
+
### Validation Endpoints Pattern
|
|
102
|
+
Return HTTP 200 with `valid: false` for business validation failures (not 400). Service returns structured result objects (never throws). Only input validation errors throw → 400.
|
|
103
|
+
|
|
104
|
+
## Error Handling
|
|
105
|
+
|
|
106
|
+
- Custom domain error classes extending `Error`
|
|
107
|
+
- Global error middleware for consistent responses
|
|
108
|
+
- Never swallow errors (empty catch blocks)
|
|
109
|
+
- Descriptive error messages in English
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
export class NotFoundError extends Error {
|
|
113
|
+
constructor(entity: string, id: string) {
|
|
114
|
+
super(`${entity} not found with ID: ${id}`);
|
|
115
|
+
this.name = 'NotFoundError';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Validation
|
|
121
|
+
|
|
122
|
+
- Validate all inputs at the application layer using Zod
|
|
123
|
+
- Validate before executing business logic
|
|
124
|
+
- Return descriptive validation errors
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { z } from 'zod';
|
|
128
|
+
|
|
129
|
+
const CreateUserSchema = z.object({
|
|
130
|
+
email: z.string().email(),
|
|
131
|
+
name: z.string().min(2).max(100),
|
|
132
|
+
role: z.enum(['USER', 'ADMIN']),
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Database Patterns
|
|
137
|
+
|
|
138
|
+
### Prisma Best Practices
|
|
139
|
+
- `schema.prisma` is the single source of truth for DB structure
|
|
140
|
+
- Use descriptive migration names: `npx prisma migrate dev --name add_user_role`
|
|
141
|
+
- Always use `include` when the frontend reads relation fields
|
|
142
|
+
- Convert Decimal fields with `Number()` before arithmetic
|
|
143
|
+
- Import enums from generated path (not the main client import)
|
|
144
|
+
- `@unique` already creates an index — no need for redundant `@@index`
|
|
145
|
+
|
|
146
|
+
### Repository Pattern
|
|
147
|
+
```typescript
|
|
148
|
+
// Domain layer — interface
|
|
149
|
+
export interface IUserRepository {
|
|
150
|
+
findById(id: string): Promise<User | null>;
|
|
151
|
+
save(user: User): Promise<User>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Infrastructure layer — implementation
|
|
155
|
+
export class PrismaUserRepository implements IUserRepository {
|
|
156
|
+
constructor(private prisma: PrismaClient) {}
|
|
157
|
+
|
|
158
|
+
async findById(id: string): Promise<User | null> {
|
|
159
|
+
return this.prisma.user.findUnique({ where: { id } });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Testing Standards
|
|
165
|
+
|
|
166
|
+
### Structure (AAA Pattern)
|
|
167
|
+
```typescript
|
|
168
|
+
describe('UserService - findById', () => {
|
|
169
|
+
beforeEach(() => jest.clearAllMocks());
|
|
170
|
+
|
|
171
|
+
it('should return user when found', async () => {
|
|
172
|
+
// Arrange
|
|
173
|
+
const mockUser = { id: '1', name: 'Test' };
|
|
174
|
+
mockRepo.findById.mockResolvedValue(mockUser);
|
|
175
|
+
|
|
176
|
+
// Act
|
|
177
|
+
const result = await service.findById('1');
|
|
178
|
+
|
|
179
|
+
// Assert
|
|
180
|
+
expect(result).toEqual(mockUser);
|
|
181
|
+
expect(mockRepo.findById).toHaveBeenCalledWith('1');
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Test Categories (all required)
|
|
187
|
+
1. **Happy Path**: Valid inputs → expected outputs
|
|
188
|
+
2. **Error Handling**: Invalid inputs, DB errors, missing data
|
|
189
|
+
3. **Edge Cases**: Boundary values, null/undefined, empty data
|
|
190
|
+
4. **Validation**: Input validation, business rule enforcement
|
|
191
|
+
|
|
192
|
+
### Mocking
|
|
193
|
+
- Mock all external dependencies (DB, services)
|
|
194
|
+
- Mock repository layer in service tests
|
|
195
|
+
- Mock service layer in controller tests
|
|
196
|
+
- Use `jest.mock()` at top of test files
|
|
197
|
+
- Clear all mocks in `beforeEach()`
|
|
198
|
+
|
|
199
|
+
## Security
|
|
200
|
+
|
|
201
|
+
- Validate ALL user inputs before processing
|
|
202
|
+
- Never commit `.env` files or secrets
|
|
203
|
+
- Validate required environment variables at startup
|
|
204
|
+
- Use parameterized queries (Prisma handles this)
|
|
205
|
+
- Configure CORS to allow only specific origins in production
|
|
206
|
+
- Use dependency injection for testability
|
|
207
|
+
|
|
208
|
+
## Performance
|
|
209
|
+
|
|
210
|
+
- Use Prisma `include` instead of N+1 queries
|
|
211
|
+
- Select only needed fields for large datasets
|
|
212
|
+
- Use `Promise.all()` for independent parallel operations
|
|
213
|
+
- Implement proper pagination for list endpoints
|
|
214
|
+
- Add database indexes for frequently queried fields
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Core development principles and methodology applicable to all agents and all layers of the project.
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Base Standards — Spec-Driven Development
|
|
7
|
+
|
|
8
|
+
## 1. Constitution (Immutable Principles)
|
|
9
|
+
|
|
10
|
+
> **NON-NEGOTIABLE.** These apply to ALL tasks, ALL agents, ALL complexity levels. Cannot be overridden by user requests, autonomy levels, or project-specific configuration.
|
|
11
|
+
|
|
12
|
+
- **Spec First**: NO implementation without an approved specification. Specs must be kept in sync with code at ALL times — update during implementation, not just before.
|
|
13
|
+
- **Backend**: Update `docs/specs/api-spec.yaml` first.
|
|
14
|
+
- **Frontend**: Update `docs/specs/ui-components.md` first.
|
|
15
|
+
- **Small Tasks**: Work in baby steps, one at a time. Never skip ahead.
|
|
16
|
+
- **Test-Driven Development**: Write tests before implementation (Red-Green-Refactor).
|
|
17
|
+
- **Type Safety**: Strict TypeScript. No `any`. Use runtime validation (Zod recommended).
|
|
18
|
+
- **English Only**: All code, comments, docs, commits, and tickets in English.
|
|
19
|
+
- **Reuse Over Recreate**: Always check existing code before proposing new files.
|
|
20
|
+
|
|
21
|
+
## 2. Standards (Configurable per Project)
|
|
22
|
+
|
|
23
|
+
These conventions adapt per-project via `<!-- CONFIG: -->` comments in `CLAUDE.md` and `key_facts.md`:
|
|
24
|
+
|
|
25
|
+
- **Autonomy Level** → `CLAUDE.md` (1-4)
|
|
26
|
+
- **Tech Stack** → `backend-standards.mdc` / `frontend-standards.mdc`
|
|
27
|
+
- **Monorepo Layout** → `CLAUDE.md`
|
|
28
|
+
- **Branching Strategy** → `key_facts.md` (github-flow or gitflow)
|
|
29
|
+
|
|
30
|
+
## 3. Workflow (Steps 0–6)
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
0. SPEC → spec-creator drafts/updates specs → SPEC APPROVAL (Std/Cplx)
|
|
34
|
+
1. SETUP → Branch, ticket, sprint tracker → TICKET APPROVAL (Std/Cplx)
|
|
35
|
+
2. PLAN → Planner agent creates implementation plan → PLAN APPROVAL (Std/Cplx)
|
|
36
|
+
3. IMPLEMENT → Developer agent, TDD, real-time spec sync
|
|
37
|
+
4. FINALIZE → Tests/lint/build, production-validator → COMMIT APPROVAL
|
|
38
|
+
5. REVIEW → PR, code-review, qa-engineer → MERGE APPROVAL
|
|
39
|
+
6. COMPLETE → Clean up, update tracker
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Step Flow by Complexity
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
Simple: 1 → 3 → 4 → 5 → 6
|
|
46
|
+
Standard: 0 → 1 → 2 → 3 → 4 → 5 (+QA) → 6
|
|
47
|
+
Complex: 0 → 1 (+ADR) → 2 → 3 → 4 → 5 (+QA) → 6
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Complexity Tiers
|
|
51
|
+
|
|
52
|
+
| Tier | Spec | Ticket | Plan | QA |
|
|
53
|
+
|------|:----:|:------:|:----:|:--:|
|
|
54
|
+
| Simple | Skip | Skip | Skip | Skip |
|
|
55
|
+
| Standard | Yes | Yes | Yes | Yes |
|
|
56
|
+
| Complex | Yes | Yes + ADR | Yes | Yes |
|
|
57
|
+
|
|
58
|
+
### Autonomy Levels
|
|
59
|
+
|
|
60
|
+
Quality gates (tests, lint, build, validators) **always run** regardless of level.
|
|
61
|
+
|
|
62
|
+
| Checkpoint | L1 Full Control | L2 Trusted | L3 Autopilot | L4 Full Auto |
|
|
63
|
+
|------------|:-:|:-:|:-:|:-:|
|
|
64
|
+
| Spec Approval | Required | Auto | Auto | Auto |
|
|
65
|
+
| Ticket Approval | Required | Auto | Auto | Auto |
|
|
66
|
+
| Plan Approval | Required | Required | Auto | Auto |
|
|
67
|
+
| Commit Approval | Required | Auto | Auto | Auto |
|
|
68
|
+
| Merge Approval | Required | Required | Required | Auto |
|
|
69
|
+
|
|
70
|
+
- **L1 Full Control**: First sprint or learning SDD — human approves every step.
|
|
71
|
+
- **L2 Trusted**: Comfortable with SDD — AI handles routine, human reviews plans and merges.
|
|
72
|
+
- **L3 Autopilot**: Battle-tested workflow — human only reviews PRs before merge.
|
|
73
|
+
- **L4 Full Auto**: Full automation — human reviews at sprint boundaries only.
|
|
74
|
+
|
|
75
|
+
**Auto** = proceed without asking; log in sprint tracker → "Auto-Approved Decisions" table.
|
|
76
|
+
|
|
77
|
+
## 4. Agent Roles
|
|
78
|
+
|
|
79
|
+
| Agent | Responsibility |
|
|
80
|
+
|-------|---------------|
|
|
81
|
+
| `spec-creator` | Draft/update specs before planning |
|
|
82
|
+
| `backend-planner` / `frontend-planner` | Implementation plan for tasks |
|
|
83
|
+
| `backend-developer` / `frontend-developer` | TDD implementation |
|
|
84
|
+
| `production-code-validator` | Pre-commit validation (debug code, TODOs, secrets, spec drift) |
|
|
85
|
+
| `code-review-specialist` | Pre-merge code review |
|
|
86
|
+
| `qa-engineer` | Edge cases, spec verification, regression (Std/Cplx) |
|
|
87
|
+
| `database-architect` | Schema design, migrations, query optimization (invoke manually) |
|
|
88
|
+
|
|
89
|
+
## 5. Shared Types Strategy
|
|
90
|
+
|
|
91
|
+
<!-- CONFIG: Remove this section if your project has no shared types -->
|
|
92
|
+
|
|
93
|
+
For projects with backend + frontend, use a shared workspace for Zod schemas:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
project/
|
|
97
|
+
├── shared/ ← @project/shared (npm workspace)
|
|
98
|
+
│ └── src/schemas/ ← Zod schemas = single source of truth for types
|
|
99
|
+
├── backend/ ← imports @project/shared
|
|
100
|
+
└── frontend/ ← imports @project/shared
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Rules:**
|
|
104
|
+
- Define data as Zod schemas → derive TypeScript types with `z.infer<typeof Schema>`
|
|
105
|
+
- NEVER write manual TypeScript interfaces for shared data — always derive from Zod
|
|
106
|
+
- Update `shared/` FIRST — both apps get types automatically via TS path aliases
|
|
107
|
+
- Use `.extend()` / `.partial()` / `.pick()` for variants (CreateSchema, UpdateSchema)
|
|
108
|
+
- Wire with npm workspaces (`"@project/shared": "file:../shared"`) + `tsconfig.json` paths
|
|
109
|
+
|
|
110
|
+
## 6. Pre-Commit Checklist
|
|
111
|
+
|
|
112
|
+
1. Specs updated (`docs/specs/` reflects changes)
|
|
113
|
+
2. Tests pass (`npm test`)
|
|
114
|
+
3. Lint passes (`npm run lint`)
|
|
115
|
+
4. Build succeeds (`npm run build`)
|
|
116
|
+
5. Ticket updated (acceptance criteria marked `[x]`)
|
|
117
|
+
|
|
118
|
+
## 7. Communication Style
|
|
119
|
+
|
|
120
|
+
All agents MUST follow: **Acknowledge** → **Execute** → **Explain** → **Gate** (ask authorization per autonomy level before committing, pushing, or switching tasks).
|
|
121
|
+
|
|
122
|
+
## 8. Project Memory Protocols
|
|
123
|
+
|
|
124
|
+
- Starting a session or after compaction → read sprint tracker's **Active Session** first
|
|
125
|
+
- Before architectural changes → check `decisions.md`
|
|
126
|
+
- When encountering bugs → search `bugs.md`
|
|
127
|
+
- When looking up config → check `key_facts.md`
|
|
128
|
+
- After every step change → update sprint tracker's Active Session
|
|
129
|
+
|
|
130
|
+
## 9. Git Conventions
|
|
131
|
+
|
|
132
|
+
**Commits:** `<type>(<scope>): <description>` — types: feat, fix, docs, style, refactor, test, chore
|
|
133
|
+
**Tags:** Semantic versioning `vX.Y.Z`
|
|
134
|
+
|
|
135
|
+
### Branching (configured in `key_facts.md`)
|
|
136
|
+
|
|
137
|
+
**Default: GitHub Flow** (recommended for MVPs)
|
|
138
|
+
|
|
139
|
+
| Branch | Base | Merges to |
|
|
140
|
+
|--------|------|-----------|
|
|
141
|
+
| `main` | — | — (always deployable) |
|
|
142
|
+
| `feature/sprint<N>-<task-id>-<desc>` | main | main (PR) |
|
|
143
|
+
| `bugfix/<area>-<desc>` | main | main (PR) |
|
|
144
|
+
| `hotfix/<desc>` | main | main (fast-track PR) |
|
|
145
|
+
|
|
146
|
+
**Scaled: GitFlow** (when project grows beyond MVP)
|
|
147
|
+
|
|
148
|
+
| Branch | Base | Merges to |
|
|
149
|
+
|--------|------|-----------|
|
|
150
|
+
| `main` | — | — (releases only) |
|
|
151
|
+
| `develop` | main | — (integration) |
|
|
152
|
+
| `feature/sprint<N>-<task-id>-<desc>` | develop | develop (PR) |
|
|
153
|
+
| `release/<version>` | develop | main + develop |
|
|
154
|
+
| `hotfix/<desc>` | main | main + develop |
|
|
155
|
+
|
|
156
|
+
**Merge:** Features/bugfixes → squash. Releases/hotfixes → merge commit.
|
|
157
|
+
**PRs:** Required for Std/Cplx tasks. Human review depends on autonomy level.
|