Skip to main content

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 methodsProcessAdvantagesDisadvantages
Traditional developmentRequirements β†’ Design β†’ CodingFlexibleHigh communication cost
Spec-DrivenSpecification β†’ AI generated codeAutomation, traceabilityNeed to write specifications
Agile DevelopmentUser Stories β†’ IterationQuick ResponseMissing 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​

PrinciplesDescriptionExamples
SpecificSpecific and clear"User can log in" rather than "implement authentication"
MeasurableMeasurable"Password 8-32 characters" rather than "Password complex enough"
AchievableAchievableConsider technical limitations
RelevantRelevanceAlignment with business goals
Time-boundTime-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​

DimensionsSpec-DrivenVibe Coding
PlanningDetailed specificationsFeel free to play
TraceabilityHighLow
TeamworkEasyHard
AI ParticipationCoreAuxiliary
Applicable scenariosLarge projects, teamsPrototypes, personal projects

Spec-Driven vs Test-Driven Development​

DimensionsSpec-DrivenTDD
Starting PointSpecificationsTesting
SequenceSpec β†’ Code β†’ TestTest β†’ Code
AI FriendlyYesNo
CombinableComposableRelatively 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​


Document updated: December 2025