D

Documentation Auto-Generator

Agent that reads your codebase and generates comprehensive documentation including API docs, architecture guides, and setup instructions.

AgentClipticsdocumentationv1.0.0MIT
0 views0 copies

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

StatusDescription
400Validation failed (invalid email, missing required fields)
401Missing or invalid authentication token
403Insufficient permissions (admin required)
409Email 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
  1. Install dependencies

    npm install
  2. Set up environment variables

    cp .env.example .env # Edit .env with your local settings
  3. 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
  4. Run database migrations

    npm run db:migrate npm run db:seed # Optional: seed with test data
  5. Start the development server

    npm run dev # API available at http://localhost:3001 # Frontend at http://localhost:3000

Environment Variables

VariableRequiredDefaultDescription
DATABASE_URLYesβ€”PostgreSQL connection string
REDIS_URLYesredis://localhost:6379Redis connection string
JWT_SECRETYesβ€”Secret for signing JWT tokens
PORTNo3001API server port
NODE_ENVNodevelopmentEnvironment mode
STRIPE_SECRET_KEYNoβ€”Stripe API key (for payments)
SMTP_HOSTNoβ€”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

IssueSolution
Port 3001 already in uselsof -i :3001 to find process, then kill -9 <PID>
Database connection refusedCheck PostgreSQL is running: pg_isready
Migration failedRun npm run db:status to check migration state
Node version mismatchRun 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

PropTypeDefaultDescription
dataT[]requiredArray of data objects
columnsColumn<T>[]requiredColumn definitions
pageSizenumber20Rows per page
sortablebooleantrueEnable column sorting
selectablebooleanfalseEnable row selection
onSelectionChange(rows: T[]) => voidβ€”Callback on selection change
onRowClick(row: T) => voidβ€”Callback on row click
loadingbooleanfalseShow loading skeleton
emptyMessagestring'No data'Message when data is empty
exportablebooleanfalseShow 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:

FrameworkDetectionDocumentation Style
Express.jsapp.get(), router.post() patternsREST API reference
Next.js APIpages/api/ or app/api/ directoriesAPI routes + pages
GraphQL.graphql files, resolversSchema + query docs
React.tsx componentsComponent props + usage
Prismaschema.prismaData model reference
OpenAPIopenapi.yamlSwagger-compatible docs

Output Formats

FormatCommandUse Case
MarkdownDefaultGitHub wikis, repos
MDX--format mdxDocusaurus, Nextra
HTML--format htmlStatic site hosting
OpenAPI--format openapiSwagger UI, Postman
JSDocInline in codeIDE 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

  1. Document the why, not the what β€” Code shows what; docs explain why decisions were made
  2. Keep examples runnable β€” Every code example should work if copy-pasted
  3. Use consistent terminology β€” Define terms once and use them everywhere
  4. Include error examples β€” Show what happens when things go wrong
  5. Version your docs β€” Tag docs with the API version they describe
  6. Link between docs β€” Cross-reference related sections
  7. Start with a quick start β€” First section should get someone running in under 5 minutes
  8. Document edge cases β€” Cover the non-obvious behavior
  9. Add diagrams β€” Architecture flows, data models, sequence diagrams
  10. Review docs like code β€” Include docs in PR reviews
Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates