Loading...
Loading...
Use after brainstorming completes - writes validated designs to docs/design-plans/ with structured format and discrete implementation phases required for creating detailed implementation plans
npx skill4agent add ed3dai/ed3d-plugins writing-design-plans| Include | Exclude |
|---|---|
| Module and directory structure | Task-level breakdowns |
| Component names and responsibilities | Implementation code |
| File paths (from investigation) | Function bodies |
| Dependencies between components | Step-by-step instructions |
| "Done when" verification criteria | Test code |
interface TokenService {
generate(claims: TokenClaims): Promise<string>;
validate(token: string): Promise<TokenClaims | null>;
}
interface TokenClaims {
sub: string; // service identifier
aud: string[]; // allowed audiences
exp: number; // expiration timestamp
}async function generate(claims: TokenClaims): Promise<string> {
const payload = { ...claims, iat: Date.now() };
return jwt.sign(payload, config.secret, { algorithm: 'RS256' });
}docs/design-plans/YYYY-MM-DD-<topic>.mddocs/design-plans/2025-01-18-oauth2-svc-authn.mddocs/design-plans/2025-01-18-user-prof-redesign.mddocs/design-plans/design.mddocs/design-plans/new-feature.md# [Feature Name] Design
## Summary
<!-- TO BE GENERATED after body is written -->
## Definition of Done
[Already written - confirmed in Phase 3]
## Acceptance Criteria
<!-- TO BE GENERATED and validated before glossary -->
## Glossary
<!-- TO BE GENERATED after body is written -->## Architecture
[Approach selected in brainstorming Phase 2]
[Key components and how they interact]
[Data flow and system boundaries]
## Existing Patterns
[Document codebase patterns discovered by investigator that this design follows]
[If introducing new patterns, explain why and note divergence from existing code]
[If no existing patterns found, state that explicitly]
## Implementation Phases
Break implementation into discrete phases (<=8 recommended).
**REQUIRED: Wrap each phase in HTML comment markers:**
<!-- START_PHASE_1 -->
### Phase 1: [Name]
**Goal:** What this phase achieves
**Components:** What gets built/modified (exact paths from investigator)
**Dependencies:** What must exist first
**Done when:** How to verify this phase is complete (see Phase Verification below)
<!-- END_PHASE_1 -->
<!-- START_PHASE_2 -->
### Phase 2: [Name]
[Same structure]
<!-- END_PHASE_2 -->
...continue for each phase...
**Why markers:** These enable writing-implementation-plans to parse phases individually, reducing context usage and enabling granular task tracking across compaction boundaries.
## Additional Considerations
[Error handling, edge cases, future extensibility - only if relevant]
[Don't include hypothetical "nice to have" features]| Phase Type | Done When | Examples |
|---|---|---|
| Infrastructure/scaffolding | Operational success | Project installs, builds, runs, deploys |
| Functionality/behavior | Tests pass that verify the ACs this phase covers | Unit tests, integration tests, E2E tests |
oauth2-svc-authn.AC1.1oauth2-svc-authn.AC1.3oauth2-svc-authn.AC1.3<!-- START_PHASE_2 -->
### Phase 2: Core Services
**Goal:** Token generation and session management
**Components:**
- TokenService in `src/services/auth/` — generates and validates JWT tokens
- SessionManager in `src/services/auth/` — creates, validates, and invalidates sessions
- Types in `src/types/auth.ts` — TokenClaims, SessionData interfaces
**Dependencies:** Phase 1 (project setup)
**Done when:** Token generation/validation works, sessions can be created/invalidated, all tests pass
<!-- END_PHASE_2 -->Phase 2: Core Services
- Task 1: TokenPayload type and TokenConfig
- Task 2: TokenService implementation
- Task 3: TokenService tests
- Task 4: SessionManager implementation
- Task 5: SessionManager tests## Additional Considerations
**Implementation scoping:** This design has [N] phases total. The writing-plans skill limits implementation plans to 8 phases. Consider:
1. Implementing first 8 phases in initial plan
2. Creating second implementation plan for remaining phases
3. Simplifying design to fit within 8 phases<!-- START_PHASE_1 -->
### Phase 1: Project Setup
**Goal:** Initialize project structure and dependencies
**Components:**
- `package.json` with auth dependencies (jsonwebtoken, bcrypt)
- `tsconfig.json` with strict mode
- `src/index.ts` entry point
**Dependencies:** None (first phase)
**Done when:** `npm install` succeeds, `npm run build` succeeds
<!-- END_PHASE_1 --><!-- START_PHASE_2 -->
### Phase 2: Token Generation Service
**Goal:** JWT token generation and validation for service-to-service auth
**Components:**
- TokenService in `src/services/auth/` — generates signed JWTs, validates signatures and expiration
- TokenValidator in `src/services/auth/` — middleware-friendly validation that returns claims or rejects
**Dependencies:** Phase 1 (project setup)
**Done when:** Tokens can be generated, validated, and rejected when invalid/expired
<!-- END_PHASE_2 -->### Phase 1: Authentication
**Goal:** Add auth stuff
**Components:** Auth files
**Dependencies:** Database maybe### Phase 2: Token Service
**Components:**
- Create `src/types/token.ts` with TokenClaims interface
- Create `src/services/auth/token-service.ts` with generate() and validate()
- Create `tests/services/auth/token-service.test.ts`
- Step 1: Write failing test for generate()
- Step 2: Implement generate()
- Step 3: Write failing test for validate()
...## Architecture
Service-to-service authentication using OAuth2 client credentials flow.
Auth service (`src/services/auth/`) generates and validates JWT tokens. API middleware (`src/api/middleware/auth.ts`) validates tokens on incoming requests. Token store (`src/data/token-store.ts`) maintains revocation list in PostgreSQL.
Tokens expire after 1 hour. Refresh not needed for service accounts (can request new token).## Architecture
In this exciting new architecture, we'll be implementing a robust and scalable authentication system that leverages the power of OAuth2! The system will be designed with best practices in mind, ensuring security and performance at every level. We'll use industry-standard JWT tokens that provide excellent flexibility and are widely supported across the ecosystem. This will integrate seamlessly with our existing infrastructure and provide a solid foundation for future enhancements!## Existing Patterns
Investigation found existing authentication in `src/services/legacy-auth/`. This design follows the same service structure:
- Service classes in `src/services/<domain>/`
- Middleware in `src/api/middleware/`
- Data access in `src/data/`
Token storage follows pattern from `src/data/session-store.ts` (PostgreSQL with TTL).## Existing Patterns
Investigation found no existing authentication implementation. This design introduces new patterns:
- Service layer for business logic (`src/services/`)
- Middleware for request interception (`src/api/middleware/`)
These patterns align with functional core, imperative shell separation.## Existing Patterns
Investigation found legacy authentication in `src/auth/`. This design diverges:
- OLD: Monolithic `src/auth/auth.js` (600 lines, mixed concerns)
- NEW: Separate services (`token-service.ts`, `validator.ts`) following FCIS
Divergence justified by: Legacy code violates FCIS pattern, difficult to test, high coupling.## Additional Considerations
**Error handling:** Token validation failures return 401 with generic message (don't leak token details). Service-to-service communication failures retry 3x with exponential backoff before returning 503.**Edge cases:** Clock skew handled by 5-minute token validation window. Revoked tokens remain in database for 7 days for audit trail.**Future extensibility:** Token claims structure supports adding user metadata (currently unused). Enables future human user authentication without architecture change.{slug}.AC{N}.{M}{slug}YYYY-MM-DD-.md2025-01-18-oauth2-svc-authn.mdoauth2-svc-authn## Acceptance Criteria
### oauth2-svc-authn.AC1: Users can authenticate
- **oauth2-svc-authn.AC1.1 Success:** User with valid credentials receives auth token
- **oauth2-svc-authn.AC1.2 Success:** Token contains correct user ID and permissions
- **oauth2-svc-authn.AC1.3 Failure:** Invalid password returns 401 with generic error (no password hint)
- **oauth2-svc-authn.AC1.4 Failure:** Locked account returns 403 with lockout duration
- **oauth2-svc-authn.AC1.5 Edge:** Empty password field shows validation error before submission
### oauth2-svc-authn.AC2: Sessions persist across page refresh
- **oauth2-svc-authn.AC2.1 Success:** ...
- **oauth2-svc-authn.AC2.2 Failure:** ...
...
### oauth2-svc-authn.AC[N]: Cross-Cutting Behaviors
- **oauth2-svc-authn.AC[N].1:** Token expiration triggers re-authentication prompt (not silent failure)
- **oauth2-svc-authn.AC[N].2:** All API errors include correlation ID for debugging
- ...oauth2-svc-authn.AC2.1user-prof.AC2.1# [Feature Name] Design
## Summary
<!-- TO BE GENERATED after body is written -->
## Definition of Done
[Already written from Phase 3]
## Acceptance Criteria
[Validated in previous step]
## Glossary
<!-- TO BE GENERATED after body is written -->
## Architecture
[... body content ...]
## Existing Patterns
[... body content ...]
## Implementation Phases
[... body content ...]
## Additional Considerations
[... body content ...]<invoke name="Task">
<parameter name="subagent_type">ed3d-basic-agents:sonnet-general-purpose</parameter>
<parameter name="description">Generating Summary and Glossary for design document</parameter>
<parameter name="prompt">
Read the design document at [file path].
Generate two sections to replace the placeholders in the document:
1. **Summary**: Write 1-2 paragraphs summarizing what is being built and the
high-level approach. This should be understandable to someone unfamiliar
with the codebase. The Definition of Done section already exists — your
summary should complement it by explaining the "how" rather than restating
the "what."
2. **Glossary**: List domain terms from the application and third-party concepts
(libraries, frameworks, patterns) that a reviewer needs to understand this
document. Format as:
- **[Term]**: [Brief explanation]
Include only terms that appear in the document and would benefit from
explanation.
3. **Omitted Terms**: List terms you considered but skipped as too obvious or
generic. Only include borderline cases — terms that a less technical reviewer
might not know. Format as a simple comma-separated list.
Return all three sections. The first two are markdown ready to insert; the
third is for transparency about what was excluded.
</parameter>
</invoke>git add docs/design-plans/YYYY-MM-DD-<topic>.md
git commit -m "$(cat <<'EOF'
docs: add [feature name] design plan
Completed brainstorming session. Design includes:
- [Key architectural decision 1]
- [Key architectural decision 2]
- [N] implementation phases
EOF
)"docs/design-plans/YYYY-MM-DD-<topic>.md| Excuse | Reality |
|---|---|
| "I'll write the summary first since I know what I'm building" | Write body first. Summarize what you wrote, not what you planned. |
| "I can write Summary and Glossary myself, don't need subagent" | Subagent has fresh context and acts as forcing function. Use it. |
| "Glossary isn't needed, terms are obvious" | Obvious to you after brainstorming. Not to fresh reviewer. Include it. |
| "Design is simple, don't need phases" | Phases make implementation manageable. Always include. |
| "Phases are obvious, don't need detail" | writing-plans needs component descriptions. Provide them. |
| "Can have 10 phases if needed" | Hard limit is 8. Scope or split. |
| "I'll include the code so implementation is easier" | No. Implementation plans generate code fresh from codebase state. Design provides direction only. |
| "Breaking into tasks helps the reader" | Task breakdown is implementation planning's job. Design stays at component level. |
| "I'll just show how the function works" | Implementation code doesn't belong in design. Show contracts/interfaces if needed, not function bodies. |
| "Additional considerations should be comprehensive" | Only include if relevant. YAGNI applies. |
| "Should document all future possibilities" | Document current design only. No hypotheticals. |
| "Existing patterns section can be skipped" | Shows investigation happened. Always include. |
| "Can use generic file paths" | Exact paths from investigation. No handwaving. |
| "Tests can be a separate phase at the end" | No. Tests for functionality belong in the phase that creates that functionality. |
| "We'll add tests after the code works" | Phase isn't done until its tests pass. Tests are deliverables, not afterthoughts. |
| "Infrastructure needs unit tests too" | No. Infrastructure verified operationally. Don't over-engineer. |
| "Phase 3 tests will cover Phase 2 code" | Each phase tests its own deliverables. Later phases may extend tests, but don't defer. |
| "Phase markers are just noise" | Markers enable granular parsing. Implementation planning depends on them. Always include. |
| "Acceptance criteria are just the Definition of Done restated" | Criteria must be specific and verifiable. "System is secure" becomes "API rejects invalid tokens with 401." |
| "User approved DoD, don't need to validate criteria" | Criteria translate DoD into testable items. User must confirm this translation is correct. |
| "I'll skip criteria validation to save time" | Implementation planning depends on validated criteria. Skipping creates downstream confusion. |
| "Criteria are obvious from the phases" | Obvious to you. User must confirm they agree on what 'done' means before proceeding. |
Phase 3 (Definition of Done) completes
-> User confirms Definition of Done
-> File created with Title, Summary placeholder, DoD, AC placeholder, Glossary placeholder
-> DoD captured at full fidelity
Brainstorming (Phase 4) completes
-> Validated design exists in conversation
-> User approved incrementally
Writing Design Plans (this skill)
-> Append body: Architecture, Existing Patterns, Implementation Phases, Additional Considerations
-> Add exact paths from investigation
-> Create discrete phases (<=8)
-> Generate Acceptance Criteria inline (success + failure cases for each DoD item)
-> USER VALIDATES Acceptance Criteria
-> Replace AC placeholder with validated criteria
-> Dispatch subagent to generate Summary and Glossary
-> Replace Summary/Glossary placeholders with generated content
-> Commit to git
Writing Implementation Plans (next step)
-> Reads this design document
-> Uses phases as basis for detailed tasks
-> Uses Acceptance Criteria to generate test-requirements.md
-> Expects exact paths and structure