Fetch Plan
Plan the complete fetch layer for a new entity before writing any code. Outputs a structured plan of files to create with their function signatures and URL patterns.
Usage
/fetch-plan <entity> <section>
Examples:
/fetch-plan schedules setting
/fetch-plan campaigns management
/fetch-plan queue dialer
/fetch-plan agents report
Input
Gather before planning:
| Input |
Description |
Example |
| Entity name |
Singular, snake_case |
schedule, campaign_batch |
| Section |
Backend route group |
setting, management, dialer, report |
| Operations |
Which CRUD operations |
GET list, GET single, POST, PUT, DELETE, status toggle, bulk status |
Output Template
Generate this plan for the entity:
## Fetch Plan: {entity} ({section})
### Naming Conventions
- **Path**: {path-name} (kebab-case, e.g., campaign-batches)
- **Entity ID param**: {entityId} (camelCase, e.g., campaignBatchId)
- **Pascal name**: {EntityPascal} (e.g., CampaignBatch)
### 1. Server Actions — `lib/actions/{section}/{path-name}.actions.ts`
| Function | Method | URL | Returns |
|----------|--------|-----|---------|
| `get{Entities}(limit, skip, filters?)` | GET | `/backend/{section}/{path}?...` | `{Entity}Response` |
| `get{Entity}(id)` | GET | `/backend/{section}/{path}/{id}` | `{Entity}` |
| `create{Entity}(data)` | POST | `/backend/{section}/{path}` | `{Entity}` |
| `update{Entity}(id, data)` | PUT | `/backend/{section}/{path}/{id}` | `{Entity}` |
| `delete{Entity}(id)` | DELETE | `/backend/{section}/{path}/{id}` | `void` |
### 2. API Routes
| File | Methods | Backend endpoint |
|------|---------|-----------------|
| `app/api/{section}/{path}/route.ts` | GET, POST | `/{section}/{path}` |
| `app/api/{section}/{path}/[{entityId}]/route.ts` | GET, PUT, DELETE | `/{section}/{path}/{id}` |
| `app/api/{section}/{path}/[{entityId}]/status/route.ts` | PUT | `/{section}/{path}/{id}/status` |
| `app/api/{section}/{path}/status/route.ts` | PUT | `/{section}/{path}/status` |
**Pattern reminders:**
- GET handlers: `(token) => backendFetch(...)`
- Mutation handlers: `(token, headers) => backendFetch(..., { headers })`
- Import: `backendFetch` from `@/lib/fetch/backend`
### 3. Client Calls (from table component)
| Action | Call | Returns |
|--------|------|---------|
| Refresh | `api.get<{Entity}Response>('/api/{section}/{path}?...')` | `{Entity}Response` |
| Create | `api.post<{Entity}>('/api/{section}/{path}', data)` | `{Entity}` |
| Update | `api.put<{Entity}>('/api/{section}/{path}/{id}', data)` | `{Entity}` |
| Toggle status | `api.put<{Entity}>('/api/{section}/{path}/{id}/status', { is_active })` | `{Entity}` |
| Delete | `api.delete('/api/{section}/{path}/{id}')` | `void` |
| Bulk status | `api.put('/api/{section}/{path}/status', { ids, is_active })` | `{Entity}[]` |
### 4. Page Component — `app/(pages)/{section}/{path}/page.tsx`
- SSR fetch via `get{Entities}()` server action
- Pass `initialData` to client table component
- No `auth()` check needed (layout handles it)
- Use `Promise.all()` if multiple data sources needed
### 5. Dependencies Check
Before implementing, verify these exist:
- [ ] Backend endpoint: `/{section}/{path}` responds
- [ ] TypeScript types: `lib/types/api/{path-name}.ts` has `{Entity}`, `{Entity}Create`, `{Entity}Response`
- [ ] Backend schemas use `CamelModel` (camelCase in API responses)
Rules
- Always plan before implementing — don't skip to code
- Server actions use
/backend/ URLs — never /api/
- API routes use
backendFetch directly — no helper wrappers
- Mutations forward CSRF —
(token, headers) pattern
- Client uses
api object — returns T directly
- One server action file per entity — group all CRUD in one file
- Standard route structure — collection, resource, status, bulk status
1---2name: fetch-plan3description: Plan fetch layers for a new entity — determines which server actions, API routes, and client calls to create before implementation.4---56# Fetch Plan78Plan the complete fetch layer for a new entity before writing any code. Outputs a structured plan of files to create with their function signatures and URL patterns.910## Usage1112```13/fetch-plan <entity> <section>14```1516**Examples:**17```18/fetch-plan schedules setting19/fetch-plan campaigns management20/fetch-plan queue dialer21/fetch-plan agents report22```2324## Input2526Gather before planning:2728| Input | Description | Example |29|-------|-------------|---------|30| Entity name | Singular, snake_case | `schedule`, `campaign_batch` |31| Section | Backend route group | `setting`, `management`, `dialer`, `report` |32| Operations | Which CRUD operations | GET list, GET single, POST, PUT, DELETE, status toggle, bulk status |3334## Output Template3536Generate this plan for the entity:3738```markdown39## Fetch Plan: {entity} ({section})4041### Naming Conventions42- **Path**: {path-name} (kebab-case, e.g., campaign-batches)43- **Entity ID param**: {entityId} (camelCase, e.g., campaignBatchId)44- **Pascal name**: {EntityPascal} (e.g., CampaignBatch)4546### 1. Server Actions — `lib/actions/{section}/{path-name}.actions.ts`4748| Function | Method | URL | Returns |49|----------|--------|-----|---------|50| `get{Entities}(limit, skip, filters?)` | GET | `/backend/{section}/{path}?...` | `{Entity}Response` |51| `get{Entity}(id)` | GET | `/backend/{section}/{path}/{id}` | `{Entity}` |52| `create{Entity}(data)` | POST | `/backend/{section}/{path}` | `{Entity}` |53| `update{Entity}(id, data)` | PUT | `/backend/{section}/{path}/{id}` | `{Entity}` |54| `delete{Entity}(id)` | DELETE | `/backend/{section}/{path}/{id}` | `void` |5556### 2. API Routes5758| File | Methods | Backend endpoint |59|------|---------|-----------------|60| `app/api/{section}/{path}/route.ts` | GET, POST | `/{section}/{path}` |61| `app/api/{section}/{path}/[{entityId}]/route.ts` | GET, PUT, DELETE | `/{section}/{path}/{id}` |62| `app/api/{section}/{path}/[{entityId}]/status/route.ts` | PUT | `/{section}/{path}/{id}/status` |63| `app/api/{section}/{path}/status/route.ts` | PUT | `/{section}/{path}/status` |6465**Pattern reminders:**66- GET handlers: `(token) => backendFetch(...)`67- Mutation handlers: `(token, headers) => backendFetch(..., { headers })`68- Import: `backendFetch` from `@/lib/fetch/backend`6970### 3. Client Calls (from table component)7172| Action | Call | Returns |73|--------|------|---------|74| Refresh | `api.get<{Entity}Response>('/api/{section}/{path}?...')` | `{Entity}Response` |75| Create | `api.post<{Entity}>('/api/{section}/{path}', data)` | `{Entity}` |76| Update | `api.put<{Entity}>('/api/{section}/{path}/{id}', data)` | `{Entity}` |77| Toggle status | `api.put<{Entity}>('/api/{section}/{path}/{id}/status', { is_active })` | `{Entity}` |78| Delete | `api.delete('/api/{section}/{path}/{id}')` | `void` |79| Bulk status | `api.put('/api/{section}/{path}/status', { ids, is_active })` | `{Entity}[]` |8081### 4. Page Component — `app/(pages)/{section}/{path}/page.tsx`8283- SSR fetch via `get{Entities}()` server action84- Pass `initialData` to client table component85- No `auth()` check needed (layout handles it)86- Use `Promise.all()` if multiple data sources needed8788### 5. Dependencies Check8990Before implementing, verify these exist:91- [ ] Backend endpoint: `/{section}/{path}` responds92- [ ] TypeScript types: `lib/types/api/{path-name}.ts` has `{Entity}`, `{Entity}Create`, `{Entity}Response`93- [ ] Backend schemas use `CamelModel` (camelCase in API responses)94```9596## Rules97981. **Always plan before implementing** — don't skip to code992. **Server actions use `/backend/` URLs** — never `/api/`1003. **API routes use `backendFetch` directly** — no helper wrappers1014. **Mutations forward CSRF** — `(token, headers)` pattern1025. **Client uses `api` object** — returns `T` directly1036. **One server action file per entity** — group all CRUD in one file1047. **Standard route structure** — collection, resource, status, bulk status