node-express-boilerplate / rules
Cursor rule36 starsChanged 4 months agoMITView on GitHub
Coding conventions, patterns, and hard rules for every file in this repo
- Reads credentials
We split this conventions.mdc into the rules it gives an agent
8 rules. About 0 are common, 0 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
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
- Very specific: line 9
Environment variables: Never use process.env directly anywhere.
- Very specific: line 13
Logging: Use the Pino logger from src/config/logger.ts.
- Very specific: line 22
All type-only imports must use import type
- Very specific: line 24
No floating promises — always await or .catch()
- Very specific: line 25
Prefer ?? over || for nullish checks
- Very specific: line 49
Use this.prisma.<model> for all queries
- Very specific: line 51
Use this.findManyWithPagination() and this.count() from the base class for list/count operations
- Very specific: line 74
All mutating routes require a CSRF token (double-submit cookie pattern via doubleCsrfProtection)
≈ “Common” is an estimate: at least 1 in 5 of the 6,350 Cursor rule 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
---
description: Coding conventions, patterns, and hard rules for every file in this repo
globs: ["src/**/*.ts"]
alwaysApply: true
---
# Hard Rules
**Environment variables:** Never use `process.env` directly anywhere. Import the typed config object from `src/config/env.ts`.
**Error handling:** Throw from `src/errors/index.ts`. In controllers, always catch and call `this.handleError(error, next)` — never `res.status().json()` on error paths. Available classes: `AppError`, `ValidationError`, `AuthenticationError`, `AuthorizationError`, `NotFoundError`, `ConflictError`, `InternalServerError`.
**Logging:** Use the Pino logger from `src/config/logger.ts`. Never use `console.log/warn/error`.
**Validation:** Zod v4 schemas in `src/validations/`. Use `validateBody(schema)` from `src/lib/validate.ts` to produce middleware. Export both the schema type and the `RequestHandler` from the validation file.
**Package manager:** pnpm only. Never generate `package-lock.json` or `yarn.lock`.
# TypeScript
- Strict mode — no `any`, no `@ts-ignore`
- All type-only imports must use `import type`
- Explicit return types on all public methods and class properties
- No floating promises — always `await` or `.catch()`
- Prefer `??` over `||` for nullish checks
# Formatting (Prettier)
4-space indent · single quotes · semicolons · trailing commas · 100-char line limit
# Controller Pattern
Controller methods are arrow function *properties* (not regular methods) so `this` is bound correctly when passed as route handlers:
```ts
public createFoo = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
try {
// ...
this.sendResponse(res, 201, 'Foo created', data);
} catch (error) {
this.handleError(error, next);
}
};
```
# Repository Pattern
- Extend `BaseRepository`
- Use `this.prisma.<model>` for all queries
- In `update`/`delete`, wrap Prisma calls in try/catch and call `this.handlePrismaError(error)`
- Use `this.findManyWithPagination()` and `this.count()` from the base class for list/count operations
# Route Pattern
```ts
export class FooRoute extends BaseRoute {
private fooController!: IFooController;
protected initializeRoutes(): void {
this.fooController = this.container.getFooController();
this.router.post('/', fooLimiter, protect, createFooValidation, this.fooController.createFoo);
// ...
}
}
const fooRoute = new FooRoute();
const fooRoutes = fooRoute.getRouter();
export default fooRoutes;
```
# Authentication & Security
- Protected routes: apply `protect` middleware (JWT from HttpOnly cookie)
- All mutating routes require a CSRF token (double-submit cookie pattern via `doubleCsrfProtection`)
- Rate-limit every route group with its own limiter from `src/middleware/limiter.middleware.ts`
- Passwords hashed with bcrypt; never log or return password fields
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 3,978 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository18 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .cursor/rules/architecture.mdcCursor rule
- add-middlewareSkill
- add-openapi-docsSkill
- add-testSkill
- api-design-principlesSkill
- find-skillsSkill
- improveSkill
- multi-stage-dockerfileSkill
- new-resourceSkill
- 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.
Reviews can't be read right now.
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.

