agentleFS
KhaledSaeed18KhaledSaeed18/node-express-boilerplate/.cursor/rules/conventions.mdc

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
  1. Very specific:

    Environment variables: Never use process.env directly anywhere.

    line 9
  2. Very specific:

    Logging: Use the Pino logger from src/config/logger.ts.

    line 13
  3. Very specific:

    All type-only imports must use import type

    line 22
  4. Very specific:

    No floating promises — always await or .catch()

    line 24
  5. Very specific:

    Prefer ?? over || for nullish checks

    line 25
  6. Very specific:

    Use this.prisma.<model> for all queries

    line 49
  7. Very specific:

    Use this.findManyWithPagination() and this.count() from the base class for list/count operations

    line 51
  8. Very specific:

    All mutating routes require a CSRF token (double-submit cookie pattern via doubleCsrfProtection)

    line 74

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
conventions.mdc
---
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

Download now (ZIP)

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.