Code Documentation
Overview
Generate professional, comprehensive documentation for software projects,
codebases, libraries, and APIs. Follows best practices from React, Django,
Stripe, Kubernetes to produce accurate, well-structured docs.
When to Use
- User asks to "document", "create docs", or "write documentation" for code
- User requests a README, API reference, or developer guide
- User shares a codebase and wants documentation generated
- User asks to improve or update existing documentation
- User needs architecture documentation with diagrams
- User requests a changelog or migration guide
Workflow
Phase 1: Codebase Analysis
Step 1.1: Project Discovery
| Field |
How to Determine |
| Language(s) |
File extensions, package.json, pyproject.toml, go.mod |
| Framework |
Dependencies (React, Django, Express, Spring) |
| Build System |
Makefile, CMakeLists.txt, webpack.config.js |
| Package Manager |
npm/yarn/pnpm, pip/uv/poetry, cargo |
| Project Structure |
Map directory tree |
| Entry Points |
main files, CLI entry points, exported modules |
| Existing Docs |
README, docs/, wiki, inline docs |
# Discover project structure
list_dir(".")
# Read key files
read_file("package.json") # or pyproject.toml, go.mod, etc.
# Find all source files
bash("find . -name '*.py' -not -path '*/venv/*' -not -path '*/.venv/*' | head -30")
Step 1.2: Code Structure Analysis
# Find entry points
bash("grep -rl 'if __name__' --include='*.py' . | head -10")
# Find API routes/endpoints
bash("grep -rn '@app.route\|@router\.\|def get\|def post' --include='*.py' . | head -20")
# Find exported modules
bash("grep -rn 'export\|module.exports' --include='*.js' --include='*.ts' . | head -20")
# Find classes (for API reference)
bash("grep -rn '^class ' --include='*.py' . | head -20")
Phase 2: Documentation Generation
README.md
# Project Name
> One-line description
## Features
- Feature 1
- Feature 2
## Installation
\`\`\`bash
pip install project-name
\`\`\`
## Quick Start
\`\`\`python
from project import Client
client = Client()
result = client.do_thing()
\`\`\`
## API Reference
### `Client.do_thing(param: str) -> Result`
Description of what this does.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| param | str | Yes | The input |
## Configuration
| Key | Default | Description |
|-----|---------|-------------|
## Contributing
See CONTRIBUTING.md
## License
MIT
API Reference
For each public function/class:
- Signature (parameters, return type)
- Description
- Parameters table
- Return value
- Example usage
- Exceptions raised
Architecture Documentation
- System overview diagram (use
architecture-diagram skill)
- Component descriptions
- Data flow
- Key design decisions (ADR format)
Phase 3: Review
Documentation Conventions by Language
| Language |
Inline Format |
Reference Format |
| Python |
docstrings (Google/NumPy style) |
Sphinx, MkDocs |
| JavaScript/TypeScript |
JSDoc/TSDoc |
JSDoc, TypeDoc |
| Go |
GoDoc comments |
godoc |
| Java |
Javadoc |
javadoc |
| Rust |
rustdoc (///) |
rustdoc |
Changelog Generation
# From git log
bash("git log --oneline --no-decorate v1.0.0..HEAD | head -50")
# Generate changelog from commits
bash("git log v1.0.0..HEAD --pretty=format:'- %s (%h)' --no-merges")
Pitfalls
- Stale docs: documentation must match code. If code changed, docs must
update. Note the commit/version the docs were generated from.
- No examples: documentation without runnable examples is useless. Always
include copy-pasteable examples.
- Over-documenting internals: document public API, not implementation
details. Internal code should have inline comments, not API docs.
- No table of contents: for long docs, include a TOC with anchor links.
- Missing prerequisites: list all dependencies, environment requirements,
and minimum versions.
1---2name: code-documentation3description: Generate docs: README, API reference, architecture, guides.4license: MIT5---67# Code Documentation89## Overview1011Generate professional, comprehensive documentation for software projects,12codebases, libraries, and APIs. Follows best practices from React, Django,13Stripe, Kubernetes to produce accurate, well-structured docs.1415## When to Use1617- User asks to "document", "create docs", or "write documentation" for code18- User requests a README, API reference, or developer guide19- User shares a codebase and wants documentation generated20- User asks to improve or update existing documentation21- User needs architecture documentation with diagrams22- User requests a changelog or migration guide2324## Workflow2526### Phase 1: Codebase Analysis2728#### Step 1.1: Project Discovery2930| Field | How to Determine |31|-------|-----------------|32| **Language(s)** | File extensions, `package.json`, `pyproject.toml`, `go.mod` |33| **Framework** | Dependencies (React, Django, Express, Spring) |34| **Build System** | `Makefile`, `CMakeLists.txt`, `webpack.config.js` |35| **Package Manager** | npm/yarn/pnpm, pip/uv/poetry, cargo |36| **Project Structure** | Map directory tree |37| **Entry Points** | main files, CLI entry points, exported modules |38| **Existing Docs** | README, docs/, wiki, inline docs |3940```bash41# Discover project structure42list_dir(".")43# Read key files44read_file("package.json") # or pyproject.toml, go.mod, etc.45# Find all source files46bash("find . -name '*.py' -not -path '*/venv/*' -not -path '*/.venv/*' | head -30")47```4849#### Step 1.2: Code Structure Analysis5051```bash52# Find entry points53bash("grep -rl 'if __name__' --include='*.py' . | head -10")5455# Find API routes/endpoints56bash("grep -rn '@app.route\|@router\.\|def get\|def post' --include='*.py' . | head -20")5758# Find exported modules59bash("grep -rn 'export\|module.exports' --include='*.js' --include='*.ts' . | head -20")6061# Find classes (for API reference)62bash("grep -rn '^class ' --include='*.py' . | head -20")63```6465### Phase 2: Documentation Generation6667#### README.md6869```markdown70# Project Name7172> One-line description7374## Features75- Feature 176- Feature 27778## Installation79\`\`\`bash80pip install project-name81\`\`\`8283## Quick Start84\`\`\`python85from project import Client86client = Client()87result = client.do_thing()88\`\`\`8990## API Reference91### `Client.do_thing(param: str) -> Result`92Description of what this does.9394| Parameter | Type | Required | Description |95|-----------|------|----------|-------------|96| param | str | Yes | The input |9798## Configuration99| Key | Default | Description |100|-----|---------|-------------|101102## Contributing103See CONTRIBUTING.md104105## License106MIT107```108109#### API Reference110111For each public function/class:112- Signature (parameters, return type)113- Description114- Parameters table115- Return value116- Example usage117- Exceptions raised118119#### Architecture Documentation120121- System overview diagram (use `architecture-diagram` skill)122- Component descriptions123- Data flow124- Key design decisions (ADR format)125126### Phase 3: Review127128- [ ] All public APIs documented129- [ ] Examples are runnable130- [ ] Installation instructions tested131- [ ] No broken links132- [ ] Language-appropriate conventions (docstrings, JSDoc, GoDoc)133- [ ] Architecture diagram included for complex projects134135## Documentation Conventions by Language136137| Language | Inline Format | Reference Format |138|----------|--------------|-----------------|139| Python | docstrings (Google/NumPy style) | Sphinx, MkDocs |140| JavaScript/TypeScript | JSDoc/TSDoc | JSDoc, TypeDoc |141| Go | GoDoc comments | godoc |142| Java | Javadoc | javadoc |143| Rust | rustdoc (`///`) | rustdoc |144145## Changelog Generation146147```bash148# From git log149bash("git log --oneline --no-decorate v1.0.0..HEAD | head -50")150151# Generate changelog from commits152bash("git log v1.0.0..HEAD --pretty=format:'- %s (%h)' --no-merges")153```154155## Pitfalls156157- **Stale docs**: documentation must match code. If code changed, docs must158 update. Note the commit/version the docs were generated from.159- **No examples**: documentation without runnable examples is useless. Always160 include copy-pasteable examples.161- **Over-documenting internals**: document public API, not implementation162 details. Internal code should have inline comments, not API docs.163- **No table of contents**: for long docs, include a TOC with anchor links.164- **Missing prerequisites**: list all dependencies, environment requirements,165 and minimum versions.