Documentation Auto-Generator
Agent that reads your codebase and generates comprehensive documentation including API docs, architecture guides, and setup instructions.
Documentation Auto-Generator
Overview
An agent that reads your codebase and generates comprehensive documentation β API references, architecture overviews, setup guides, component docs, and developer onboarding guides. It understands code structure, extracts types and interfaces, and produces markdown documentation that stays accurate and up-to-date.
Quick Start
# Generate API documentation from your routes claude "Generate API documentation for all endpoints in src/routes/" # Generate a project README claude "Create a comprehensive README for this project" # Generate architecture documentation claude "Document the system architecture with diagrams" # Generate component documentation claude "Create docs for all React components in src/components/"
Documentation Types
1. API Reference
Generates endpoint documentation from your route files:
## POST /api/users Create a new user account. **Authentication:** Required (Bearer token) **Authorization:** Admin only ### Request Body | Field | Type | Required | Description | |-------|------|----------|-------------| | `email` | string | Yes | Valid email address | | `name` | string | Yes | Full name (2-100 chars) | | `role` | enum | No | One of: `admin`, `editor`, `viewer`. Default: `viewer` | | `teamId` | string | No | Team to assign the user to | ### Example Request ```json POST /api/users Authorization: Bearer eyJhbG... Content-Type: application/json { "email": "[email protected]", "name": "Jane Smith", "role": "editor", "teamId": "team-123" }
Response
201 Created
{ "data": { "id": "usr_abc123", "email": "[email protected]", "name": "Jane Smith", "role": "editor", "teamId": "team-123", "createdAt": "2024-01-15T10:30:00Z" } }
Error Responses
| Status | Description |
|---|---|
400 | Validation failed (invalid email, missing required fields) |
401 | Missing or invalid authentication token |
403 | Insufficient permissions (admin required) |
409 | Email already registered |
### 2. Architecture Overview
Generates system-level documentation:
```markdown
## System Architecture
### Overview
The application follows a layered architecture with clear separation
of concerns:
βββββββββββββββββββββββββββββββββββββββββββ β Client Layer β β React SPA / Mobile App / API Client β βββββββββββββββββββββββββββββββββββββββββββ€ β API Gateway β β Rate Limiting Β· Auth Β· Load Balance β ββββββββββ¬βββββββββββ¬ββββββββββ¬βββββββββββ€ β Auth β Users β Orders β Payments β βService β Service β Service β Service β ββββββββββ΄βββββββββββ΄ββββββββββ΄βββββββββββ€ β Message Queue (Redis) β ββββββββββ¬βββββββββββ¬ββββββββββ¬βββββββββββ€ β User β Order β Payment β Event β β DB β DB β DB β Store β ββββββββββ΄βββββββββββ΄ββββββββββ΄βββββββββββ
### Directory Structure
src/ βββ routes/ # HTTP endpoint definitions βββ controllers/ # Request handling & response formatting βββ services/ # Business logic (framework-agnostic) βββ models/ # Database schemas & data access βββ middleware/ # Auth, validation, error handling βββ utils/ # Shared utilities & helpers βββ types/ # TypeScript interfaces & types βββ config/ # Environment & app configuration βββ jobs/ # Background job processors βββ tests/ # Test suites
### Data Flow
1. Request hits route β middleware chain (auth, rate limit, validate)
2. Controller parses request β calls service with clean data
3. Service executes business logic β calls model for data access
4. Model queries database β returns typed results
5. Controller formats response β sends to client
### Key Design Decisions
| Decision | Choice | Rationale |
|----------|--------|-----------|
| Architecture | Layered monolith | Simple to start, easy to extract services later |
| Database | PostgreSQL | ACID compliance, JSON support, mature ecosystem |
| Auth | JWT + refresh tokens | Stateless, scalable, standard |
| API style | REST | Team familiarity, tooling support |
| Queue | Redis + BullMQ | Simple setup, reliable for current scale |
3. Setup Guide
Generates onboarding documentation:
## Developer Setup Guide ### Prerequisites | Tool | Version | Installation | |------|---------|-------------| | Node.js | >= 20 | `nvm install 20` | | PostgreSQL | >= 15 | `brew install postgresql@15` | | Redis | >= 7 | `brew install redis` | | Docker | >= 24 | [Download](https://docker.com) | ### Quick Start 1. **Clone the repository** ```bash git clone https://github.com/org/project.git cd project
-
Install dependencies
npm install -
Set up environment variables
cp .env.example .env # Edit .env with your local settings -
Start the database
# Option A: Docker docker compose up -d postgres redis # Option B: Local services brew services start postgresql@15 brew services start redis -
Run database migrations
npm run db:migrate npm run db:seed # Optional: seed with test data -
Start the development server
npm run dev # API available at http://localhost:3001 # Frontend at http://localhost:3000
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_URL | Yes | β | PostgreSQL connection string |
REDIS_URL | Yes | redis://localhost:6379 | Redis connection string |
JWT_SECRET | Yes | β | Secret for signing JWT tokens |
PORT | No | 3001 | API server port |
NODE_ENV | No | development | Environment mode |
STRIPE_SECRET_KEY | No | β | Stripe API key (for payments) |
SMTP_HOST | No | β | Email server host |
Common Tasks
# Run tests npm test # Run tests in watch mode npm run test:watch # Lint code npm run lint # Format code npm run format # Build for production npm run build # Run database migrations npm run db:migrate # Create a new migration npm run db:migration:create -- --name add-orders-table # Reset database (development only) npm run db:reset
Troubleshooting
| Issue | Solution |
|---|---|
| Port 3001 already in use | lsof -i :3001 to find process, then kill -9 <PID> |
| Database connection refused | Check PostgreSQL is running: pg_isready |
| Migration failed | Run npm run db:status to check migration state |
| Node version mismatch | Run nvm use to switch to project's Node version |
### 4. Component Documentation
Generates docs for React components:
```markdown
## Component: DataTable
A feature-rich data table with sorting, pagination, filtering,
row selection, and CSV export.
### Import
```tsx
import { DataTable } from '@/components/DataTable';
Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | T[] | required | Array of data objects |
columns | Column<T>[] | required | Column definitions |
pageSize | number | 20 | Rows per page |
sortable | boolean | true | Enable column sorting |
selectable | boolean | false | Enable row selection |
onSelectionChange | (rows: T[]) => void | β | Callback on selection change |
onRowClick | (row: T) => void | β | Callback on row click |
loading | boolean | false | Show loading skeleton |
emptyMessage | string | 'No data' | Message when data is empty |
exportable | boolean | false | Show CSV export button |
Usage
const columns = [ { key: 'name', label: 'Name', sortable: true }, { key: 'email', label: 'Email', sortable: true }, { key: 'role', label: 'Role', render: (val) => <Badge>{val}</Badge> }, { key: 'createdAt', label: 'Joined', render: (val) => formatDate(val) }, ]; <DataTable data={users} columns={columns} pageSize={25} selectable onSelectionChange={setSelectedUsers} exportable />
### 5. Changelog
Generates release notes from git history:
```markdown
## v2.1.0 (2024-01-15)
### New Features
- **User invitations** β Invite users to teams via email with role assignment
- **CSV export** β Export table data to CSV from the DataTable component
- **Dark mode** β System-aware dark mode with manual toggle
### Improvements
- Improved search performance with debounced API calls
- Added loading skeletons to all data-heavy pages
- Reduced bundle size by 23% through code splitting
### Bug Fixes
- Fixed session expiry not redirecting to login page
- Fixed pagination resetting when filters change
- Fixed mobile menu not closing after navigation
### Breaking Changes
- `UserService.create()` now requires a `teamId` parameter
- Removed deprecated `GET /api/users/search` endpoint (use `GET /api/users?search=` instead)
Auto-Detection
The generator automatically detects and adapts to:
| Framework | Detection | Documentation Style |
|---|---|---|
| Express.js | app.get(), router.post() patterns | REST API reference |
| Next.js API | pages/api/ or app/api/ directories | API routes + pages |
| GraphQL | .graphql files, resolvers | Schema + query docs |
| React | .tsx components | Component props + usage |
| Prisma | schema.prisma | Data model reference |
| OpenAPI | openapi.yaml | Swagger-compatible docs |
Output Formats
| Format | Command | Use Case |
|---|---|---|
| Markdown | Default | GitHub wikis, repos |
| MDX | --format mdx | Docusaurus, Nextra |
| HTML | --format html | Static site hosting |
| OpenAPI | --format openapi | Swagger UI, Postman |
| JSDoc | Inline in code | IDE tooltips |
Configuration
// .claude/docs-config.json { "output": "docs/", "format": "markdown", "sections": ["api", "architecture", "setup", "components"], "include": ["src/**/*.ts", "src/**/*.tsx"], "exclude": ["src/**/*.test.ts", "src/**/*.stories.tsx"], "apiBaseUrl": "https://api.example.com", "projectName": "My App", "badges": ["build", "coverage", "license"] }
Keeping Docs Updated
Pre-commit Hook
Regenerate docs automatically when source files change:
// .claude/hooks.json { "hooks": { "pre-commit": { "command": "claude docs --changed-only", "description": "Update docs for changed files" } } }
CI Pipeline
# .github/workflows/docs.yml on: push: branches: [main] paths: ['src/**'] jobs: docs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: npm ci - run: npx claude docs --all - uses: peaceiris/actions-gh-pages@v3 with: publish_dir: docs/
Best Practices
- Document the why, not the what β Code shows what; docs explain why decisions were made
- Keep examples runnable β Every code example should work if copy-pasted
- Use consistent terminology β Define terms once and use them everywhere
- Include error examples β Show what happens when things go wrong
- Version your docs β Tag docs with the API version they describe
- Link between docs β Cross-reference related sections
- Start with a quick start β First section should get someone running in under 5 minutes
- Document edge cases β Cover the non-obvious behavior
- Add diagrams β Architecture flows, data models, sequence diagrams
- Review docs like code β Include docs in PR reviews
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
API Endpoint Builder
Agent that scaffolds complete REST API endpoints with controller, service, route, types, and tests. Supports Express, Fastify, and NestJS.
Ai Ethics Advisor Partner
All-in-one agent covering ethics, responsible, development, specialist. Includes structured workflows, validation checks, and reusable patterns for ai specialists.
Guide Hackathon Navigator
Streamline your workflow with this expert, hackathon, strategist, judge. Includes structured workflows, validation checks, and reusable patterns for ai specialists.