---
name: crud-generator
description: Generate generic CRUD (list/create/update/delete) with table + form for an entity. Use for standard admin screens.
---

# Skill: CRUD Generator

## When to use

A standard entity needing the 5 CRUD operations + admin screens. Driven by `/create-crud`.

## Steps

1. Schema (per `feature-vertical-slice`).
2. **5 endpoints:** `GET /<plural>` (paged), `GET /<plural>/{id}`, `POST /<plural>`, `PUT /<plural>/{id}`, `DELETE /<plural>/{id}` (soft delete).
3. **List page:** `DataTableComponent` with columns + keyset pagination for large tables; OFFSET for small.
4. **Form:** Reactive Form, shared create/edit, client + server validation.
5. **Permissions:** `<entity>.read` (list/detail), `.write` (create/update), `.delete`.
6. **Audit:** emit on create/update/delete via `AuditDispatcher`.

## Gotchas

- DELETE sets `deletedAt`, never removes the row. The default Prisma query filter excludes soft-deleted rows.
- List endpoints return `PagedResponse<T>` (`{ success, message, data, page, pageSize, total }`).
- Keyset pagination beats OFFSET past ~10k rows — use `WHERE id > @cursor ORDER BY id LIMIT n`.
- The form's `markAllAsTouched()` (from `form.util.ts`) surfaces validation on submit.

## Validation

All 5 endpoints authorized + tested; list paginates; soft delete verified; `pnpm validate` green.
