Intermediate

Writing Specs with spec-kit

Learn to write PRDs, technical specifications, API documentation, architecture decision records, user stories, and acceptance criteria — all with AI-powered assistance.

Writing PRDs with AI Assistance

A Product Requirements Document (PRD) defines what you are building and why. spec-kit's AI can generate a comprehensive PRD from a brief description:

Terminal
# Generate a PRD with AI assistance
specc create prd --name "notification-system" \
  --ai \
  --context "Real-time notification system supporting
  email, SMS, and push notifications with user
  preference management and rate limiting"

The AI generates a structured PRD including:

  • Overview & Problem Statement: Why this feature is needed
  • Goals & Non-Goals: What is and is not in scope
  • User Stories: Who uses it and how
  • Requirements: Functional and non-functional
  • Success Metrics: How to measure success
  • Timeline & Milestones: Delivery expectations
Tip: The more context you provide in the --context flag, the better the AI-generated output. Include technical constraints, target users, and business goals for best results.

Technical Specification Format

Technical specs describe how a system will be built. They complement PRDs by providing implementation details:

YAML + Markdown
---
title: Notification Service Technical Spec
type: tech-spec
status: review
related_prd: notification-system
---

# Notification Service

## Architecture
The notification service uses an event-driven
architecture with a message queue (RabbitMQ) for
reliable delivery across channels.

## Components
### NotificationRouter
Routes notifications to appropriate channel
handlers based on user preferences and message type.

### ChannelHandlers
- **EmailHandler**: SMTP integration via SendGrid
- **SMSHandler**: Twilio API integration
- **PushHandler**: Firebase Cloud Messaging

## Data Model
```sql
CREATE TABLE notifications (
  id UUID PRIMARY KEY,
  user_id UUID NOT NULL,
  channel VARCHAR(20) NOT NULL,
  status VARCHAR(20) DEFAULT 'pending',
  payload JSONB NOT NULL,
  created_at TIMESTAMP DEFAULT NOW()
);
```

## API Endpoints
- POST /api/notifications - Send notification
- GET  /api/notifications/:id - Get status
- PUT  /api/preferences - Update user preferences

API Specification Generation

spec-kit can generate API specifications from existing code or from descriptions:

Terminal
# Generate API spec from description
specc create api-spec --name "notifications-api" \
  --ai \
  --context "REST API for sending and managing
  notifications across email, SMS, and push channels"

# Generate from existing route files
specc create api-spec --name "notifications-api" \
  --scan src/routes/notifications.ts

Architecture Decision Records (ADRs)

ADRs capture the reasoning behind significant technical decisions. spec-kit structures them consistently:

YAML + Markdown
---
title: Use RabbitMQ for Message Queue
type: adr
status: accepted
date: 2026-03-14
decision_makers:
  - jane.doe
  - bob.smith
---

# ADR-003: Use RabbitMQ for Message Queue

## Context
We need a reliable message queue for the
notification service to handle async delivery.

## Decision
We will use RabbitMQ over Kafka and SQS.

## Rationale
- Supports complex routing patterns we need
- Team has existing expertise
- Lower operational overhead than Kafka
- Better for our message volume (10K/min)

## Consequences
- Need to manage RabbitMQ cluster
- Must implement dead letter queues
- Team training on RabbitMQ management

User Story Generation

spec-kit can generate user stories from PRDs or feature descriptions:

Terminal
# Generate user stories from a PRD
specc generate stories --from prds/notification-system.md

# Output:
Generated 8 user stories:
1. As a user, I want to receive email notifications
   so that I stay informed about important updates.
2. As a user, I want to manage my notification
   preferences so that I only receive relevant alerts.
3. As an admin, I want to set rate limits so that
   users are not overwhelmed with notifications.
...

Acceptance Criteria

AI-generated acceptance criteria ensure thorough test coverage:

Terminal
# Generate acceptance criteria for a user story
specc generate criteria \
  --story "As a user, I want to receive push
  notifications so that I get real-time alerts"

# Output:
Acceptance Criteria:
- [ ] Push notification appears within 5 seconds
- [ ] Notification includes title and body text
- [ ] Tapping notification opens the relevant screen
- [ ] Notifications respect device Do Not Disturb
- [ ] Failed deliveries are retried up to 3 times
- [ ] User can dismiss notifications

Data Model Specs

spec-kit helps document data models with AI-assisted schema generation:

Terminal
# Generate data model documentation
specc create data-model --name "notification-schema" \
  --ai \
  --context "Notification system with users,
  preferences, channels, and delivery logs"

# Scan existing database schema
specc create data-model --name "notification-schema" \
  --scan prisma/schema.prisma
💡
Remember: AI-generated content is a starting point, not a final product. Always review and refine the generated specifications to ensure they accurately reflect your project's requirements and constraints.