---
name: document-generate
description: Use when documenting code: generates missing Diataxis docs (tutorial, how-to, reference, explanation) for a feature, module, or project.
---
# Document Generate: Diataxis Documentation Writer
## What this does
Researches the code thoroughly, then writes structured documentation from scratch using the Diataxis framework: Tutorial (learning-oriented), How-to (task-oriented), Reference (information-oriented), Explanation (understanding-oriented). Philosophy: research the whole, then write the parts.
## When to use
- "write docs for this", "generate documentation", "document this feature", "create a tutorial", "write a how-to", "explain this module", "docs for this project"
- A coverage check found undocumented features and you need to fill the gaps.
## How to run it
1. **Scope and intent.** Decide the target: a specific feature/module/file, the whole project, or listed gaps. Ask the user where docs should go: (A) inline in existing files (README, ARCHITECTURE), (B) standalone files such as `docs/`, or (C) both. Recommend C: inline summaries for discoverability plus deep docs in standalone files. Follow existing conventions: if `docs/` exists or a doc framework is used (Nextra, Docusaurus, MkDocs, VitePress), match it; otherwise plain Markdown in `docs/`.
2. **Codebase archaeology (most important step).**
- Map the structure, excluding `.git`, `node_modules`, `dist`, `build`, `.next`.
- Read entry points: README, ARCHITECTURE, CONTRIBUTING, CLAUDE.md/AGENTS.md, package manifest (package.json, Cargo.toml, pyproject.toml, go.mod), main entry files, config examples.
- For each target, read implementation end-to-end, the tests (they reveal intended behavior and edge cases), related modules, and comments like NOTE/DESIGN/WHY.
- Build an internal concept map: Target, Purpose (one sentence), Key concepts (3-5), Public surface, Dependencies, Dependents, Edge cases, Design decisions.
- Report: "Researched N files, identified K public surface items, M concepts, J design decisions."
3. **Partition by quadrant.** Not every entity needs all four:
- New user-facing feature: tutorial, how-to, reference, maybe explanation
- CLI command/flag: how-to, reference
- Internal module/architecture: reference, explanation
- Config option: how-to, reference
- Design pattern/philosophy: explanation only
- API endpoint: how-to, reference, maybe tutorial
- Multi-step workflow: tutorial, how-to, maybe explanation
Show the plan as a table. If more than 5 documents, confirm with the user first.
4. **Write reference docs first** (they establish vocabulary), then how-tos and tutorials, then explanations. Accuracy over elegance: every claim must trace to code. Include types, defaults, and constraints (e.g. "string, max 256 chars, matches `^[a-z-]+$`", not "accepts a string"). Use real, runnable examples.
## Reference doc template
markdown
# {Entity Name}
{One paragraph: what it is, what it does, when you'd use it.}
## API / Interface
{Complete public surface: functions, commands, config options, parameters, with types, defaults, constraints.}
## Options / Configuration
{Every option with type, default, and effect, if applicable.}
## Examples
{2-3 concrete examples with real command output or code that would run.}
## Related
{Links to other reference docs, how-tos, or explanations.}
## Output
New documentation files (and inline summaries if chosen) in the agreed location, plus a short list of what was written per quadrant and any gaps you could not verify from the code.
Credit: Based on public content by garrytan, packaged by Orbit.