Bonus: The Spec Kit
AI-Powered Specification and Requirements Writing
What is the Spec Kit?
The Spec Kit is Microsoft's framework for AI-assisted specification writing. It combines structured templates, best practices, and AI prompts to help developers and technical writers create comprehensive, consistent technical specifications, requirements documents, API designs, and architecture documentation.
Rather than starting from a blank page, the Spec Kit provides a structured approach to capture requirements, design decisions, and technical details using AI as an intelligent collaborator that asks the right questions and helps you think through edge cases and implications.
Why Specifications Matter (Even More with AI)
In the age of AI-assisted development, clear specifications are more critical than ever. Here's why:
- AI Needs Context: Well-written specs provide the context AI tools need to generate accurate code
- Team Alignment: Specs ensure everyone (including AI) works toward the same goals
- Reduces Rework: Catching design issues early is cheaper than fixing generated code later
- Knowledge Capture: Specs serve as training data for future AI-assisted work
- Compliance & Auditing: Many industries require documented specifications for regulatory compliance
When to Use the Spec Kit
1. New Feature Development
Before writing a single line of code, use the Spec Kit to document what you're building, why, and how. This spec becomes the input for AI-assisted code generation.
2. API Design
Designing APIs requires careful thought about contracts, versioning, and backward compatibility. The Spec Kit helps structure API specifications following industry standards like OpenAPI/Swagger.
3. Architecture Decision Records (ADRs)
Document significant architecture decisions, their context, consequences, and alternatives considered. ADRs become valuable context for future AI-assisted development.
4. Technical RFCs (Request for Comments)
When proposing significant changes, use the Spec Kit to create comprehensive RFCs that invite team feedback and discussion before implementation.
5. Legacy System Documentation
Working with undocumented legacy code? Use the Spec Kit with AI to reverse-engineer specifications from existing implementations.
Spec Kit Structure
Core Template Components
Specification Document
├── 1. Overview
│ ├── Problem Statement
│ ├── Goals & Non-Goals
│ └── Success Metrics
├── 2. Background
│ ├── Current State
│ ├── User Research
│ └── Prior Art
├── 3. Requirements
│ ├── Functional Requirements
│ ├── Non-Functional Requirements
│ └── Constraints
├── 4. Proposed Solution
│ ├── High-Level Design
│ ├── Detailed Design
│ └── API Contracts
├── 5. Alternatives Considered
├── 6. Implementation Plan
│ ├── Phases
│ ├── Dependencies
│ └── Risks & Mitigations
└── 7. Appendices
├── Glossary
├── References
└── Open Questions
Quick Start: Writing Your First Spec with AI
Step 1: Set Up Your Environment
# Install the Spec Kit CLI (example)
npm install -g @microsoft/spec-kit
# Or clone the template repository
git clone https://github.com/microsoft/spec-kit.git
cd spec-kit
# Initialize a new spec
spec-kit init --template=feature-spec --name="user-authentication"
Step 2: Start with the Problem Statement
## Problem Statement
**Current Situation:**
Users must re-authenticate every time they visit our application, causing
friction and abandonment (35% drop-off rate at login).
**Impact:**
- Lost revenue: ~$200K monthly from abandoned sessions
- Poor user experience: Average 4.2 login attempts per user
- Support burden: 150+ weekly tickets related to login issues
**Desired Outcome:**
Implement secure "Remember Me" functionality that balances convenience
with security, reducing login friction by 80% while maintaining SOC 2 compliance.
**Constraints:**
- Must comply with GDPR, SOC 2 Type II
- Cannot store passwords in browser
- Must work across multiple devices
- Budget: $50K development, $5K monthly infrastructure
AI Prompt for Problem Refinement
Use GitHub Copilot Chat with this prompt:
@workspace Review this problem statement for a new feature.
Identify any:
1. Missing stakeholder impact analysis
2. Unclear success metrics
3. Unstated assumptions
4. Security or compliance gaps
5. Alternative approaches I should consider
Suggest improvements to make the problem statement more actionable.
Step 3: Define Requirements
## Functional Requirements
### Must Have (P0)
- [ ] FR-1: System generates secure, time-limited refresh tokens
- [ ] FR-2: Tokens automatically expire after 30 days of inactivity
- [ ] FR-3: Users can revoke access from any device via settings
- [ ] FR-4: System logs all authentication events for audit trail
- [ ] FR-5: Works across desktop, mobile web, and native apps
### Should Have (P1)
- [ ] FR-6: Email notification when new device logs in
- [ ] FR-7: Show list of active sessions with device info
- [ ] FR-8: Allow bulk revocation of all sessions
### Nice to Have (P2)
- [ ] FR-9: Biometric authentication for token refresh
- [ ] FR-10: Suspicious activity detection and auto-logout
## Non-Functional Requirements
- NFR-1: Performance: Token validation < 50ms at p99
- NFR-2: Availability: 99.9% uptime for auth service
- NFR-3: Security: Tokens encrypted at rest and in transit
- NFR-4: Scalability: Support 10M concurrent authenticated users
- NFR-5: Privacy: PII minimization in logs and tokens
- NFR-6: Compliance: GDPR Article 25 (privacy by design)
AI Prompt for Requirements Review
@workspace Analyze these requirements for completeness.
Check for:
1. Testability: Can each requirement be verified?
2. Conflicts: Do any requirements contradict each other?
3. Dependencies: What infrastructure/services are needed?
4. Edge cases: What unusual scenarios are not covered?
5. Accessibility: Are there any a11y requirements missing?
Generate additional requirements I may have missed.
Step 4: Design the Solution
## Proposed Solution
### High-Level Architecture
```
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Client │─────▶│ API Gateway │─────▶│ Auth │
│ (Browser) │ │ │ │ Service │
└─────────────┘ └──────────────┘ └─────────────┘
│ │
│ ▼
│ ┌──────────────┐
└───── Store Token ─────────────────▶│ Token │
(httpOnly cookie) │ Store │
│ (Redis) │
└──────────────┘
```
### Token Flow
1. **Initial Authentication**
- User provides credentials
- Server validates and creates refresh token
- Token stored in httpOnly cookie (XSS protection)
- Token metadata stored in Redis with TTL
2. **Session Refresh**
- Client sends refresh token with API requests
- API Gateway validates token signature
- If valid and not expired, issues new access token
- If invalid, requires re-authentication
3. **Token Revocation**
- User clicks "Log out all devices"
- Server invalidates all tokens for that user
- Next request from any device requires re-auth
### API Specification
```openapi
POST /auth/token/refresh
Content-Type: application/json
Cookie: refresh_token=eyJhbGc...
Response 200 OK:
{
"access_token": "eyJhbGc...",
"expires_in": 3600,
"token_type": "Bearer"
}
Response 401 Unauthorized:
{
"error": "invalid_token",
"error_description": "Refresh token expired or revoked"
}
```
AI Prompt for Design Validation
@workspace Review this authentication design.
Evaluate for:
1. Security vulnerabilities (OWASP Top 10)
2. Scalability bottlenecks
3. Single points of failure
4. Database/cache consistency issues
5. Performance under load
6. API design best practices
Suggest improvements and identify risks.
Advanced Spec Kit Patterns
Pattern 1: Spec-Driven Development
# Workflow
1. Write specification using Spec Kit template
2. Use AI to review and refine spec
3. Generate test cases from requirements
4. Use spec as context for AI code generation
5. Validate implementation against spec
# Example: Generate tests from spec
@workspace Based on the requirements in auth-spec.md, generate:
1. Unit test cases for token validation
2. Integration tests for the auth flow
3. Security test scenarios
4. Performance test criteria
Use pytest and include edge cases.
Pattern 2: Living Documentation
# Keep specs in sync with code
# Add to your CI/CD pipeline:
name: Validate Spec Sync
on: [pull_request]
jobs:
spec-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract implemented features
run: |
# Parse code for feature flags, implemented endpoints
node scripts/extract-features.js > implemented.json
- name: Compare with spec
run: |
# Compare spec requirements with implementation
spec-kit validate \
--spec=docs/specs/auth-spec.md \
--impl=implemented.json \
--strict
- name: Comment on PR
if: failure()
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
body: '⚠️ Implementation doesn't match spec. Run `spec-kit diff` locally.'
})
Pattern 3: Multi-Agent Spec Review
# Use specialized agents to review different aspects
# Security Review Agent
@workspace /security Review the auth spec for:
- OWASP Top 10 vulnerabilities
- Compliance with security standards
- Cryptographic best practices
- Data protection requirements
# Performance Review Agent
@workspace /performance Analyze the design for:
- Scalability constraints
- Performance bottlenecks
- Caching strategies
- Database query patterns
# Accessibility Review Agent
@workspace /accessibility Check for:
- WCAG 2.1 AA compliance
- Screen reader compatibility
- Keyboard navigation
- Error message clarity
Real-World Example: E-Commerce Feature Spec
Complete Specification
# Specification: Smart Shopping Cart Recommendations
## 1. Overview
### Problem Statement
Cart abandonment rate is 69.8%, costing $260B annually in lost sales.
Users struggle to discover complementary products that enhance their purchase.
### Goals
- Reduce cart abandonment by 15% within 3 months
- Increase average order value (AOV) by 12%
- Improve cross-sell conversion rate to 8%
### Non-Goals
- Not building a full recommendation engine (leverage existing ML service)
- Not replacing checkout flow (only augmenting cart page)
- Not personalizing homepage (separate project)
### Success Metrics
- Cart abandonment rate: 70% → 59%
- Average order value: $85 → $95
- Cross-sell click-through rate: 3% → 8%
- Page load time: < 2s (no regression)
## 2. Requirements
### Functional Requirements
**FR-1: Display Related Products**
- Show 3-5 product recommendations in cart
- Recommendations based on cart contents
- Each product shows: image, name, price, rating
- "Add to Cart" button for one-click addition
**FR-2: Smart Positioning**
- Recommendations appear after cart items
- Sticky on scroll (mobile)
- Dismissible (user preference remembered)
**FR-3: Real-Time Updates**
- Recommendations refresh when cart changes
- Loading state during fetch (< 500ms)
- Fallback to popular items if ML service unavailable
### Non-Functional Requirements
**NFR-1: Performance**
- Recommendations load asynchronously (non-blocking)
- Cache results for 5 minutes per cart state
- Lazy load product images
**NFR-2: Accessibility**
- WCAG 2.1 AA compliant
- Screen reader announces "Recommended for you"
- Keyboard navigation support
## 3. Proposed Solution
### Architecture
```javascript
// Frontend (React)
CartPage
├── CartItems
├── RecommendationWidget
│ ├── useRecommendations hook (fetch logic)
│ ├── ProductCard (display)
│ └── AddToCartButton (action)
└── CheckoutButton
// Backend API
GET /api/cart/:cartId/recommendations
- Queries ML service with cart items
- Caches result in Redis (5 min TTL)
- Returns ranked product list
```
### API Contract
```typescript
// Request
GET /api/cart/abc123/recommendations
Authorization: Bearer token
// Response
{
"recommendations": [
{
"productId": "prod_456",
"name": "Wireless Mouse",
"price": 2999,
"imageUrl": "https://...",
"rating": 4.5,
"rationale": "Pairs well with laptop in cart"
}
],
"metadata": {
"source": "ml_service",
"generatedAt": "2026-02-15T10:30:00Z",
"cacheHit": false
}
}
```
## 4. Implementation Plan
### Phase 1: MVP (Week 1-2)
- [ ] API endpoint for recommendations
- [ ] Basic React component
- [ ] Integration with ML service
- [ ] A/B test setup (50% traffic)
### Phase 2: Optimization (Week 3)
- [ ] Caching layer
- [ ] Performance monitoring
- [ ] Accessibility audit
- [ ] Mobile responsive design
### Phase 3: Enhancement (Week 4)
- [ ] User preference persistence
- [ ] Analytics events
- [ ] Admin dashboard for monitoring
- [ ] Documentation
### Dependencies
- ML recommendation service API access
- Redis cluster for caching
- Analytics platform integration
- Design system v2.0
### Risks & Mitigations
| Risk | Impact | Probability | Mitigation |
|------|--------|-------------|------------|
| ML service downtime | High | Medium | Fallback to popular items |
| Performance degradation | High | Low | Async loading, caching |
| Low click-through rate | Medium | Medium | A/B test multiple designs |
AI Prompts for Spec Kit Workflows
Initial Spec Generation
I need to create a technical specification for [feature/project name].
Context:
- Problem: [brief description]
- Users: [target audience]
- Constraints: [technical, budget, timeline]
Generate a comprehensive spec outline following Microsoft's Spec Kit format.
Include:
1. Problem statement with metrics
2. Functional and non-functional requirements
3. High-level architecture options
4. Implementation phases
5. Success criteria
Ask me questions to fill in gaps.
Spec Review & Refinement
@workspace Review this specification: [file path]
Analyze for:
1. Clarity: Are requirements unambiguous?
2. Completeness: What's missing?
3. Feasibility: Any unrealistic expectations?
4. Testability: Can requirements be verified?
5. Risks: What could go wrong?
Provide specific suggestions for improvement.
API Specification Generation
Generate an OpenAPI 3.0 specification for this feature: [description]
Include:
- Endpoint paths and HTTP methods
- Request/response schemas
- Authentication requirements
- Error responses (4xx, 5xx)
- Rate limiting details
- Example requests/responses
Follow REST best practices and semantic versioning.
Integration with Development Workflow
Spec-First Development Process
- Spec Creation: Use Spec Kit with AI assistance
- Spec Review: Team reviews, AI validates completeness
- Test Generation: AI generates test cases from requirements
- Implementation: AI assists coding with spec as context
- Validation: Automated check that code matches spec
- Documentation: Auto-generate user docs from spec
Linking Specs to Code
// In your code, reference spec requirements
/**
* Authenticates user and issues refresh token
*
* @spec-ref auth-spec.md#FR-1
* @complies-with GDPR Article 25, SOC 2 CC6.1
*/
async function authenticate(credentials) {
// Implementation
}
// In tests, link to requirements
describe('Authentication', () => {
// @spec-ref auth-spec.md#FR-1
it('should issue refresh token on successful login', async () => {
// Test implementation
});
});
Best Practices
- Start Early: Write specs before coding, not after
- Be Specific: Vague requirements lead to vague implementations
- Include Examples: Show concrete examples of expected behavior
- Version Control: Keep specs in Git alongside code
- Iterate: Specs evolve as you learn more
- Link Liberally: Reference related specs, ADRs, and RFCs
- Use AI Wisely: AI helps structure, not replace thinking
- Review Regularly: Keep specs updated as implementation progresses
Resources
- Spec Kit Repository: github.com/microsoft/spec-kit
- Template Library: Feature specs, API specs, ADRs, RFCs
- Example Gallery: Real-world specs from open source projects
- Style Guide: Writing conventions and best practices
- AI Prompts Library: Pre-built prompts for common spec tasks
Practice Task
Create a Specification for Your Current Project:
- Choose a feature you're planning to build
- Use the Spec Kit template to document it
- Use AI to review and refine each section
- Share with your team for feedback
- Use the spec as context for AI-assisted implementation
Track the time saved and quality improvements compared to your usual process.
🔗 Continue Your Journey
Explore more bonus topics:
- Bonus 1: Awesome-Copilot Repository - Community resources
- Bonus 2: GitHub Copilot SDK - Build custom extensions
- Bonus 4: Agentic Workflows - Advanced automation patterns
- Bonus 5: Copilot Coding Agent in Action - Automate development tasks
- Bonus 6: Copilot Instructions - Configure custom project guidance