FSD Writer Skill
A general-purpose skill that turns a rough, unstructured project description into
a structured Functional Specification Document (FSD) in Markdown, or surgically
updates an existing FSD with new requirements, corrections, or expansions.
1. Purpose
This skill:
- Generates a canonical FSD from a rough description (initial mode).
- Updates or expands an existing FSD using a delta description (evolve mode).
- Dynamically adjusts depth and verbosity based on inferred system complexity.
- Ensures full requirement traceability (FR / NFR <-> test coverage).
- Surfaces risks, assumptions, and constraints as first-class content.
- Produces deterministic, agent-consumable Markdown.
It supports embedded systems, networking, SDR, IoT, cloud backends, mobile apps,
multi-service orchestrations, and hybrid hardware/software projects.
2. Invocation
2.1 Mode A — Initial Generation
Start a new FSD from scratch.
/fsd-writer
<rough description text>
Behavior:
- Parse the rough description.
- Ask clarifying questions if critical information is missing (Section 5).
- Infer complexity tier (Section 6).
- Generate the complete FSD (Section 7).
- Write the file (Section 10).
2.2 Mode B — Evolve Existing FSD
Update, expand, refactor, or correct an already existing FSD.
/fsd-writer update <path-to-existing-fsd>
<delta description — changes, additions, clarifications, new constraints>
If no path is given, search the project for an existing FSD:
- Check
Documents/*-fsd.md
- Check
Documents/*-FSD.md
- Check
docs/*-fsd.md
- Check project root for
*-fsd.md
Behavior:
- Read the existing FSD in full using the Read tool.
- Parse the delta description.
- Ask clarifying questions only if the delta introduces architectural ambiguity.
- Apply changes surgically — preserve all unaffected sections verbatim.
- Regenerate only the sections affected by the delta.
- Maintain numbering, cross-references, and the traceability matrix automatically.
- Write the updated file using the Edit tool (preferred) or Write tool
(if changes are too extensive for surgical edits).
3. Tool Usage
This skill uses the following Claude Code tools:
| Tool |
When |
| Read |
Read existing FSD (evolve mode), read project files for context |
| Glob |
Find existing FSD files, scan project structure for architecture clues |
| Grep |
Search for protocols, frameworks, dependencies in project source |
| Write |
Create new FSD file (initial mode) or full rewrite |
| Edit |
Surgical updates to existing FSD sections (evolve mode) |
| AskUserQuestion |
Clarifying questions when critical info is missing |
| Task (Explore) |
Deep codebase exploration when the project has existing source code |
3.1 Context Gathering (Before Generation)
Before writing the FSD, the skill should gather context from the project when
source code exists:
- Glob for project structure —
**/*.c, **/*.h, **/*.py, **/*.ts,
**/Cargo.toml, **/package.json, **/CMakeLists.txt, **/go.mod, etc.
- Grep for protocols and frameworks — BLE, WiFi, MQTT, HTTP, gRPC, REST,
WebSocket, LoRa, OCPP, etc.
- Read key config files —
sdkconfig.defaults, platformio.ini,
docker-compose.yml, Makefile, build configs.
- Use findings to pre-fill architecture sections and reduce clarifying questions.
3.2 Evolve Mode — Diff Discipline
When updating an existing FSD:
- Never regenerate the entire file. Only touch sections affected by the delta.
- Use the Edit tool with precise
old_string / new_string pairs.
- If a delta adds a new phase, insert it and renumber subsequent phases.
- If a delta adds new FRs, assign the next available FR number in the correct group.
- Always update the traceability matrix when FRs or tests change.
- If the delta invalidates existing content, remove or revise it — do not leave
contradictions.
4. Interaction Model (Clarifying Questions)
4.1 When to Ask
The skill must ask clarifying questions when critical architecture-affecting
information is missing. "Critical" means it affects:
- System architecture or component decomposition
- Protocol selection (BLE vs WiFi vs LoRa vs cellular)
- Interface definitions (API style, command format)
- Safety or regulatory constraints
- Multi-phase decomposition
- Hardware or platform selection
- External integrations (MQTT broker, cloud service, Home Assistant, etc.)
4.2 How to Ask
Use the AskUserQuestion tool with:
- 1-3 precise questions per round (never a wall of questions)
- Multiple-choice options where possible (with sensible defaults)
- Questions phrased to unblock the FSD, not to explore nice-to-haves
Example:
Questions:
1. "How does the device connect?" → Options: WiFi, BLE, LoRa, Cellular, USB only
2. "Do you need OTA firmware updates?" → Options: Yes (WiFi), Yes (BLE DFU), No
3. "Who is the primary operator?" → Options: End user, Installer/technician, Automated backend
4.3 When to Infer Instead of Asking
The skill may silently infer reasonable defaults when:
- The detail does not significantly change high-level architecture, AND
- The cost of being wrong is low.
Safe inferences:
- "web API" mentioned → assume HTTP + JSON
- "logs" mentioned → assume structured logging to console / file / serial
- "dashboard" mentioned → describe generic "dashboard system" without naming tools
- "database" mentioned without type → assume PostgreSQL for relational, SQLite for embedded
When inferring, mark the inference in the FSD with (assumed) or group them in
Section 5: Risks, Assumptions & Dependencies.
5. Complexity Scaling Rules
The skill dynamically scales the FSD depth based on inferred system complexity.
5.1 Complexity Tiers
| Tier |
Characteristics |
Target Length |
Phases |
| Low |
Single MCU/service, simple data flows, 1-2 interfaces |
3-5 pages |
1-2 |
| Medium |
MCU + app, or multi-service, OTA, 2-4 protocols |
6-12 pages |
2-3 |
| High |
Distributed system, multi-protocol, real-time constraints, regulatory |
15-25+ pages |
3-5 |
5.2 Complexity Signals
Infer complexity from:
- Number of distinct components (devices, services, apps)
- Number of protocols (BLE, WiFi, MQTT, HTTP, LoRa, OCPP, Modbus, etc.)
- Number of external integrations (cloud, Home Assistant, third-party APIs)
- Presence of real-time constraints or safety requirements
- Domain (SDR, energy systems, medical → automatically higher complexity)
- Multi-user or multi-tenant requirements
5.3 Scaling Behavior
| FSD Section |
Low |
Medium |
High |
| System Overview |
Brief paragraph |
Full section |
Full + stakeholder analysis |
| Architecture |
Single diagram description |
Logical + platform + software |
All subsections, detailed |
| Phases |
1-2 phases, brief |
2-3 phases, full exit criteria |
3-5 phases, dependencies mapped |
| Requirements |
5-15 FRs, 3-5 NFRs |
15-30 FRs, 5-10 NFRs |
30+ FRs, 10+ NFRs, constraints |
| Risks & Assumptions |
Bullet list |
Table with mitigations |
Full risk register |
| Interfaces |
Inline descriptions |
Tables per protocol |
Full schemas, sequence descriptions |
| Operational Procedures |
Bullet steps |
Numbered procedures |
Detailed with recovery paths |
| V&V |
Checklist |
Phase-based test tables |
Full traceability matrix + acceptance |
| Troubleshooting |
3-5 common issues |
Symptom-cause-fix table |
Categorized diagnostic guide |
| Appendix |
Constants only |
Constants + examples |
Constants + schemas + diagrams + logs |
6. Information Extraction & Inference Rules
Given the rough description, the skill must extract or infer the following:
6.1 Project Name
Derive a short, descriptive name:
- "ESP32 BLE HID Keyboard"
- "Solar-Aware EV Charging Controller"
- "LoRa Mailbox Notifier"
6.2 System Purpose & Goals
Extract in 2-4 sentences: what problem is solved, for whom, in what environment.
6.3 System Components
Identify major components:
- Hardware / platforms (MCU, SBC, server, cloud)
- Software services / apps / daemons
- User-facing components (mobile app, web UI, CLI)
- External integrations (Home Assistant, OCPP backend, MQTT broker)
If components are implied but not explicit, infer and mark as assumptions.
6.4 Functional Requirements (FR)
Convert each described behavior into FR-x.y items:
- Group logically (Communication, Data Processing, User Interaction, Safety)
- Assign priority: Must / Should / May
- Use "shall" language: "The system shall..."
Example:
"Device sends sensor readings every minute and on threshold events."
Becomes:
- FR-1.1 [Must]: The device shall send periodic sensor measurements at a
configurable interval (default: 60 s).
- FR-1.2 [Must]: The device shall send an immediate measurement when a
threshold condition is met.
6.5 Non-Functional Requirements (NFR)
Extract or infer key NFRs with priorities:
- Performance (latency, throughput)
- Reliability / uptime
- Accuracy / precision
- Scalability
- Power consumption (embedded)
- Security and privacy (authentication, encryption, access control)
6.6 Interfaces & Data Models
From the description and answers:
- Identify protocols (BLE, WiFi, USB HID, HTTP, MQTT, LoRa, OCPP, etc.)
- Describe endpoints, characteristics, topics, commands
- Define payload structures (fields, units, types)
- Specify direction (client -> server, device -> cloud, etc.)
6.7 Phases
At minimum define:
- Phase 1: Infrastructure / Foundation
- Phase 2: Core Functional Features
- Phase 3+ (optional): Optimization, UX, analytics, etc.
Each phase must include: Scope, Deliverables, Exit Criteria, Dependencies.
6.8 Operational Procedures
Extract or infer:
- Deployment / flashing / installation
- Configuration / provisioning
- Normal operation workflows
- Failure recovery (reset, re-provisioning, safe-mode)
If not covered in the description, provide a generic but plausible set for the
domain.
6.9 Verification & Validation
From extracted requirements:
- Create test cases that verify FRs and critical NFRs
- Organize by phase and feature area
- Use structured format: Objective, Preconditions, Steps, Expected Result
- Build the traceability matrix (Section 8)
7. Canonical FSD Structure
All generated or updated FSDs must conform to this structure:
# <Project Name> — Functional Specification Document (FSD)
## 1. System Overview
- Purpose
- Problem statement
- Users / stakeholders
- Goals & non-goals
- High-level system flow
## 2. System Architecture
### 2.1 Logical Architecture
- Subsystems
- Data flow
- Runtime interactions
### 2.2 Hardware / Platform Architecture
- Devices, nodes, servers
- Key hardware / runtime platforms
- Connectivity and power (if relevant)
### 2.3 Software Architecture
- Tasks / modules / services
- Boot sequence (if applicable)
- Persistence / storage
- Update model (OTA, rollout strategy, etc.)
## 3. Implementation Phases
### 3.1 Phase 1 — Infrastructure Foundation
### 3.2 Phase 2 — Core Functionality
### 3.3 Phase 3+ — Extensions / Enhancements
Each phase includes:
- Scope (what is included)
- Deliverables (artifacts, running features)
- Exit criteria (tests passed, demos, metrics)
- Dependencies (on previous phases or external factors)
## 4. Functional Requirements
### 4.1 Functional Requirements (FR)
- FR-x.y [Must/Should/May]: requirement text
### 4.2 Non-Functional Requirements (NFR)
- NFR-x.y [Must/Should/May]: requirement text
### 4.3 Constraints
- Technological, regulatory, environmental constraints
## 5. Risks, Assumptions & Dependencies
- Technical risks (with likelihood, impact, mitigation)
- Assumptions (mark items inferred by this skill with "(assumed)")
- External dependencies
- Environmental constraints
- Regulatory constraints
## 6. Interface Specifications
### 6.1 External Interfaces
- APIs, protocols, user-facing interfaces
### 6.2 Internal Interfaces
- Inter-module / inter-service communication
### 6.3 Data Models / Schemas
- Key entities, message formats, payload schemas
### 6.4 Commands / Opcodes
- (If embedded or custom protocol — omit section if not applicable)
## 7. Operational Procedures
- Deployment / installation / flashing
- Provisioning / configuration
- Normal operation workflows
- Maintenance procedures
- Recovery procedures (factory reset, re-provisioning, safe-mode)
## 8. Verification & Validation
### 8.1 Phase 1 Verification
| Test ID | Feature | Procedure | Success Criteria |
|---------|---------|-----------|-----------------|
### 8.2 Phase 2 Verification
| Test ID | Feature | Procedure | Success Criteria |
|---------|---------|-----------|-----------------|
### 8.3 Acceptance Tests
- End-to-end scenarios
- Performance / load / reliability tests (if applicable)
### 8.4 Traceability Matrix
| Requirement | Priority | Test Case(s) | Status |
|------------|----------|-------------|--------|
| FR-1.1 | Must | TC-1.1, TC-1.2 | Covered |
| NFR-2.1 | Should | TC-5.1 | Covered |
| FR-3.4 | Must | --- | GAP |
## 9. Troubleshooting Guide
| Symptom | Likely Cause | Diagnostic Steps | Corrective Action |
|---------|-------------|-----------------|-------------------|
## 10. Appendix
- Constants, magic numbers, configuration defaults
- UUIDs, endpoints, topics, pinouts
- Timing diagrams, sequence descriptions
- Example logs, traces, payloads
7.1 Section Inclusion Rules
Not every section applies to every project. The skill must:
- Always include: Sections 1, 2, 3, 4, 5, 7, 8 (with traceability matrix)
- Include if applicable: Section 6.4 (Commands/Opcodes) — only for embedded or
custom protocols
- Include if complexity >= Medium: Section 9 (Troubleshooting), full Appendix
- Include if complexity = High: All sections, fully expanded
- Omit empty sections rather than writing "N/A" — but note the omission reason
in a comment if it might confuse readers
8. Traceability Matrix (Mandatory)
Every FSD must contain a traceability matrix in Section 8.4.
Rules:
- Every FR and NFR with priority Must or Should must appear in >= 1 test.
- Every test case must reference the FR(s) / NFR(s) it validates.
- Requirements with no test coverage must be flagged as
GAP.
- May-priority requirements may have test coverage but it is not mandatory.
- When updating an FSD (evolve mode), the matrix must be regenerated to reflect
any added, removed, or changed requirements and tests.
9. Formatting & Style Rules
- Output pure Markdown — no HTML tags.
- Use heading levels exactly as defined in Section 7.
- Use bullet lists for requirements; tables for tests, interfaces, and diagnostics.
- Use concise, unambiguous engineering language.
- Use "shall" for requirements ("The system shall...").
- Use "must" for constraints ("The device must operate on 3.3V").
- Avoid marketing language, filler, and subjective qualifiers.
- Keep requirement IDs stable across evolve updates — never renumber existing IDs
unless explicitly asked to refactor numbering.
- Use
(assumed) inline for inferred details.
10. Output File Naming & Location
10.1 Default Location
If the user does not specify a target path:
Documents/<project-name-kebab-case>-fsd.md
Create the Documents/ directory if it does not exist.
Examples:
Documents/esp32-ble-hid-keyboard-fsd.md
Documents/solar-ev-charging-controller-fsd.md
Documents/lora-mailbox-notifier-fsd.md
10.2 Explicit Path
If the user provides a path, use it exactly. Do not relocate or rename the file.
10.3 Evolve Mode
When updating, write to the same file that was read. Confirm the path before
writing if it was auto-detected.
11. Example Output Snippet
The following snippet demonstrates the expected tone, structure, and level of
detail for a medium-complexity project:
# ESP32 BLE HID Keyboard — Functional Specification Document (FSD)
## 1. System Overview
The ESP32-S3 BLE HID Keyboard System enables a smartphone app to transmit text
commands via BLE to an ESP32-S3 microcontroller, which converts them into USB HID
keyboard events for any connected host computer. The system eliminates the need
for Bluetooth keyboard pairing on the host side and provides deterministic,
low-latency input paths suitable for accessibility tools, automation, and
assistive typing.
**Primary goals:**
- Reliable BLE -> HID translation with sub-50 ms latency.
- Support for multiple keyboard layouts (US, DE, FR at minimum).
- OTA firmware updates via WiFi for field maintenance.
- Robust provisioning, logging, and recovery mechanisms.
**Non-goals:**
- The system does not act as a general-purpose BLE-to-USB bridge.
- No audio or media key support in Phase 1-2.
**Users / stakeholders:**
- End users who need assistive or automated keyboard input.
- Developers/installers who flash and provision the device.
## 4. Functional Requirements
### 4.1 Functional Requirements
#### Communication
- **FR-1.1** [Must]: The device shall accept text input via BLE Nordic UART
Service (NUS) from a connected smartphone.
- **FR-1.2** [Must]: The device shall convert received text into USB HID keyboard
reports and send them to the connected host within 50 ms.
- **FR-1.3** [Should]: The device shall support keyboard layout selection via BLE
command.
#### Update & Maintenance
- **FR-2.1** [Must]: The device shall support OTA firmware updates triggered via
BLE command or HTTP endpoint.
- **FR-2.2** [Should]: The device shall report its firmware version via HTTP
`/status` endpoint.
### 4.2 Non-Functional Requirements
- **NFR-1.1** [Must]: BLE-to-HID latency shall not exceed 50 ms under normal
operating conditions.
- **NFR-1.2** [Must]: The device shall recover from OTA failure by rolling back
to the previous firmware partition.
## 5. Risks, Assumptions & Dependencies
| Risk | Likelihood | Impact | Mitigation |
|------|-----------|--------|------------|
| USB HID descriptor rejected by host OS | Medium | High | Test with macOS, Windows, Linux during Phase 2 |
| BLE connection drops during text entry | Low | Medium | Implement reconnect logic with buffering |
**Assumptions:**
- The host computer provides USB bus power (500 mA) (assumed).
- iOS is the primary mobile platform; Android support is deferred (assumed).
**Dependencies:**
- ESP-IDF v5.x TinyUSB stack for HID support.
- NimBLE stack for BLE.
## 8. Verification & Validation
### 8.4 Traceability Matrix
| Requirement | Priority | Test Case(s) | Status |
|------------|----------|--------------------|---------|
| FR-1.1 | Must | TC-2.1 | Covered |
| FR-1.2 | Must | TC-2.2, TC-2.3 | Covered |
| FR-1.3 | Should | TC-2.4 | Covered |
| FR-2.1 | Must | TC-1.5, TC-2.5 | Covered |
| FR-2.2 | Should | TC-2.6 | Covered |
| NFR-1.1 | Must | TC-2.3 | Covered |
| NFR-1.2 | Must | TC-2.7 | Covered |
12. Evolve Mode — Detailed Behavior
When operating in evolve mode, the skill must follow these rules:
12.1 What to Preserve
- All section headings and numbering for unaffected sections.
- All existing FR/NFR IDs — never renumber unless explicitly asked.
- All existing test case IDs.
- Prose in unaffected sections — do not rephrase or "improve" text that is not
part of the delta.
12.2 What to Update
- Sections directly affected by the delta description.
- The traceability matrix (always — to reflect any FR/test changes).
- Cross-references if section numbers shift (e.g., new phase inserted).
- The Risks & Assumptions section if the delta introduces new risks or invalidates
existing assumptions.
12.3 What to Add
- New FRs/NFRs get the next available ID in their group.
- New phases get inserted in logical order; subsequent phases are renumbered.
- New test cases get the next available TC-x.y ID.
- New traceability rows are appended to the matrix.
12.4 What to Remove
- Requirements or sections the delta explicitly deprecates or removes.
- Assumptions that are now confirmed or contradicted by the delta.
- Traceability rows for removed requirements (mark as "Removed" rather than
deleting, to maintain audit trail).
12.5 Conflict Resolution
If the delta contradicts existing FSD content:
- Flag the contradiction to the user via AskUserQuestion.
- Do not silently overwrite — get explicit confirmation.
- Once resolved, update all affected sections consistently.
13. Quality Checklist
After generating or updating an FSD, the skill must verify:
Report any checklist failures to the user before finalizing.
1---2name: fsd-writer3description: Generates or updates a Functional Specification Document (FSD) from a rough project description. Supports initial generation and incremental evolution of existing FSDs. Domain-agnostic — works for embedded, IoT, backend, mobile, SDR, energy systems, and hybrid hardware/software projects. Triggers on "FSD", "write FSD", "new FSD", "update FSD", "evolve FSD", "functional spec", "specification document".4---5
6# FSD Writer Skill
7
8A general-purpose skill that turns a rough, unstructured project description into
9a structured Functional Specification Document (FSD) in Markdown, or surgically
10updates an existing FSD with new requirements, corrections, or expansions.
11
12## 1. Purpose
13
14This skill:
15
16- Generates a canonical FSD from a rough description (**initial mode**).
17- Updates or expands an existing FSD using a delta description (**evolve mode**).
18- Dynamically adjusts depth and verbosity based on inferred system complexity.
19- Ensures full requirement traceability (FR / NFR <-> test coverage).
20- Surfaces risks, assumptions, and constraints as first-class content.
21- Produces deterministic, agent-consumable Markdown.
22
23It supports embedded systems, networking, SDR, IoT, cloud backends, mobile apps,
24multi-service orchestrations, and hybrid hardware/software projects.
25
26## 2. Invocation
27
28### 2.1 Mode A — Initial Generation
29
30Start a new FSD from scratch.
31
32```
33/fsd-writer
34<rough description text>
35```
36
37Behavior:
381. Parse the rough description.
392. Ask clarifying questions if critical information is missing (Section 5).
403. Infer complexity tier (Section 6).
414. Generate the complete FSD (Section 7).
425. Write the file (Section 10).
43
44### 2.2 Mode B — Evolve Existing FSD
45
46Update, expand, refactor, or correct an already existing FSD.
47
48```
49/fsd-writer update <path-to-existing-fsd>
50<delta description — changes, additions, clarifications, new constraints>
51```
52
53If no path is given, search the project for an existing FSD:
541. Check `Documents/*-fsd.md`
552. Check `Documents/*-FSD.md`
563. Check `docs/*-fsd.md`
574. Check project root for `*-fsd.md`
58
59Behavior:
601. Read the existing FSD in full using the **Read** tool.
612. Parse the delta description.
623. Ask clarifying questions only if the delta introduces architectural ambiguity.
634. Apply changes surgically — preserve all unaffected sections verbatim.
645. Regenerate only the sections affected by the delta.
656. Maintain numbering, cross-references, and the traceability matrix automatically.
667. Write the updated file using the **Edit** tool (preferred) or **Write** tool
67 (if changes are too extensive for surgical edits).
68
69## 3. Tool Usage
70
71This skill uses the following Claude Code tools:
72
73| Tool | When |
74|------|------|
75| **Read** | Read existing FSD (evolve mode), read project files for context |
76| **Glob** | Find existing FSD files, scan project structure for architecture clues |
77| **Grep** | Search for protocols, frameworks, dependencies in project source |
78| **Write** | Create new FSD file (initial mode) or full rewrite |
79| **Edit** | Surgical updates to existing FSD sections (evolve mode) |
80| **AskUserQuestion** | Clarifying questions when critical info is missing |
81| **Task** (Explore) | Deep codebase exploration when the project has existing source code |
82
83### 3.1 Context Gathering (Before Generation)
84
85Before writing the FSD, the skill should gather context from the project when
86source code exists:
87
881. **Glob** for project structure — `**/*.c`, `**/*.h`, `**/*.py`, `**/*.ts`,
89 `**/Cargo.toml`, `**/package.json`, `**/CMakeLists.txt`, `**/go.mod`, etc.
902. **Grep** for protocols and frameworks — BLE, WiFi, MQTT, HTTP, gRPC, REST,
91 WebSocket, LoRa, OCPP, etc.
923. **Read** key config files — `sdkconfig.defaults`, `platformio.ini`,
93 `docker-compose.yml`, `Makefile`, build configs.
944. Use findings to pre-fill architecture sections and reduce clarifying questions.
95
96### 3.2 Evolve Mode — Diff Discipline
97
98When updating an existing FSD:
99
100- **Never regenerate the entire file.** Only touch sections affected by the delta.
101- Use the **Edit** tool with precise `old_string` / `new_string` pairs.
102- If a delta adds a new phase, insert it and renumber subsequent phases.
103- If a delta adds new FRs, assign the next available FR number in the correct group.
104- Always update the traceability matrix when FRs or tests change.
105- If the delta invalidates existing content, remove or revise it — do not leave
106 contradictions.
107
108## 4. Interaction Model (Clarifying Questions)
109
110### 4.1 When to Ask
111
112The skill must ask clarifying questions when critical architecture-affecting
113information is missing. "Critical" means it affects:
114
115- System architecture or component decomposition
116- Protocol selection (BLE vs WiFi vs LoRa vs cellular)
117- Interface definitions (API style, command format)
118- Safety or regulatory constraints
119- Multi-phase decomposition
120- Hardware or platform selection
121- External integrations (MQTT broker, cloud service, Home Assistant, etc.)
122
123### 4.2 How to Ask
124
125Use the **AskUserQuestion** tool with:
126- 1-3 precise questions per round (never a wall of questions)
127- Multiple-choice options where possible (with sensible defaults)
128- Questions phrased to unblock the FSD, not to explore nice-to-haves
129
130Example:
131
132```
133Questions:
1341. "How does the device connect?" → Options: WiFi, BLE, LoRa, Cellular, USB only
1352. "Do you need OTA firmware updates?" → Options: Yes (WiFi), Yes (BLE DFU), No
1363. "Who is the primary operator?" → Options: End user, Installer/technician, Automated backend
137```
138
139### 4.3 When to Infer Instead of Asking
140
141The skill may silently infer reasonable defaults when:
142- The detail does not significantly change high-level architecture, AND
143- The cost of being wrong is low.
144
145Safe inferences:
146- "web API" mentioned → assume HTTP + JSON
147- "logs" mentioned → assume structured logging to console / file / serial
148- "dashboard" mentioned → describe generic "dashboard system" without naming tools
149- "database" mentioned without type → assume PostgreSQL for relational, SQLite for embedded
150
151When inferring, mark the inference in the FSD with `(assumed)` or group them in
152**Section 5: Risks, Assumptions & Dependencies**.
153
154## 5. Complexity Scaling Rules
155
156The skill dynamically scales the FSD depth based on inferred system complexity.
157
158### 5.1 Complexity Tiers
159
160| Tier | Characteristics | Target Length | Phases |
161|------|----------------|---------------|--------|
162| **Low** | Single MCU/service, simple data flows, 1-2 interfaces | 3-5 pages | 1-2 |
163| **Medium** | MCU + app, or multi-service, OTA, 2-4 protocols | 6-12 pages | 2-3 |
164| **High** | Distributed system, multi-protocol, real-time constraints, regulatory | 15-25+ pages | 3-5 |
165
166### 5.2 Complexity Signals
167
168Infer complexity from:
169- Number of distinct components (devices, services, apps)
170- Number of protocols (BLE, WiFi, MQTT, HTTP, LoRa, OCPP, Modbus, etc.)
171- Number of external integrations (cloud, Home Assistant, third-party APIs)
172- Presence of real-time constraints or safety requirements
173- Domain (SDR, energy systems, medical → automatically higher complexity)
174- Multi-user or multi-tenant requirements
175
176### 5.3 Scaling Behavior
177
178| FSD Section | Low | Medium | High |
179|------------|-----|--------|------|
180| System Overview | Brief paragraph | Full section | Full + stakeholder analysis |
181| Architecture | Single diagram description | Logical + platform + software | All subsections, detailed |
182| Phases | 1-2 phases, brief | 2-3 phases, full exit criteria | 3-5 phases, dependencies mapped |
183| Requirements | 5-15 FRs, 3-5 NFRs | 15-30 FRs, 5-10 NFRs | 30+ FRs, 10+ NFRs, constraints |
184| Risks & Assumptions | Bullet list | Table with mitigations | Full risk register |
185| Interfaces | Inline descriptions | Tables per protocol | Full schemas, sequence descriptions |
186| Operational Procedures | Bullet steps | Numbered procedures | Detailed with recovery paths |
187| V&V | Checklist | Phase-based test tables | Full traceability matrix + acceptance |
188| Troubleshooting | 3-5 common issues | Symptom-cause-fix table | Categorized diagnostic guide |
189| Appendix | Constants only | Constants + examples | Constants + schemas + diagrams + logs |
190
191## 6. Information Extraction & Inference Rules
192
193Given the rough description, the skill must extract or infer the following:
194
195### 6.1 Project Name
196
197Derive a short, descriptive name:
198- "ESP32 BLE HID Keyboard"
199- "Solar-Aware EV Charging Controller"
200- "LoRa Mailbox Notifier"
201
202### 6.2 System Purpose & Goals
203
204Extract in 2-4 sentences: what problem is solved, for whom, in what environment.
205
206### 6.3 System Components
207
208Identify major components:
209- Hardware / platforms (MCU, SBC, server, cloud)
210- Software services / apps / daemons
211- User-facing components (mobile app, web UI, CLI)
212- External integrations (Home Assistant, OCPP backend, MQTT broker)
213
214If components are implied but not explicit, infer and mark as assumptions.
215
216### 6.4 Functional Requirements (FR)
217
218Convert each described behavior into FR-x.y items:
219- Group logically (Communication, Data Processing, User Interaction, Safety)
220- Assign priority: **Must** / **Should** / **May**
221- Use "shall" language: "The system shall..."
222
223Example:
224> "Device sends sensor readings every minute and on threshold events."
225
226Becomes:
227- **FR-1.1** [Must]: The device shall send periodic sensor measurements at a
228 configurable interval (default: 60 s).
229- **FR-1.2** [Must]: The device shall send an immediate measurement when a
230 threshold condition is met.
231
232### 6.5 Non-Functional Requirements (NFR)
233
234Extract or infer key NFRs with priorities:
235- Performance (latency, throughput)
236- Reliability / uptime
237- Accuracy / precision
238- Scalability
239- Power consumption (embedded)
240- Security and privacy (authentication, encryption, access control)
241
242### 6.6 Interfaces & Data Models
243
244From the description and answers:
245- Identify protocols (BLE, WiFi, USB HID, HTTP, MQTT, LoRa, OCPP, etc.)
246- Describe endpoints, characteristics, topics, commands
247- Define payload structures (fields, units, types)
248- Specify direction (client -> server, device -> cloud, etc.)
249
250### 6.7 Phases
251
252At minimum define:
253- **Phase 1**: Infrastructure / Foundation
254- **Phase 2**: Core Functional Features
255- **Phase 3+** (optional): Optimization, UX, analytics, etc.
256
257Each phase must include: Scope, Deliverables, Exit Criteria, Dependencies.
258
259### 6.8 Operational Procedures
260
261Extract or infer:
262- Deployment / flashing / installation
263- Configuration / provisioning
264- Normal operation workflows
265- Failure recovery (reset, re-provisioning, safe-mode)
266
267If not covered in the description, provide a generic but plausible set for the
268domain.
269
270### 6.9 Verification & Validation
271
272From extracted requirements:
273- Create test cases that verify FRs and critical NFRs
274- Organize by phase and feature area
275- Use structured format: Objective, Preconditions, Steps, Expected Result
276- Build the traceability matrix (Section 8)
277
278## 7. Canonical FSD Structure
279
280All generated or updated FSDs must conform to this structure:
281
282```markdown
283# <Project Name> — Functional Specification Document (FSD)
284
285## 1. System Overview
286- Purpose
287- Problem statement
288- Users / stakeholders
289- Goals & non-goals
290- High-level system flow
291
292## 2. System Architecture
293### 2.1 Logical Architecture
294- Subsystems
295- Data flow
296- Runtime interactions
297
298### 2.2 Hardware / Platform Architecture
299- Devices, nodes, servers
300- Key hardware / runtime platforms
301- Connectivity and power (if relevant)
302
303### 2.3 Software Architecture
304- Tasks / modules / services
305- Boot sequence (if applicable)
306- Persistence / storage
307- Update model (OTA, rollout strategy, etc.)
308
309## 3. Implementation Phases
310### 3.1 Phase 1 — Infrastructure Foundation
311### 3.2 Phase 2 — Core Functionality
312### 3.3 Phase 3+ — Extensions / Enhancements
313
314Each phase includes:
315- Scope (what is included)
316- Deliverables (artifacts, running features)
317- Exit criteria (tests passed, demos, metrics)
318- Dependencies (on previous phases or external factors)
319
320## 4. Functional Requirements
321### 4.1 Functional Requirements (FR)
322- FR-x.y [Must/Should/May]: requirement text
323
324### 4.2 Non-Functional Requirements (NFR)
325- NFR-x.y [Must/Should/May]: requirement text
326
327### 4.3 Constraints
328- Technological, regulatory, environmental constraints
329
330## 5. Risks, Assumptions & Dependencies
331- Technical risks (with likelihood, impact, mitigation)
332- Assumptions (mark items inferred by this skill with "(assumed)")
333- External dependencies
334- Environmental constraints
335- Regulatory constraints
336
337## 6. Interface Specifications
338### 6.1 External Interfaces
339- APIs, protocols, user-facing interfaces
340
341### 6.2 Internal Interfaces
342- Inter-module / inter-service communication
343
344### 6.3 Data Models / Schemas
345- Key entities, message formats, payload schemas
346
347### 6.4 Commands / Opcodes
348- (If embedded or custom protocol — omit section if not applicable)
349
350## 7. Operational Procedures
351- Deployment / installation / flashing
352- Provisioning / configuration
353- Normal operation workflows
354- Maintenance procedures
355- Recovery procedures (factory reset, re-provisioning, safe-mode)
356
357## 8. Verification & Validation
358### 8.1 Phase 1 Verification
359| Test ID | Feature | Procedure | Success Criteria |
360|---------|---------|-----------|-----------------|
361
362### 8.2 Phase 2 Verification
363| Test ID | Feature | Procedure | Success Criteria |
364|---------|---------|-----------|-----------------|
365
366### 8.3 Acceptance Tests
367- End-to-end scenarios
368- Performance / load / reliability tests (if applicable)
369
370### 8.4 Traceability Matrix
371| Requirement | Priority | Test Case(s) | Status |
372|------------|----------|-------------|--------|
373| FR-1.1 | Must | TC-1.1, TC-1.2 | Covered |
374| NFR-2.1 | Should | TC-5.1 | Covered |
375| FR-3.4 | Must | --- | GAP |
376
377## 9. Troubleshooting Guide
378| Symptom | Likely Cause | Diagnostic Steps | Corrective Action |
379|---------|-------------|-----------------|-------------------|
380
381## 10. Appendix
382- Constants, magic numbers, configuration defaults
383- UUIDs, endpoints, topics, pinouts
384- Timing diagrams, sequence descriptions
385- Example logs, traces, payloads
386```
387
388### 7.1 Section Inclusion Rules
389
390Not every section applies to every project. The skill must:
391
392- **Always include**: Sections 1, 2, 3, 4, 5, 7, 8 (with traceability matrix)
393- **Include if applicable**: Section 6.4 (Commands/Opcodes) — only for embedded or
394 custom protocols
395- **Include if complexity >= Medium**: Section 9 (Troubleshooting), full Appendix
396- **Include if complexity = High**: All sections, fully expanded
397- **Omit empty sections** rather than writing "N/A" — but note the omission reason
398 in a comment if it might confuse readers
399
400## 8. Traceability Matrix (Mandatory)
401
402Every FSD must contain a traceability matrix in Section 8.4.
403
404Rules:
405- Every FR and NFR with priority **Must** or **Should** must appear in >= 1 test.
406- Every test case must reference the FR(s) / NFR(s) it validates.
407- Requirements with no test coverage must be flagged as `GAP`.
408- **May**-priority requirements may have test coverage but it is not mandatory.
409- When updating an FSD (evolve mode), the matrix must be regenerated to reflect
410 any added, removed, or changed requirements and tests.
411
412## 9. Formatting & Style Rules
413
414- Output pure Markdown — no HTML tags.
415- Use heading levels exactly as defined in Section 7.
416- Use bullet lists for requirements; tables for tests, interfaces, and diagnostics.
417- Use concise, unambiguous engineering language.
418- Use **"shall"** for requirements ("The system shall...").
419- Use **"must"** for constraints ("The device must operate on 3.3V").
420- Avoid marketing language, filler, and subjective qualifiers.
421- Keep requirement IDs stable across evolve updates — never renumber existing IDs
422 unless explicitly asked to refactor numbering.
423- Use `(assumed)` inline for inferred details.
424
425## 10. Output File Naming & Location
426
427### 10.1 Default Location
428
429If the user does not specify a target path:
430
431```
432Documents/<project-name-kebab-case>-fsd.md
433```
434
435Create the `Documents/` directory if it does not exist.
436
437Examples:
438- `Documents/esp32-ble-hid-keyboard-fsd.md`
439- `Documents/solar-ev-charging-controller-fsd.md`
440- `Documents/lora-mailbox-notifier-fsd.md`
441
442### 10.2 Explicit Path
443
444If the user provides a path, use it exactly. Do not relocate or rename the file.
445
446### 10.3 Evolve Mode
447
448When updating, write to the same file that was read. Confirm the path before
449writing if it was auto-detected.
450
451## 11. Example Output Snippet
452
453The following snippet demonstrates the expected tone, structure, and level of
454detail for a medium-complexity project:
455
456```markdown
457# ESP32 BLE HID Keyboard — Functional Specification Document (FSD)
458
459## 1. System Overview
460
461The ESP32-S3 BLE HID Keyboard System enables a smartphone app to transmit text
462commands via BLE to an ESP32-S3 microcontroller, which converts them into USB HID
463keyboard events for any connected host computer. The system eliminates the need
464for Bluetooth keyboard pairing on the host side and provides deterministic,
465low-latency input paths suitable for accessibility tools, automation, and
466assistive typing.
467
468**Primary goals:**
469- Reliable BLE -> HID translation with sub-50 ms latency.
470- Support for multiple keyboard layouts (US, DE, FR at minimum).
471- OTA firmware updates via WiFi for field maintenance.
472- Robust provisioning, logging, and recovery mechanisms.
473
474**Non-goals:**
475- The system does not act as a general-purpose BLE-to-USB bridge.
476- No audio or media key support in Phase 1-2.
477
478**Users / stakeholders:**
479- End users who need assistive or automated keyboard input.
480- Developers/installers who flash and provision the device.
481
482## 4. Functional Requirements
483
484### 4.1 Functional Requirements
485
486#### Communication
487- **FR-1.1** [Must]: The device shall accept text input via BLE Nordic UART
488 Service (NUS) from a connected smartphone.
489- **FR-1.2** [Must]: The device shall convert received text into USB HID keyboard
490 reports and send them to the connected host within 50 ms.
491- **FR-1.3** [Should]: The device shall support keyboard layout selection via BLE
492 command.
493
494#### Update & Maintenance
495- **FR-2.1** [Must]: The device shall support OTA firmware updates triggered via
496 BLE command or HTTP endpoint.
497- **FR-2.2** [Should]: The device shall report its firmware version via HTTP
498 `/status` endpoint.
499
500### 4.2 Non-Functional Requirements
501
502- **NFR-1.1** [Must]: BLE-to-HID latency shall not exceed 50 ms under normal
503 operating conditions.
504- **NFR-1.2** [Must]: The device shall recover from OTA failure by rolling back
505 to the previous firmware partition.
506
507## 5. Risks, Assumptions & Dependencies
508
509| Risk | Likelihood | Impact | Mitigation |
510|------|-----------|--------|------------|
511| USB HID descriptor rejected by host OS | Medium | High | Test with macOS, Windows, Linux during Phase 2 |
512| BLE connection drops during text entry | Low | Medium | Implement reconnect logic with buffering |
513
514**Assumptions:**
515- The host computer provides USB bus power (500 mA) (assumed).
516- iOS is the primary mobile platform; Android support is deferred (assumed).
517
518**Dependencies:**
519- ESP-IDF v5.x TinyUSB stack for HID support.
520- NimBLE stack for BLE.
521
522## 8. Verification & Validation
523
524### 8.4 Traceability Matrix
525
526| Requirement | Priority | Test Case(s) | Status |
527|------------|----------|--------------------|---------|
528| FR-1.1 | Must | TC-2.1 | Covered |
529| FR-1.2 | Must | TC-2.2, TC-2.3 | Covered |
530| FR-1.3 | Should | TC-2.4 | Covered |
531| FR-2.1 | Must | TC-1.5, TC-2.5 | Covered |
532| FR-2.2 | Should | TC-2.6 | Covered |
533| NFR-1.1 | Must | TC-2.3 | Covered |
534| NFR-1.2 | Must | TC-2.7 | Covered |
535```
536
537## 12. Evolve Mode — Detailed Behavior
538
539When operating in evolve mode, the skill must follow these rules:
540
541### 12.1 What to Preserve
542
543- All section headings and numbering for unaffected sections.
544- All existing FR/NFR IDs — never renumber unless explicitly asked.
545- All existing test case IDs.
546- Prose in unaffected sections — do not rephrase or "improve" text that is not
547 part of the delta.
548
549### 12.2 What to Update
550
551- Sections directly affected by the delta description.
552- The traceability matrix (always — to reflect any FR/test changes).
553- Cross-references if section numbers shift (e.g., new phase inserted).
554- The Risks & Assumptions section if the delta introduces new risks or invalidates
555 existing assumptions.
556
557### 12.3 What to Add
558
559- New FRs/NFRs get the next available ID in their group.
560- New phases get inserted in logical order; subsequent phases are renumbered.
561- New test cases get the next available TC-x.y ID.
562- New traceability rows are appended to the matrix.
563
564### 12.4 What to Remove
565
566- Requirements or sections the delta explicitly deprecates or removes.
567- Assumptions that are now confirmed or contradicted by the delta.
568- Traceability rows for removed requirements (mark as "Removed" rather than
569 deleting, to maintain audit trail).
570
571### 12.5 Conflict Resolution
572
573If the delta contradicts existing FSD content:
5741. Flag the contradiction to the user via **AskUserQuestion**.
5752. Do not silently overwrite — get explicit confirmation.
5763. Once resolved, update all affected sections consistently.
577
578## 13. Quality Checklist
579
580After generating or updating an FSD, the skill must verify:
581
582- [ ] Every **Must** and **Should** FR/NFR appears in the traceability matrix.
583- [ ] Every traceability row with no test is marked `GAP`.
584- [ ] No `<placeholder>` or `TODO` text remains (flag to user if unresolvable).
585- [ ] Section numbering is sequential with no gaps.
586- [ ] All phases have scope, deliverables, and exit criteria.
587- [ ] The file has been written to the correct path.
588- [ ] (Evolve mode) Unaffected sections are identical to the original.
589
590Report any checklist failures to the user before finalizing.