new-resource
Skill36 starsChanged 4 months agoMITView on GitHub
Scaffold a complete new API resource (validation → repository → service → controller → route → container → app mount → OpenAPI → tests). Use when the user asks to add a new resource, entity, model, or endpoint group to the API.
We split this skill into the rules it gives an agent
17 rules. About 0 are common, 9 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 6
When the user asks to add a new resource (e.g.
- Distinctive: line 18
Add the new model first so TypeScript types are available for every subsequent step.
- Distinctive: line 22
All fields with appropriate types and nullability
- Very specific: line 52
Create Zod v4 schemas. Pattern from src/validations/note.validation.ts:
- Very specific: line 74
Use this.prisma.<model> for all queries.
- Very specific: line 76
Use this.findManyWithPagination() and this.count() for paginated list operations.
- Distinctive: line 90
Never return password, token, or internal fields.
- Distinctive: line 100
All methods are arrow function properties — never regular methods.
- Very specific: line 101
Every method is wrapped in try/catch using this.handleError(error, next).
- Very specific: line 102
Use this.sendResponse() for single items and this.sendPaginatedResponse() for lists.
- Very specific: line 103
Never call res.status().json() directly on error paths.
- Very specific: line 146
Add the getter signature to the IContainer interface.
- Distinctive: line 161
Add or update the OpenAPI spec for the new resource:
- Distinctive: line 164
Document all endpoints with path, method, summary, request, and response examples
- Distinctive: line 173
Test every service method: happy path, not-found, conflict, authorization failure
- Very specific: line 176
Use supertest against the real app
- Distinctive: line 177
Test full HTTP cycle: correct status codes, response shape, auth enforcement, CSRF enforcement, validation rejection
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When the user asks to add a new resource (e.g. "add a comments resource"), follow this exact sequence. Ask for the resource name if not provided.
Variables
<Name>= PascalCase singular (e.g.Comment)<name>= camelCase singular (e.g.comment)<names>= camelCase plural (e.g.comments)
Step 1 — Prisma Schema (prisma/schema.prisma)
Add the new model first so TypeScript types are available for every subsequent step.
Requirements:
id String @id @default(cuid())- All fields with appropriate types and nullability
- Foreign key relations with
onDelete: Cascadeon the child side createdAt DateTime @default(now())andupdatedAt DateTime @updatedAt@@indexon every foreign key column and commonly filtered fields@@map("snake_case_table_name")
Then immediately run:
pnpm prisma:migrate
pnpm prisma:generateStep 2 — Types (src/types/<name>.types.ts)
Define DTOs before writing any other layer:
export interface Create<Name>DTO { /* fields */ }
export interface Update<Name>DTO { /* partial fields */ }
export interface <Name>ResponseDTO { /* safe fields to return, no password etc. */ }Export from src/types/index.ts.
Step 3 — Validation (src/validations/<name>.validation.ts)
Create Zod v4 schemas. Pattern from src/validations/note.validation.ts:
import { z } from 'zod';
import { validateBody } from '../lib/validate';
import type { RequestHandler } from 'express';
export const create<Name>Schema = z.object({ /* fields */ });
export type Create<Name>Input = z.infer<typeof create<Name>Schema>;
export const create<Name>Validation: RequestHandler = validateBody(create<Name>Schema);
export const update<Name>Schema = z.object({ /* fields, all optional for PATCH */ });
export type Update<Name>Input = z.infer<typeof update<Name>Schema>;
export const update<Name>Validation: RequestHandler = validateBody(update<Name>Schema);Step 4 — Repository (src/repository/<name>.repository.ts)
- Define
I<Name>Repositoryinterface with all method signatures. - Implement
<Name>Repository extends BaseRepository. - Use
this.prisma.<model>for all queries. - Wrap
updateanddeletein try/catch callingthis.handlePrismaError(error). - Use
this.findManyWithPagination()andthis.count()for paginated list operations.
Pattern: copy src/repository/note.repository.ts and adapt.
Export from src/repository/index.ts.
Step 5 — Service (src/services/<name>.service.ts)
- Define
I<Name>Serviceinterface. - Implement
<Name>Service— injectI<Name>Repositoryvia constructor. - Throw from
src/errors/only — never return raw Prisma errors. - Map entities to
<Name>ResponseDTOvia a privatetoResponseDTO()method. - Never return password, token, or internal fields.
Export from src/services/index.ts.
Step 6 — Controller (src/controllers/<name>.controller.ts)
- Define
I<Name>Controllerinterface. - Implement
<Name>Controller extends BaseController. - All methods are arrow function properties — never regular methods.
- Every method is wrapped in try/catch using
this.handleError(error, next). - Use
this.sendResponse()for single items andthis.sendPaginatedResponse()for lists. - Never call
res.status().json()directly on error paths.
Export from src/controllers/index.ts.
Step 7 — Route (src/routes/<name>.route.ts)
- Extend
BaseRoute, implementinitializeRoutes(). - Apply a dedicated rate limiter to the entire route group.
- Apply
protectto every authenticated endpoint. - Apply
doubleCsrfProtection(imported fromsrc/app.tsor middleware) to all mutating routes. - Apply validation middleware to every POST / PUT / PATCH route.
Pattern: copy src/routes/note.route.ts and adapt.
Export from src/routes/index.ts if a barrel exists.
Step 8 — Container (src/container/index.ts)
Add in order:
// Private fields
private <name>Repository!: I<Name>Repository;
private <name>Service!: I<Name>Service;
private <name>Controller!: I<Name>Controller;
// initializeRepositories()
this.<name>Repository = new <Name>Repository(this.prisma);
// initializeServices()
this.<name>Service = new <Name>Service(this.<name>Repository);
// initializeControllers()
this.<name>Controller = new <Name>Controller(this.<name>Service);
// Public getter
get<Name>Controller(): I<Name>Controller { return this.<name>Controller; }Add the getter signature to the IContainer interface.
Step 9 — App (src/app.ts)
import <name>Routes from './routes/<name>.route';
app.use(`${config.BASE_URL}/${config.API_VERSION}/<names>`, <name>Routes);Step 10 — OpenAPI (src/docs/)
Add or update the OpenAPI spec for the new resource:
- Define request body schemas
- Define response schemas
- Document all endpoints with path, method, summary, request, and response examples
- Reference the
<Name>schema in the paths object
Step 11 — Tests
Unit test (tests/unit/services/<name>.service.test.ts):
- Mock
I<Name>Repositoryusingvi.fn() - Test every service method: happy path, not-found, conflict, authorization failure
Integration test (tests/integration/<names>.test.ts):
- Use
supertestagainst the real app - Test full HTTP cycle: correct status codes, response shape, auth enforcement, CSRF enforcement, validation rejection
Step 12 — Verification
pnpm full-check # format + lint + type-check
pnpm test # unit tests
pnpm test:integration # integration tests (if db:test:up is running)Fix every error before reporting the task as done.
In this repository18 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .cursor/rules/architecture.mdcCursor rule
- .cursor/rules/conventions.mdcCursor rule
- add-middlewareSkill
- add-openapi-docsSkill
- add-testSkill
- api-design-principlesSkill
- find-skillsSkill
- improveSkill
- multi-stage-dockerfileSkill
- nodejs-best-practicesSkill
- prisma-client-apiSkill
- prisma-database-setupSkill
- prisma-postgresSkill
- security-auditSkill
- typescript-magicianSkill
- update-schemaSkill
- vitestSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

