PROMPT · coding
Spec-Driven Implementation
Write the spec before you write the code. This prompt enforces a spec → plan → build → verify loop that prevents scope creep, architectural drift, and "it works but not how we wanted" outcomes. The spec is the contract between what you want and what gets built. Every implementation decision traces back to a spec requirement.
specyfikacjaarchitekturaplanowanieimplementacjatdd
Download prompt file
YAML frontmatter + markdown body, ready to paste
Spec-Driven Implementation
The Pattern
Write the specification BEFORE writing any code. The spec is the contract — it defines what "done" looks like before implementation begins.
Spec → Plan → Build → Verify → Ship
Why Spec First
Without a spec, AI tends to:
- Solve the wrong problem confidently
- Add features you didn't ask for
- Make architectural decisions without asking
- Produce code that "works" but doesn't fit the system
A spec prevents all of these because every implementation decision can be checked against a written requirement.
Spec Template
## Feature Spec: {name}
### Goal
{One sentence: what problem does this solve?}
### Requirements
1. {Requirement — testable, specific}
2. {Requirement — testable, specific}
3. {Requirement — testable, specific}
### Non-Requirements (explicitly out of scope)
- {Thing we're NOT building}
- {Edge case we're NOT handling}
### Constraints
- Must work with: {existing system/API/pattern}
- Must not break: {existing functionality}
- Performance: {latency/throughput/size requirements}
- Security: {auth, validation, data handling requirements}
### Interface Contract
{How will other code interact with this? API shape, props, events, etc.}
### Acceptance Criteria
- [ ] {Criterion 1 — verifiable}
- [ ] {Criterion 2 — verifiable}
- [ ] {Criterion 3 — verifiable}
Process
Phase 1: Write the Spec (10 min)
- State the goal in one sentence
- List requirements (testable, specific)
- List non-requirements (what we're NOT doing)
- Define constraints (what existing code must be respected)
- Define the interface contract (how code will be called/used)
- Write acceptance criteria (how we'll verify it works)
Phase 2: Plan (5 min)
- Break the spec into implementation steps
- Identify files to create/modify
- Identify dependencies between steps
- Estimate: is this 30 minutes or 3 hours?
Phase 3: Build (most of the time)
- Implement step by step, following the plan
- After each step, check: does this satisfy a spec requirement?
- If you need to deviate from spec — STOP. Update spec first, then continue.
- Commit after each completed requirement
Phase 4: Verify (10 min)
- Walk through each acceptance criterion
- Run tests
- Check each spec requirement: is it implemented?
- Check non-requirements: did we accidentally scope-creep?
Operating Rules
- No code before spec approval — the spec must be reviewed before implementation starts
- Spec changes require explicit acknowledgment — if requirements change during build, update the spec and note the change
- Every PR references the spec — traceability from code to requirement
- Non-requirements are sacred — resist the temptation to add "just one more thing"
- Acceptance criteria are tests — write them as tests before writing implementation
When to Use
- Any feature that takes more than 30 minutes to implement
- Changes touching more than 3 files
- Any work involving API contracts or data model changes
- When multiple people (or sessions) will work on the same feature
- When the cost of "wrong" is high (auth, payments, data migration)
Anti-Patterns
- Spec so vague it could mean anything ("make it better")
- Spec so detailed it's already pseudocode (that's the plan, not the spec)
- Skipping non-requirements (scope creep enters through this door)
- Not updating the spec when requirements change mid-build
- Writing the spec after the code is done (that's documentation, not specification)