Software Engineering Docs
Overview
Produce consistent, engineering-grade documentation from codebases and existing docs without documenting line-level implementation details. Keep requirements business-focused, keep interfaces and contracts explicit, and keep diagrams aligned with stated system boundaries.
Workflow Decision
Choose exactly one mode before writing:
full-generation mode
- Use when docs are missing, incomplete, or untrusted.
- Scan repository context, derive the system model, then generate all required docs.
doc-grounded-retrieval mode
- Use when docs already exist and the user asks questions or asks for targeted updates.
- Read existing docs first, extract relevant sections, reconcile conflicts, and answer/update with explicit cross-file references.
Core Rules
- Do not document implementation internals that should remain in code.
- Keep functional requirements at capability level. Avoid endpoint URLs, SQL, class names, or handler names in
requirements.md.
- Put interface and integration contracts in
specification.md, not in requirements.md.
- Keep all diagrams and narratives consistent with one shared system model.
- Use stable IDs across files:
- Functional requirements:
FR-###
- Non-functional requirements:
NFR-###
- Use cases:
UC-###
- Contracts:
CON-###
- External systems:
SYS-###
Step 1: Build Project Context
For existing applications, inspect:
- Product docs (
README, docs/, ADRs)
- Domain model (entities/value objects/events)
- Boundary code (controllers/routes/consumers/producers)
- Integration points (queues, DBs, third-party services)
- Test structure (unit/integration/e2e coverage patterns)
Use scripts/project_inventory.sh to collect a fast baseline inventory, then validate findings with targeted file reads.
Step 2: Build Canonical System Model
Before generating docs, define:
- Primary actors
- Internal systems/services and responsibilities
- External systems and contracts
- Core domain entities
- Primary business flows
- Quality attributes (security, reliability, scalability, observability, performance)
Treat this system model as the single source for all generated documents.
Step 3: Generate Documentation Set
Use references/templates.md and generate documents in this order:
requirements.md
- Include: goals, scope,
FR-*, NFR-*, constraints, acceptance criteria at capability level.
- Exclude: endpoint paths, payload schemas, table names, framework-specific details.
use_cases.md
- Include all
UC-* stories with actor, trigger, preconditions, main flow, alternates, exceptions, success guarantees.
- Include system interaction diagrams (Mermaid sequence/flowchart).
specification.md
- Include architecture style rationale (for example TDD/DDD/EDA/CQRS where applicable).
- Define high-level operational contracts
CON-* between systems.
- For each contract include: purpose, inputs/outputs, preconditions, postconditions, failure modes, idempotency/retry notes.
architecture.md
- Include context/container-level system diagram.
- Include each system responsibility, ownership boundary, and dependency relation.
uml.md
- Include UML class/domain diagrams for significant entities.
- Include attributes and behavior-level methods only when domain-relevant.
- Omit persistence/ORM/tooling noise.
tests.md (if applicable)
- Map
FR-* / NFR-* to validation strategy.
- Summarize coverage by test level (unit/integration/e2e/non-functional).
- List critical scenarios and quality gates.
Step 4: Enforce Consistency Gates
Apply checks from references/quality-gates.md before finalizing:
- Every
FR-* is covered by at least one UC-*.
- Every
UC-* maps to one or more CON-* or internal operations.
- Every external interaction in diagrams is represented in
specification.md.
NFR-* map to measurable verification notes in tests.md.
- No contradiction in terminology for systems/entities/actors across files.
- No endpoint-level details in
requirements.md.
Step 5: Doc-Grounded Retrieval and Update
When docs already exist and user asks for focused outputs:
- Read only relevant sections from existing docs first.
- Build a short trace map (
requirement -> use case -> contract -> test).
- Return or update only the needed sections.
- Preserve existing IDs unless user asks for refactoring.
- If docs conflict, prefer newest authoritative file and call out the conflict explicitly.
References
Load only as needed:
references/templates.md
references/quality-gates.md
references/diagram-patterns.md
1---2name: software-engineering-docs3description: Generate and maintain structured software engineering documentation for new or existing applications. Use when asked to create, update, or normalize requirements.md, use_cases.md, specification.md, architecture.md, uml.md, or tests.md from source code and existing docs, and when enforcing consistency and domain boundaries (for example, preventing endpoint-level details in high-level requirements).4---56# Software Engineering Docs78## Overview910Produce consistent, engineering-grade documentation from codebases and existing docs without documenting line-level implementation details. Keep requirements business-focused, keep interfaces and contracts explicit, and keep diagrams aligned with stated system boundaries.1112## Workflow Decision1314Choose exactly one mode before writing:15161. `full-generation` mode17- Use when docs are missing, incomplete, or untrusted.18- Scan repository context, derive the system model, then generate all required docs.19202. `doc-grounded-retrieval` mode21- Use when docs already exist and the user asks questions or asks for targeted updates.22- Read existing docs first, extract relevant sections, reconcile conflicts, and answer/update with explicit cross-file references.2324## Core Rules25261. Do not document implementation internals that should remain in code.272. Keep functional requirements at capability level. Avoid endpoint URLs, SQL, class names, or handler names in `requirements.md`.283. Put interface and integration contracts in `specification.md`, not in `requirements.md`.294. Keep all diagrams and narratives consistent with one shared system model.305. Use stable IDs across files:31- Functional requirements: `FR-###`32- Non-functional requirements: `NFR-###`33- Use cases: `UC-###`34- Contracts: `CON-###`35- External systems: `SYS-###`3637## Step 1: Build Project Context3839For existing applications, inspect:4041- Product docs (`README`, `docs/`, ADRs)42- Domain model (entities/value objects/events)43- Boundary code (controllers/routes/consumers/producers)44- Integration points (queues, DBs, third-party services)45- Test structure (unit/integration/e2e coverage patterns)4647Use `scripts/project_inventory.sh` to collect a fast baseline inventory, then validate findings with targeted file reads.4849## Step 2: Build Canonical System Model5051Before generating docs, define:52531. Primary actors542. Internal systems/services and responsibilities553. External systems and contracts564. Core domain entities575. Primary business flows586. Quality attributes (security, reliability, scalability, observability, performance)5960Treat this system model as the single source for all generated documents.6162## Step 3: Generate Documentation Set6364Use `references/templates.md` and generate documents in this order:65661. `requirements.md`67- Include: goals, scope, `FR-*`, `NFR-*`, constraints, acceptance criteria at capability level.68- Exclude: endpoint paths, payload schemas, table names, framework-specific details.69702. `use_cases.md`71- Include all `UC-*` stories with actor, trigger, preconditions, main flow, alternates, exceptions, success guarantees.72- Include system interaction diagrams (Mermaid sequence/flowchart).73743. `specification.md`75- Include architecture style rationale (for example TDD/DDD/EDA/CQRS where applicable).76- Define high-level operational contracts `CON-*` between systems.77- For each contract include: purpose, inputs/outputs, preconditions, postconditions, failure modes, idempotency/retry notes.78794. `architecture.md`80- Include context/container-level system diagram.81- Include each system responsibility, ownership boundary, and dependency relation.82835. `uml.md`84- Include UML class/domain diagrams for significant entities.85- Include attributes and behavior-level methods only when domain-relevant.86- Omit persistence/ORM/tooling noise.87886. `tests.md` (if applicable)89- Map `FR-*` / `NFR-*` to validation strategy.90- Summarize coverage by test level (unit/integration/e2e/non-functional).91- List critical scenarios and quality gates.9293## Step 4: Enforce Consistency Gates9495Apply checks from `references/quality-gates.md` before finalizing:96971. Every `FR-*` is covered by at least one `UC-*`.982. Every `UC-*` maps to one or more `CON-*` or internal operations.993. Every external interaction in diagrams is represented in `specification.md`.1004. `NFR-*` map to measurable verification notes in `tests.md`.1015. No contradiction in terminology for systems/entities/actors across files.1026. No endpoint-level details in `requirements.md`.103104## Step 5: Doc-Grounded Retrieval and Update105106When docs already exist and user asks for focused outputs:1071081. Read only relevant sections from existing docs first.1092. Build a short trace map (`requirement -> use case -> contract -> test`).1103. Return or update only the needed sections.1114. Preserve existing IDs unless user asks for refactoring.1125. If docs conflict, prefer newest authoritative file and call out the conflict explicitly.113114## References115116Load only as needed:117118- `references/templates.md`119- `references/quality-gates.md`120- `references/diagram-patterns.md`