| name | add-backend-endpoint |
| description | Scaffold a new NestJS endpoint/module/route in the backend following this project's conventions (module + controller + service + dto + constants, auth/roles, pagination, prisma, tests). Use when adding or extending a backend API. |
Add a backend endpoint
Read backend/CLAUDE.md first. Match the existing module shape (look at
src/subscription/ or src/notifications/ as references).
Steps
- Locate / create the module under
src/<feature>/:
<feature>.module.ts, <feature>.controller.ts, <feature>.service.ts,
dto/*.dto.ts, constants/<feature>.constants.ts.
- DTOs (
class-validator + @nestjs/swagger): validate every field; add
@MaxLength matching DB VarChar, bounds on numbers, @IsInt for integer
columns. Extend PaginationDto for list queries.
- Controller:
@ApiTags + @ApiBearerAuth('JWT'). Auth is global; use
@Public() to opt out, @Roles(UserRole.ADMIN) to gate admins,
@CurrentUser('id') for the user id. Use ParsePositiveIntPipe on :id.
Webhooks → @Public() + @SkipThrottle().
- Service: inject
PrismaService. Use $transaction for multi-write
invariants. Throw { code, message } from constants (HttpExceptions).
Return DTOs / projected select (never leak tokens/secrets).
- Wire the module into
src/app.module.ts imports.
- Prisma changes (if any): edit
schema.prisma, then create an incremental
migration with bun run prisma:migrate (= migrate dev --name ..., which also
regenerates the client) — see the prisma-migration skill. Seed defaults in
prisma/seed*.ts if needed.
- Test: add
<thing>.spec.ts for service/guard/pipe logic (mock Prisma as a
plain object; new Service(mockPrisma as never)).
- Verify (from
backend/): bunx tsc -p tsconfig.build.json --noEmit,
bun run build, bun run lint, bun run test.