backend-conventions
Skill0 starsChanged 15 days agoMITView on GitHub
The house rules for Node.js Express backends — module layout, file and function naming, controller/service/route responsibilities, error throwing, response envelope, pagination shape, logging, config and lint style. Use whenever writing, editing or generating any Express/Node.js backend code (routes, controllers, services, validations, middleware), even for a one-line change.
- Reads credentials
7 other projects use a version of this.
Adopted by
Most recently taken up by
- getsentry/sentrytheir own version, first seen Nov 27, 2026
- jbouder/skillstheir own version, first seen Nov 1, 2026
- fpindej/netrocktheir own version, first seen Oct 8, 2026
- flntfnd/claude-skillstheir own version, first seen Aug 20, 2026
- ryokkon624/scrum-agent-basetheir own version, first seen Jul 9, 2026
- sefaertunc/anthropic-watchtheir own version, first seen Apr 30, 2026
Used with
Projects with it also use frontend-conventions.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
CloudflareSkillfrontend-conventions
Use for creating, modifying, moving, or reviewing React frontend code anywhere in packages/*, including Workshop pages, gatekeeper management apps, shared UI, components, hooks, forms, interactions, styling, accessibility, and frontend tests.
Also in 3 projects that use this
Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 7
- getsentry/sentry★ 46ksame name
- fpindej/netrock★ 234same name
- sefaertunc/Worclaude★ 4same name
- jbouder/skills★ 1same name
- sefaertunc/anthropic-watch★ 1same name
- flntfnd/claude-skills★ 0same name
- ryokkon624/scrum-agent-base★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- ai-integrationSkill
- api-docsSkill
- auth-sessionsSkill
- backend-reviewSkill
- create-backendSkill
- deploy-dockerSkill
- mongoose-mongodbSkill
- new-moduleSkill
- nextjs-api-routesSkill
- prisma-postgresSkill
- redis-cacheSkill
- scheduled-jobsSkill
- security-hardeningSkill
- session-logSkill
The file
We split this skill into the rules it gives an agent
9 rules. 0 are common, 4 are distinctive, and 5 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 86
Do not wrap in try/catch just to log and rethrow.
- Very specific: line 97
No body: omit data → null.
- Very specific: line 110
Only GET and POST. Never PUT, PATCH, DELETE.
- Very specific: line 112
Delete: POST /vendors/:vendorId/remove → sets isActive: false
- Distinctive: line 118
Always select fields explicitly.
- Very specific: line 120
No query inside a loop (N+1 is a bug): batch with $in / { in: [...] }.
- Distinctive: line 121
Every filtered or sorted field is covered by an index.
- Very specific: line 129
No comments of any kind — no inline, block, JSDoc, TODO, banners or commented-out code.
- Distinctive: line 130
No unrequested abstractions, libraries, config or "while I was here" refactors.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Backend Conventions
Apply these to every backend file you touch. A project's own CLAUDE.md overrides anything here; otherwise match the surrounding code first and these rules second.
Stack defaults
Node.js ≥ 22, ES Modules ("type": "module"), Express 5, Zod 4, winston. Database: Mongoose (MongoDB) or Prisma (PostgreSQL). Cache/sessions: Redis via ioredis.
Module layout
src/modules/<name>/
controllers/<name>.controller.js
services/<name>.service.js more services as <topic>.service.js when one file grows
routes/<name>.route.js
validations/<name>.schema.js omitted only when the module takes no input
index.js export { default as <name>Routes } from './routes/<name>.route.js';
prompt/<purpose>.prompt.js AI modules: system prompts and prompt builders
tools/<verb>-<noun>.tool.js AI modules: one tool per file, tools/index.js registry
evals/ AI modules: cases.js, score.js, run-evals.jsMongoose models live in src/models/<name>.model.js; Prisma models in prisma/schema.prisma. Domain enums live in src/shared/constant/<name>.js. Shared code lives in src/shared/ and is imported through src/shared/index.js. Modules are mounted in src/router/index.js under /v1.
Naming
| Thing | Pattern | Example |
| File | <name>.<type>.js | vendor.controller.js, vendor.model.js |
| Service | <verb><Resource>Service | getVendorsService, createVendorService |
| Controller | <verb><Resource> | getVendors, createVendor |
| Zod schema | <verb><Resource>Schema | createVendorSchema |
| Enum | E prefix, frozen object | EUserRole, EOrderStatus |
| Route export | <name>Routes | vendorRoutes |
| Redis key | <resource>:<scopeId>:<id> | vendor:store_1:abc |
Exports
- Services and controllers: declare
constfunctions, named exports at the bottom —export { a, b }; - Models: default export —
export default mongoose.models.Vendor || mongoose.model('Vendor', schema); - Zod schemas: inline —
export const createVendorSchema = z.object({ ... }); - Routes:
export default router;
Layer responsibilities
Route — wiring only. Fixed order:
authenticate → authorize(...roles) → validateRequest(schema, 'body'|'query'|'params') → controller
Controller — HTTP in, HTTP out. Read the request, call one service, shape the response, log. No database, no cache, no business rules.
const createVendor = asyncHandler(async (req, res) => {
try {
const vendor = await createVendorService(req.user.id, req.body);
logger.info('Vendor created', { userId: req.user.id, requestId: req.requestId });
return httpResponse(req, res, 201, responseMessage.custom('Vendor created'), { vendor });
} catch (error) {
logger.error('Create vendor failed', {
error: error.message,
stack: error.stack,
userId: req.user?.id,
requestId: req.requestId,
});
return httpError(req, res, error, error.statusCode || 500);
}
});Service — all business logic and data access. Plain async functions; never touch req/res. Scope ids come from req.user via the controller, never from the request body.
Errors
Expected failures are thrown from services as a plain Error with a status and a sentence a user can act on:
const error = new Error('Vendor not found');
error.statusCode = 404;
throw error;- Do not wrap in try/catch just to log and rethrow. Let unexpected errors bubble.
publicErrordecides what the client sees: 4xx messages pass through; unexpected 5xx become a generic message and the real one is logged.- Database codes map centrally: Prisma
P2002/Mongo11000→ 409,P2025→ 404,P2003→ 409,CastError→ 400. - Another tenant's record is 404, never 403.
Response envelope
httpResponse(req, res, status, message, data) → { success, statusCode, request, message, data }.
- List: pass the service result straight through →
data: { items, pagination }. - Single item: wrap in a named key →
data: { vendor }. (If the project's CLAUDE.md saysdatais the resource, follow that instead — pick one per project and never mix.) - No body: omit
data→null. - Never pass
{ data: ... }yourself.
Pagination
{ items, pagination: { total, page, limit, hasNextPage: ((page - 1) * limit) + items.length < total } }Count and fetch run in Promise.all. Query params: page default 1, limit default 20, max 100, coerced by Zod.
HTTP methods
Only GET and POST. Never PUT, PATCH, DELETE.
- Update:
POST /vendors/:vendorId - Delete:
POST /vendors/:vendorId/remove→ setsisActive: false - Actions:
POST /orders/:orderId/cancel
Data rules (both databases)
- Soft delete only:
isActive: false. Every read filtersisActive: true. - Always select fields explicitly. Never return a full row/document by default.
- Independent queries in
Promise.all. Neverawaitthem in sequence. - No query inside a loop (N+1 is a bug): batch with
$in/{ in: [...] }. - Every filtered or sorted field is covered by an index.
Config, logging, style
src/config/index.jsis the only file that readsprocess.env. Required vars are validated at boot.logger(winston) only; neverconsole.log. Every log carries{ requestId, userId, ...context }. Never log secrets, tokens, passwords or full bodies.- Single quotes, semicolons, 2-space indent, max 100 chars,
curly: all,eqeqeq. no-param-reassignis on: build new objects instead of mutating arguments.- No comments of any kind — no inline, block, JSDoc,
TODO, banners or commented-out code. Rename or extract a function instead. - No unrequested abstractions, libraries, config or "while I was here" refactors.
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.

