Core Fundamentals of Spec-Driven Development
Understanding the core principles behind spec-driven development is essential for success.
The Specification-First Mindsetβ
Traditional development often follows this pattern:
Idea β Code β Documentation β Testing
Spec-driven development reverses this:
Specification β Plan β Tasks β Implementation β Validation
Key Principlesβ
1. Executable Specificationsβ
Specifications aren't just documentationβthey're executable blueprints that directly generate working code.
Example Specification:
## User Authentication System
### Requirements
- Users can register with email and password
- Passwords must be at least 8 characters
- Email verification required before login
- Session expires after 24 hours
### Constraints
- Use bcrypt for password hashing
- Store sessions in Redis
- Rate limit to 5 login attempts per minute
2. Intent Over Implementationβ
Focus on what you want, not how to build it.
β Bad (Too Specific):
Create a React component with useState hook that manages
a counter with increment and decrement buttons styled with Tailwind.
β Good (Intent-Focused):
Build a counter interface where users can increase or decrease
a numerical value. Display the current count prominently.
3. Iterative Refinementβ
Specs evolve through multiple refinement cycles:
- Initial Spec: High-level requirements
- Clarification: Use
/sp.clarifyto resolve ambiguities - Planning: Technical implementation details
- Task Breakdown: Actionable development steps
- Implementation: AI-assisted coding
4. Separation of Concernsβ
Keep different aspects of your project separate:
- Constitution: Project principles and standards
- Specifications: What to build
- Plans: How to build it
- Tasks: Step-by-step implementation
Specification Structureβ
A well-written specification includes:
Contextβ
- Background information
- Problem statement
- Target users
Requirementsβ
- Functional requirements
- Non-functional requirements (performance, security, etc.)
- Constraints and limitations
Success Criteriaβ
- How to validate the implementation
- Expected outcomes
- Test scenarios
Example: Complete Specificationβ
# Feature: Dark Mode Toggle
## Context
Users need to work at different times of day and prefer different
color schemes for comfort and accessibility.
## Requirements
### Functional
- Toggle button in navigation header
- Persist user preference across sessions
- Smooth transition between themes
- Apply to all pages instantly
### Non-Functional
- Transition animation under 200ms
- No layout shift during switch
- WCAG AA compliant color contrast
- Works with system preference API
## Success Criteria
- All text remains readable in both modes
- User preference persists after browser restart
- Respects system dark mode setting on first visit
- Automated tests verify all color combinations
Working with AIβ
When writing specs for AI implementation:
DO β β
- Be specific about requirements
- Provide examples
- Define success criteria
- Mention constraints
DON'T ββ
- Prescribe exact code structure
- Include implementation details
- Assume specific libraries
- Mix specification with code
Next Sectionβ
Learn about Best Practices for writing effective specifications.