# /docs — Documentation Generation

Generate and update project documentation for mawidi-site.

## Usage

```
/docs update                           # Update CLAUDE.md from codebase
/docs api                              # Generate API documentation
/docs components                       # Generate component docs
/docs schema                           # Generate database schema docs
/docs readme                           # Update README.md
/docs changelog                        # Generate changelog from git history
/docs all                              # Generate all documentation
```

**Examples:**
- `/docs api`
- `/docs schema`
- `/docs changelog`

## Workflow

### Update CLAUDE.md
1. Scan the codebase for:
   - New API routes (app/api/**/route.ts)
   - New components
   - New Prisma models
   - New services (lib/services/)
   - New environment variables
2. Update the relevant sections of CLAUDE.md
3. Keep existing custom sections intact
4. Commit the update

### API Documentation
1. Scan all `app/api/**/route.ts` files
2. For each route, extract:
   - HTTP methods (GET, POST, PUT, DELETE)
   - Path pattern
   - Request body schema (from Zod validators)
   - Response format
   - Auth requirements
   - Rate limiting config
3. Generate a structured API reference:
   ```markdown
   ## API Reference

   ### Authentication
   | Method | Endpoint | Auth | Description |
   |--------|----------|------|-------------|
   | POST | /api/auth/login | No | Login with email/password |
   ...

   ### Billing
   | Method | Endpoint | Auth | Description |
   |--------|----------|------|-------------|
   | GET | /api/billing/current | Yes | Get current subscription |
   ...
   ```
4. Write to `docs/API.md`

### Component Documentation
1. Scan component directories:
   - `app/[lang]/dashboard/components/`
   - `components/`
   - `components/dashboard/`
   - `components/staff/`
2. For each component, extract:
   - Name and file path
   - Props interface
   - Description (from comments or inference)
   - Dependencies
3. Generate component catalog
4. Write to `docs/COMPONENTS.md`

### Schema Documentation
1. Read `prisma/schema.prisma`
2. Parse all models and their:
   - Fields and types
   - Relations
   - Indexes
   - Enums
3. Generate an ERD-style document:
   ```markdown
   ## Database Schema

   ### User
   | Field | Type | Description |
   |-------|------|-------------|
   | id | String (UUID) | Primary key |
   | email | String | Unique email |
   ...

   Relations: Organization (many-to-one), Appointments (one-to-many)
   ```
4. Write to `docs/SCHEMA.md`

### Changelog
1. Parse git log:
   ```bash
   git log --oneline --since="1 month ago"
   ```
2. Group by conventional commit type:
   - Features (feat:)
   - Bug Fixes (fix:)
   - Refactors (refactor:)
   - Other
3. Generate formatted changelog
4. Write to `CHANGELOG.md`

### README Update
1. Read existing README.md
2. Update sections:
   - Tech stack
   - Setup instructions
   - Environment variables
   - Available scripts
3. Keep custom sections intact

## Key Rules
- NEVER overwrite custom/manual documentation sections
- Always scan the actual codebase — don't guess
- Use consistent markdown formatting
- Include file paths for cross-reference
- Commit documentation changes after generating
