### Database Migration Spec
```markdown
# Migration: [Name]
## Purpose
[Why this migration is needed]
## Changes
### New Tables
```sql
CREATE TABLE feature_flags (
id SERIAL PRIMARY KEY,
name VARCHAR(100) UNIQUE NOT NULL,
enabled BOOLEAN DEFAULT false,
created_at TIMESTAMP DEFAULT NOW()
);
Altered Tables
ALTER TABLE users
ADDCOLUMN last_login_at TIMESTAMP;
Indexes
CREATE INDEX idx_users_last_login ON users(last_login_at);
Data Migration
UPDATE users SET last_login_at = created_at WHERE last_login_at ISNULL;
Rollback Plan
ALTER TABLE users DROPCOLUMN last_login_at;
DROPTABLE feature_flags;
Impact
Downtime required: No
Estimated duration: < 1 minute
Affected services: [list]
### Feature Spec
```markdown
# Feature: [Name]
## User Story
As a [user type]
I want to [action]
So that [benefit]
## Acceptance Criteria
- [ ] Given [context], when [action], then [outcome]
- [ ] Given [context], when [action], then [outcome]
## UI/UX
[Mockup link or description]
## Technical Approach
### Frontend
- Components: [list]
- State management: [approach]
- API calls: [list]
### Backend
- Endpoints: [list]
- Services: [list]
- Models: [list]
### Database
- Tables affected: [list]
- New migrations: [list]
## Dependencies
- [ ] [Dependency 1]
- [ ] [Dependency 2]
## Out of Scope
- [What's NOT included]
Integration with Factory
Using Thinking Skills
## Before Writing Spec1.**Clarify with Socratic Method** (thinking-socratic)
- What assumptions am I making?
- What would happen if this failed?
- Who else needs to be involved?
2.**Identify Risks** (thinking-pre-mortem)
- What could go wrong?
- What are we overlooking?
3.**Consider Second-Order Effects** (thinking-second-order)
- How will this affect other systems?
- What behavior will this incentivize?
4.**Debias Your Thinking** (thinking-debiasing)
- Am I anchored to one solution?
- Am I overconfident?
Spec Mode in Factory
# Enter spec mode for a feature
/spec Add user authentication
# Factory will:# 1. Activate spec mode# 2. Use thinking skills to clarify requirements# 3. Draft specification# 4. Present with ExitSpecMode for approval
Best Practices
Spec before code - Always document before implementing
Keep specs updated - Update when requirements change
Link to issues - Reference GitHub issues/Jira tickets
Include diagrams - Visual architecture aids understanding
Define done - Clear acceptance criteria
Consider edge cases - Error handling, empty states
Plan for rollback - Always have a backout plan
Get early feedback - Share drafts before finalizing
Time-box speculation - Don't over-engineer specs
Test the spec - Review with stakeholders
Anti-Patterns to Avoid
Analysis paralysis - Spending too long on specs
Waterfall specs - Not iterating on specs
Missing stakeholders - Not involving the right people