# /docs:generate - Auto-Generate Documentation

**Agents:** `smart-contract`, `frontend`

Automatically generate documentation from code for the Movement dApp.

**IMPORTANT**: Delegate to `smart-contract` agent for contract docs, `frontend` agent for frontend docs.

## Workflow

### Step 1: Analyze Codebase
Scan the project to identify:
- Move modules and their public interfaces
- Frontend components and hooks

### Step 2: Generate Contract Documentation

For each Move module in `contracts/sources/`:

1. Extract module name and address
2. Parse resource definitions
3. Parse entry functions with parameters
4. Parse view functions with return types
5. Parse events
6. Extract error codes

Generate `docs/contracts/{module_name}.md`:
```markdown
# {Module Name}

**Address:** `{module_address}::{module_name}`

## Overview
{Auto-generated description based on module structure}

## Resources

### {ResourceName}
\`\`\`move
struct ResourceName has key, store {
    field1: u64,
    field2: String,
}
\`\`\`

## Entry Functions

### `function_name`
\`\`\`move
public entry fun function_name(account: &signer, param1: u64)
\`\`\`
**Parameters:**
- `account`: Signer account
- `param1`: {Description}

**Effects:**
- {State changes}
- Emits `EventName`

## View Functions

### `get_value`
\`\`\`move
#[view]
public fun get_value(addr: address): u64
\`\`\`
**Parameters:**
- `addr`: Account address to query

**Returns:** `u64` - The current value

## Events

### `EventName`
\`\`\`move
#[event]
struct EventName has drop, store {
    field1: u64,
    timestamp: u64,
}
\`\`\`
Emitted when: {condition}

## Error Codes
| Code | Constant | Description |
|------|----------|-------------|
| 1 | E_NOT_AUTHORIZED | Caller is not authorized |
| 2 | E_ALREADY_EXISTS | Resource already exists |
```

### Step 3: Generate Component Documentation

For each component in `frontend/src/components/`:

Generate `docs/frontend/components.md`:
```markdown
# Frontend Components

## WalletConnect
Handles wallet connection and disconnection.

**Props:** None

**Usage:**
\`\`\`tsx
<WalletConnect />
\`\`\`
```

## Output Summary
```markdown
# 📖 Documentation Generated

## Contract Docs
- {n} module documentation files

## Frontend Docs
- {n} component documentation files

## Next Steps
- Review generated documentation
- Add custom descriptions where needed
- Keep docs updated as code changes
```

