Microservice Docs
Generate and maintain comprehensive, production-grade documentation for any microservice codebase using static code analysis only.
Inputs
| Variable |
Description |
Example |
${input:serviceName} |
Name of the service being documented |
user-preferences-api |
${input:serviceRoot} |
Absolute path to the service root |
/repos/myservice |
Core Principles
- Static Analysis Only — All documentation is generated by reading source code, config files, and build files. No compilation, building, or execution.
- Code-Grounded — Every documented feature, endpoint, model, and infrastructure component MUST exist in the codebase. Never hallucinate.
- Progressive Generation — Generate in phases, each building on the previous. Start with project overview, then expand outward.
- Cross-Referenced — Every document links to related documents.
- Generic & Adaptable — Templates work for any language, framework, or cloud provider.
Required Documentation Structure
project-root/
├── README.md # Quick start and navigation hub
├── docs/
│ ├── README.md # Documentation index & quick reference
│ ├── project-overview.md # Comprehensive project metadata
│ ├── openapi-docs/ # OpenAPI 3.0 specifications
│ │ └── {service-name}-openapi.yaml
│ ├── api-contracts/ # One file per endpoint
│ ├── architecture/ # C4 model diagrams
│ │ ├── system-context.md # C4 Level 1
│ │ ├── container-diagram.md # C4 Level 2
│ │ ├── component-diagram.md # C4 Level 3
│ │ └── deployment-diagram.md # C4 Level 4
│ ├── data-models/
│ │ ├── request-models.md
│ │ ├── response-models.md
│ │ └── data-model-er-diagram.md
│ ├── sequence-diagrams/ # One file per major flow
│ ├── dependencies/
│ │ ├── dependency-graph.md
│ │ ├── internal-dependencies.md
│ │ ├── external-dependencies.md
│ │ └── dependency-risk-assessment.md
│ ├── data-lineage/
│ │ ├── data-lineage-graph.md
│ │ ├── upstream-data-flows.md
│ │ └── downstream-data-flows.md
│ └── infrastructure/
│ ├── infrastructure-topology.md
│ ├── environment-configs.md
│ ├── networking.md
│ └── iam-policies.md # If cloud IAM exists
Adaptation Rules
Generate only what is relevant:
- No Terraform/CloudFormation? → Skip
infrastructure/iam-policies.md
- Single endpoint? → Put API contract inline in
project-overview.md
- No external service calls? → Skip
data-lineage/
- No cloud deployment? → Skip
infrastructure/infrastructure-topology.md
- Monolith, not microservice? → Simplify
architecture/ to fewer diagrams
Phase 1: README.md (Root)
The README must enable a new developer to understand and run the service in under 15 minutes.
If no README exists → Generate one with all required sections below.
If README already exists → Read it, compare against the checklist, present gaps, and ask for confirmation before modifying.
Required sections checklist:
- Service name, one-line purpose, quick-reference table (language, framework, build tool, module count)
- Prerequisites (runtime versions, tools, IDE)
- Configuration / environment variables table
- How to Run (3 methods): IDE, Terminal, Docker
- Available API endpoints (summary table: method, path, description)
- Example request (at least one curl command)
- Project structure tree
- Development commands (build, test, lint, format)
- Troubleshooting (minimum 2 common issues)
- Links to all documentation files
Phase 2: Documentation Index (docs/README.md)
Always generated. Navigation hub for docs/.
Required sections:
- Introductory paragraph — "This directory contains comprehensive documentation for the {service name} service, generated through static code analysis."
- Documentation Structure — bulleted list with relative links to every doc section
- Quick Reference — bold key-value pairs: Service, Type, Runtime, Build, Total Files
See references/DOCUMENTATION-INDEX-TEMPLATE.md.
Phase 3: Project Overview (docs/project-overview.md)
Always generated. Comprehensive project metadata document.
Required content:
- 2–3 paragraph service description (what it does, why it exists, where it fits)
- Project metadata as bold key-value pairs
- Module structure with purpose, key components, and dependencies per module
- Technology stack (frameworks, logging/monitoring, cloud, testing, build tools)
- REST API endpoint summary
- External integrations (databases, caches, third-party APIs)
- Environment configuration (profiles, required env vars, feature flags)
- Connection configuration (timeouts, pool sizes)
- Next steps with links to all other documentation
See references/PROJECT-OVERVIEW-TEMPLATE.md.
Phase 4: API Contracts
One file per endpoint. Sections in this exact order:
# API Contract: {Endpoint Name}
## Endpoint Information
## Description
## Path Parameters (omit if none)
## Query Parameters (omit if none)
## Request Headers
## Request Body
### Schema
### Required Fields
### Validation Rules
### Example Request
## Response
### Success Response
### Error Responses
## Authentication & Authorization
## Service Dependencies
## Data Flow
## Privacy & Compliance
## Monitoring & Tracing
## Testing
## Notes
See references/API-CONTRACT-TEMPLATE.md.
Phase 5: OpenAPI Specification (docs/openapi-docs/)
Always generated when the project has REST endpoints. Generate a single OpenAPI 3.0.3 YAML with:
info, servers, tags, paths (one per endpoint with parameters, request body, responses)
components.schemas — one schema per request/response model with types, required fields, examples
See references/OPENAPI-SPEC-TEMPLATE.md.
Phase 6: Architecture (C4 Model)
Four levels of Mermaid diagrams:
- Level 1 (system-context.md) — Service as a box, external systems, users/clients
- Level 2 (container-diagram.md) — Internal containers/modules, tech choices, protocols
- Level 3 (component-diagram.md) — Controllers, services, mappers, clients, filters, their dependencies
- Level 4 (deployment-diagram.md) — Cloud regions, clusters, LBs, replicas, security boundaries
See references/ARCHITECTURE-TEMPLATES.md.
Phase 7: Data Models
CRITICAL: Read the actual source file for every class before documenting it. Do not guess fields based on class names, similar classes, or logical assumptions.
Request Models & Response Models
- Each model: package/module, purpose, fields (name, type, required, description)
- Every field must be verified against the actual class/struct/interface declaration
- External library types: mark as "externally defined" — do NOT fabricate their fields
- Validation annotations: only document those that actually appear in source
- Enumerations: read all values from the actual enum/type definition
ER Diagram (data-model-er-diagram.md)
- Mermaid
erDiagram with all model relationships
- Every field in the diagram must exist in the corresponding source file
Field Verification Checklist (before finalizing any data model doc):
- Field exists — confirmed by reading the actual source file
- Field name matches — exact name, not inferred from JSON property or convention
- Type is correct — exact type including generics/union types
- Required/validation — only annotations that appear in source
- External vs internal — mark external types explicitly
- Deprecated — only mark if the source file explicitly marks it deprecated
See references/DATA-MODEL-TEMPLATES.md.
Phase 8: Sequence Diagrams
One file per major flow. Each includes:
- Mermaid sequence diagram with all participants from actual code
- Flow Description — numbered steps
- Error Handling — what happens when each step fails
- Performance Characteristics — latency, pooling, timeouts
- Monitoring & Observability — tracing, metrics, log correlation
Name files with numeric prefix: 01-create-flow.md, 02-get-flow.md.
See references/SEQUENCE-DIAGRAM-TEMPLATES.md.
Phase 9: Dependencies
- dependency-graph.md — Mermaid tree with risk indicators, conflict notes, circular dependency check
- internal-dependencies.md — Team-owned libs: version, purpose, usage location, coupling (High/Medium/Low)
- external-dependencies.md — Third-party libs: version, license, purpose, known CVEs
- dependency-risk-assessment.md — Risk dashboard (Critical/High/Medium/Low counts), upgrade roadmap
See references/DEPENDENCY-TEMPLATES.md.
Phase 10: Data Lineage
- data-lineage-graph.md — Mermaid flowchart: Data IN zone → Transformation Layer → Data OUT zone
- upstream-data-flows.md — All data sources: protocol, format, key fields
- downstream-data-flows.md — All data sinks: protocol, format, field-level mappings
See references/DATA-LINEAGE-TEMPLATES.md.
Phase 11: Infrastructure
- infrastructure-topology.md — Full cloud topology diagram, access paths, security boundaries, failure impact
- environment-configs.md — Environments table, profiles, feature flags per environment
- networking.md — Service discovery, load balancing, CORS, rate limiting, TLS
- iam-policies.md — IAM roles, policy statements, security analysis (if applicable)
See references/INFRASTRUCTURE-TEMPLATES.md.
Document Metadata Footer
Every documentation file MUST end with:
---
**Last Updated:** YYYY-MM-DD
**Key Metric Label**: Value
Generation Order
docs/project-overview.md (foundation — always generated)
docs/README.md (index — always generated)
README.md (root quick start)
architecture/ (C4 diagrams)
api-contracts/ (one per endpoint)
openapi-docs/ (always when endpoints exist)
data-models/
sequence-diagrams/
dependencies/
data-lineage/ (if external calls exist)
infrastructure/ (if cloud deployment exists)
Auto-Update Triggers
| Changed File Type |
Update These Docs |
| Controllers, request/response DTOs |
api-contracts/, openapi-docs/, data-models/ |
| Services, mappers, external clients |
sequence-diagrams/, data-lineage/ |
| Config files |
infrastructure/environment-configs.md, project-overview.md |
| Docker/K8s/Terraform |
infrastructure/, architecture/deployment-diagram.md |
| Build files |
dependencies/, project-overview.md |
Quality Standards
Common Mistakes
- Hallucinating fields — The most critical error. Every field in every table or diagram must trace back to a specific line in a source file. Never infer fields from class names or conventions.
- Documenting external library internals — If a type comes from an external dependency and its source is not in the project, mark it as "externally defined" and list only what is confirmed from usage.
- Skipping the README improvement check — When a README already exists, always read it fully before suggesting edits, and always get user approval before modifying.
- Generating all sections for a simple project — A single-endpoint service does not need 11 phases of docs. Use the Adaptation Rules to skip irrelevant sections.
- Stale cross-references — When updating one doc, check that all other docs linking to it are still accurate.
1---2name: microservice-docs3description: Use when creating a new service, updating APIs, changing configs, modifying deployments, or when documentation is missing or outdated and needs comprehensive microservice documentation generated from static code analysis.4---56# Microservice Docs78Generate and maintain comprehensive, production-grade documentation for any microservice codebase using static code analysis only.910## Inputs1112| Variable | Description | Example |13|----------|-------------|---------|14| `${input:serviceName}` | Name of the service being documented | `user-preferences-api` |15| `${input:serviceRoot}` | Absolute path to the service root | `/repos/myservice` |1617## Core Principles18191. **Static Analysis Only** — All documentation is generated by reading source code, config files, and build files. No compilation, building, or execution.202. **Code-Grounded** — Every documented feature, endpoint, model, and infrastructure component MUST exist in the codebase. Never hallucinate.213. **Progressive Generation** — Generate in phases, each building on the previous. Start with project overview, then expand outward.224. **Cross-Referenced** — Every document links to related documents.235. **Generic & Adaptable** — Templates work for any language, framework, or cloud provider.2425## Required Documentation Structure2627```28project-root/29├── README.md # Quick start and navigation hub30├── docs/31│ ├── README.md # Documentation index & quick reference32│ ├── project-overview.md # Comprehensive project metadata33│ ├── openapi-docs/ # OpenAPI 3.0 specifications34│ │ └── {service-name}-openapi.yaml35│ ├── api-contracts/ # One file per endpoint36│ ├── architecture/ # C4 model diagrams37│ │ ├── system-context.md # C4 Level 138│ │ ├── container-diagram.md # C4 Level 239│ │ ├── component-diagram.md # C4 Level 340│ │ └── deployment-diagram.md # C4 Level 441│ ├── data-models/42│ │ ├── request-models.md43│ │ ├── response-models.md44│ │ └── data-model-er-diagram.md45│ ├── sequence-diagrams/ # One file per major flow46│ ├── dependencies/47│ │ ├── dependency-graph.md48│ │ ├── internal-dependencies.md49│ │ ├── external-dependencies.md50│ │ └── dependency-risk-assessment.md51│ ├── data-lineage/52│ │ ├── data-lineage-graph.md53│ │ ├── upstream-data-flows.md54│ │ └── downstream-data-flows.md55│ └── infrastructure/56│ ├── infrastructure-topology.md57│ ├── environment-configs.md58│ ├── networking.md59│ └── iam-policies.md # If cloud IAM exists60```6162### Adaptation Rules6364Generate only what is relevant:65- **No Terraform/CloudFormation?** → Skip `infrastructure/iam-policies.md`66- **Single endpoint?** → Put API contract inline in `project-overview.md`67- **No external service calls?** → Skip `data-lineage/`68- **No cloud deployment?** → Skip `infrastructure/infrastructure-topology.md`69- **Monolith, not microservice?** → Simplify `architecture/` to fewer diagrams7071## Phase 1: README.md (Root)7273The README must enable a new developer to understand and run the service in under 15 minutes.7475**If no README exists** → Generate one with all required sections below.7677**If README already exists** → Read it, compare against the checklist, present gaps, and ask for confirmation before modifying.7879**Required sections checklist:**80- Service name, one-line purpose, quick-reference table (language, framework, build tool, module count)81- Prerequisites (runtime versions, tools, IDE)82- Configuration / environment variables table83- **How to Run** (3 methods): IDE, Terminal, Docker84- Available API endpoints (summary table: method, path, description)85- Example request (at least one curl command)86- Project structure tree87- Development commands (build, test, lint, format)88- Troubleshooting (minimum 2 common issues)89- Links to all documentation files9091## Phase 2: Documentation Index (`docs/README.md`)9293**Always generated.** Navigation hub for `docs/`.9495Required sections:961. Introductory paragraph — "This directory contains comprehensive documentation for the {service name} service, generated through static code analysis."972. Documentation Structure — bulleted list with relative links to every doc section983. Quick Reference — bold key-value pairs: Service, Type, Runtime, Build, Total Files99100See [references/DOCUMENTATION-INDEX-TEMPLATE.md](references/DOCUMENTATION-INDEX-TEMPLATE.md).101102## Phase 3: Project Overview (`docs/project-overview.md`)103104**Always generated.** Comprehensive project metadata document.105106Required content:107- 2–3 paragraph service description (what it does, why it exists, where it fits)108- Project metadata as bold key-value pairs109- Module structure with purpose, key components, and dependencies per module110- Technology stack (frameworks, logging/monitoring, cloud, testing, build tools)111- REST API endpoint summary112- External integrations (databases, caches, third-party APIs)113- Environment configuration (profiles, required env vars, feature flags)114- Connection configuration (timeouts, pool sizes)115- Next steps with links to all other documentation116117See [references/PROJECT-OVERVIEW-TEMPLATE.md](references/PROJECT-OVERVIEW-TEMPLATE.md).118119## Phase 4: API Contracts120121**One file per endpoint.** Sections in this exact order:122123```124# API Contract: {Endpoint Name}125## Endpoint Information126## Description127## Path Parameters (omit if none)128## Query Parameters (omit if none)129## Request Headers130## Request Body131 ### Schema132 ### Required Fields133 ### Validation Rules134 ### Example Request135## Response136 ### Success Response137 ### Error Responses138## Authentication & Authorization139## Service Dependencies140## Data Flow141## Privacy & Compliance142## Monitoring & Tracing143## Testing144## Notes145```146147See [references/API-CONTRACT-TEMPLATE.md](references/API-CONTRACT-TEMPLATE.md).148149## Phase 5: OpenAPI Specification (`docs/openapi-docs/`)150151**Always generated** when the project has REST endpoints. Generate a single OpenAPI 3.0.3 YAML with:152- `info`, `servers`, `tags`, `paths` (one per endpoint with parameters, request body, responses)153- `components.schemas` — one schema per request/response model with types, required fields, examples154155See [references/OPENAPI-SPEC-TEMPLATE.md](references/OPENAPI-SPEC-TEMPLATE.md).156157## Phase 6: Architecture (C4 Model)158159Four levels of Mermaid diagrams:160- **Level 1 (system-context.md)** — Service as a box, external systems, users/clients161- **Level 2 (container-diagram.md)** — Internal containers/modules, tech choices, protocols162- **Level 3 (component-diagram.md)** — Controllers, services, mappers, clients, filters, their dependencies163- **Level 4 (deployment-diagram.md)** — Cloud regions, clusters, LBs, replicas, security boundaries164165See [references/ARCHITECTURE-TEMPLATES.md](references/ARCHITECTURE-TEMPLATES.md).166167## Phase 7: Data Models168169**CRITICAL: Read the actual source file for every class before documenting it.** Do not guess fields based on class names, similar classes, or logical assumptions.170171### Request Models & Response Models172- Each model: package/module, purpose, fields (name, type, required, description)173- Every field must be verified against the actual class/struct/interface declaration174- External library types: mark as "externally defined" — do NOT fabricate their fields175- Validation annotations: only document those that actually appear in source176- Enumerations: read all values from the actual enum/type definition177178### ER Diagram (`data-model-er-diagram.md`)179- Mermaid `erDiagram` with all model relationships180- Every field in the diagram must exist in the corresponding source file181182**Field Verification Checklist** (before finalizing any data model doc):1831. Field exists — confirmed by reading the actual source file1842. Field name matches — exact name, not inferred from JSON property or convention1853. Type is correct — exact type including generics/union types1864. Required/validation — only annotations that appear in source1875. External vs internal — mark external types explicitly1886. Deprecated — only mark if the source file explicitly marks it deprecated189190See [references/DATA-MODEL-TEMPLATES.md](references/DATA-MODEL-TEMPLATES.md).191192## Phase 8: Sequence Diagrams193194**One file per major flow.** Each includes:1951. Mermaid sequence diagram with all participants from actual code1962. Flow Description — numbered steps1973. Error Handling — what happens when each step fails1984. Performance Characteristics — latency, pooling, timeouts1995. Monitoring & Observability — tracing, metrics, log correlation200201Name files with numeric prefix: `01-create-flow.md`, `02-get-flow.md`.202203See [references/SEQUENCE-DIAGRAM-TEMPLATES.md](references/SEQUENCE-DIAGRAM-TEMPLATES.md).204205## Phase 9: Dependencies206207- **dependency-graph.md** — Mermaid tree with risk indicators, conflict notes, circular dependency check208- **internal-dependencies.md** — Team-owned libs: version, purpose, usage location, coupling (High/Medium/Low)209- **external-dependencies.md** — Third-party libs: version, license, purpose, known CVEs210- **dependency-risk-assessment.md** — Risk dashboard (Critical/High/Medium/Low counts), upgrade roadmap211212See [references/DEPENDENCY-TEMPLATES.md](references/DEPENDENCY-TEMPLATES.md).213214## Phase 10: Data Lineage215216- **data-lineage-graph.md** — Mermaid flowchart: Data IN zone → Transformation Layer → Data OUT zone217- **upstream-data-flows.md** — All data sources: protocol, format, key fields218- **downstream-data-flows.md** — All data sinks: protocol, format, field-level mappings219220See [references/DATA-LINEAGE-TEMPLATES.md](references/DATA-LINEAGE-TEMPLATES.md).221222## Phase 11: Infrastructure223224- **infrastructure-topology.md** — Full cloud topology diagram, access paths, security boundaries, failure impact225- **environment-configs.md** — Environments table, profiles, feature flags per environment226- **networking.md** — Service discovery, load balancing, CORS, rate limiting, TLS227- **iam-policies.md** — IAM roles, policy statements, security analysis (if applicable)228229See [references/INFRASTRUCTURE-TEMPLATES.md](references/INFRASTRUCTURE-TEMPLATES.md).230231## Document Metadata Footer232233Every documentation file MUST end with:234235```markdown236---237238**Last Updated:** YYYY-MM-DD239**Key Metric Label**: Value240```241242## Generation Order2432441. `docs/project-overview.md` (foundation — always generated)2452. `docs/README.md` (index — always generated)2463. `README.md` (root quick start)2474. `architecture/` (C4 diagrams)2485. `api-contracts/` (one per endpoint)2496. `openapi-docs/` (always when endpoints exist)2507. `data-models/`2518. `sequence-diagrams/`2529. `dependencies/`25310. `data-lineage/` (if external calls exist)25411. `infrastructure/` (if cloud deployment exists)255256## Auto-Update Triggers257258| Changed File Type | Update These Docs |259|---|---|260| Controllers, request/response DTOs | `api-contracts/`, `openapi-docs/`, `data-models/` |261| Services, mappers, external clients | `sequence-diagrams/`, `data-lineage/` |262| Config files | `infrastructure/environment-configs.md`, `project-overview.md` |263| Docker/K8s/Terraform | `infrastructure/`, `architecture/deployment-diagram.md` |264| Build files | `dependencies/`, `project-overview.md` |265266## Quality Standards267268- [ ] New dev can run service in < 15 minutes269- [ ] All commands copy-paste ready and tested270- [ ] No broken links between documents271- [ ] Env vars in tables with realistic examples272- [ ] At least 2 troubleshooting entries273- [ ] All Mermaid diagrams render correctly274- [ ] Tech stack versions match actual build files275- [ ] Every API endpoint has its own contract file276- [ ] OpenAPI spec covers all endpoints with accurate schemas277- [ ] All four C4 architecture levels present (where applicable)278- [ ] No hallucinated endpoints, infrastructure, or features279- [ ] Every file has a metadata footer280281## Common Mistakes282283- **Hallucinating fields** — The most critical error. Every field in every table or diagram must trace back to a specific line in a source file. Never infer fields from class names or conventions.284- **Documenting external library internals** — If a type comes from an external dependency and its source is not in the project, mark it as "externally defined" and list only what is confirmed from usage.285- **Skipping the README improvement check** — When a README already exists, always read it fully before suggesting edits, and always get user approval before modifying.286- **Generating all sections for a simple project** — A single-endpoint service does not need 11 phases of docs. Use the Adaptation Rules to skip irrelevant sections.287- **Stale cross-references** — When updating one doc, check that all other docs linking to it are still accurate.