Spec-Driven Development
Overviewβ
Spec-Driven Development (SDD) or Spec-Driven Coding is a software development methodology led by Specification. Developers first write detailed requirements specifications, and then AI automatically generates code based on the specifications.
Core Concept: Clear specifications β Automatic implementation β Reduce communication costs
Core conceptsβ
1. What is Spec?β
Spec is a accurate, executable description of the software's functionality:
# User login function specifications
## Function description
Users can log in to the system using their email and password.
## Input
- email: string, consistent with email format
- password: string, 8-32 characters, including letters and numbers
## Output
- Success: Return user information and JWT token
- Failure: Return error message
## Validation rules
- Email must be registered
- Password must be correct
- The account will be locked for 30 minutes after 5 consecutive failures.
## API endpoint
POST /api/auth/login
2. Spec-Driven vs traditional developmentβ
| Development methods | Process | Advantages | Disadvantages |
|---|---|---|---|
| Traditional development | Requirements β Design β Coding | Flexible | High communication cost |
| Spec-Driven | Specification β AI generated code | Automation, traceability | Need to write specifications |
| Agile Development | User Stories β Iteration | Quick Response | Missing Documentation |
Spec-Driven Development processβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Spec-Driven Development Process β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β 1. Requirements gathering β
β β β
β βΌ β
β 2. Writing specification (Spec) βββββββββββββββββββ β
β β β Natural Language Specification β β
β ββββββββββββββββββββββΆβ API Specification β β
β β β Data model specification β β
β β β UI Specification β β
β β βββββββββββββββββββ β
β β β
β βΌ β
β 3. AI code generation βββββββββββββββββββ β
β β β Claude Code β β
β ββββββββββββββββββββββΆβ Cursor Agent β β
β β βββββββββββββββββββ β
β β β
β βΌ β
β 4. Code review β
β β β
β βΌ β
β 5. Test verification β
β β β
β βΌ β
β 6. Deployment and online β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Type of Specβ
1. Functional specificationsβ
Describe what the software should do:
## Function: User registration
### need
Users can register new accounts
### Input field
- username: 3-20 characters, alphanumeric and underlined
- email: valid email address
- Password: at least 8 characters, must contain uppercase and lowercase letters and numbers
### Business rules
- Username must be unique
- The email address must not be registered
- Automatically send verification email after registration
2. API specificationβ
Description API interface:
# OpenAPI specification
openapi: 3.0.0
info:
title: User Authentication API
version: 1.0.0
paths:
/auth/login:
post:
summary: User login
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
email:
type: string
format: email
password:
type: string
minLength: 8
responses:
'200':
description: Login successful
3. Data model specificationβ
Describe the data structure:
//TypeScript interface specification
interface User {
id: string;
username: string;
email: string;
createdAt: Date;
updatedAt: Date;
}
interface LoginRequest {
email: string;
password: string;
}
interface LoginResponse {
success: boolean;
token?: string;
user?: User;
error?: string;
}
4. UI specificationsβ
Describe interface requirements:
## Login page UI specification
### Layout
- Centered card layout
- Width 400px
### Components
- Email input box
- Password input box (with show/hide switch)
- "Remember me" checkbox
- "Forgot password" link
- Login button
### Style
- Main color: #3B82F6
- Rounded corners: 8px
- Shadow: 0 4px 6px rgba(0,0,0,0.1)
Tools that support Spec-Drivenβ
1. Cursor Composerβ
Cursor's multi-step task execution:
// user input
"Implement user authentication functions, including registration, login, and logout"
// Cursor automatic planning
1. Analyze requirements β generate specifications
2. Design data model
3. Implement API endpoints
4. Create UI components
5. Write test cases
2. Claude Code CLIβ
Define specifications via CLAUDE.md:
# Project specifications
## Coding specifications
- Use TypeScript strict mode
- Follow ESLint rules
- Use functional declarations for components
## API Specification
- RESTful style
- Unified error handling
- JWT authentication
## Test specifications
- Unit test coverage > 80%
- Use Vitest
Spec Writing Best Practicesβ
1. SMART principleβ
| Principles | Description | Examples |
|---|---|---|
| Specific | Specific and clear | "User can log in" rather than "implement authentication" |
| Measurable | Measurable | "Password 8-32 characters" rather than "Password complex enough" |
| Achievable | Achievable | Consider technical limitations |
| Relevant | Relevance | Alignment with business goals |
| Time-bound | Time-bound | "Complete within 2 seconds" |
2. Structural specificationβ
## Function Overview
Describe the function in one sentence
## User Stories
As [role], I want [feature] for [purpose]
## Acceptance criteria
- [ ] Scenario 1: Description
- [ ] Scenario 2: Description
## Technical specifications
### Data model
### API interface
### Business logic
## Non-functional requirements
### Performance: response time < 200ms
### Security: HTTPS + JWT
### Compatible: supports mainstream browsers
3. Use specification languageβ
- Use natural language but keep it structured
- Avoid ambiguous words ("as much as possible", "probably")
- Use specific numbers ("3 times" instead of "many")
- Contains boundary conditions ("null value", "overlong input")
Spec-Driven vs other development methodsβ
Spec-Driven vs Vibe Codingβ
| Dimensions | Spec-Driven | Vibe Coding |
|---|---|---|
| Planning | Detailed specifications | Feel free to play |
| Traceability | High | Low |
| Teamwork | Easy | Hard |
| AI Participation | Core | Auxiliary |
| Applicable scenarios | Large projects, teams | Prototypes, personal projects |
Spec-Driven vs Test-Driven Developmentβ
| Dimensions | Spec-Driven | TDD |
|---|---|---|
| Starting Point | Specifications | Testing |
| Sequence | Spec β Code β Test | Test β Code |
| AI Friendly | Yes | No |
| Combinable | Composable | Relatively independent |
Implementation suggestionsβ
1. Standard templateβ
# [function name] specification
## background
Why do you need this feature
## Target
What effect does this function want to achieve?
## Function description
Detailed function description
## Acceptance criteria
How to judge function completion
## Technical considerations
- Performance requirements
- Security considerations
- Compatibility requirements
## Dependencies
Other functions or modules that depend on
2. Tool configurationβ
// .claude/spec-template.json
{
"template": "# Functional Specification\n\n## Function Overview\n{summary}\n\n## Requirements\n{requirements}\n\n## Acceptance Criteria\n{acceptance}",
"requiredFields": ["summary", "requirements"],
"outputFormat": "markdown"
}
3. Version managementβ
specs/
βββ v1.0/
β βββ auth-spec.md
β βββ user-spec.md
β βββ api-spec.md
βββ v1.1/
β βββ auth-spec.md (updated)
β βββ payment-spec.md (new)
Reference resourcesβ
Related toolsβ
Related methodologiesβ
Document updated: December 2025