agentleFS
KhaledSaeed18KhaledSaeed18/node-express-boilerplate/.agents/skills/add-middleware/SKILL.md

add-middleware

Skill36 starsChanged 4 months agoMITView on GitHub

Add a new Express middleware to this project and wire it up correctly. Use when the user asks to add middleware — rate limiting, request guards, validation, logging enrichment, custom auth checks, etc.

  • Reads credentials

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When the user asks to add middleware, follow these steps.

    line 6
  2. Very specific:

    Use the Pino logger from src/config/logger.ts if logging is needed — never console.*.

    line 13
  3. Very specific:

    Use config values from src/config/env.ts — never process.env directly.

    line 14
  4. Very specific:

    No floating promises — always await or .catch().

    line 16

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

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

When the user asks to add middleware, follow these steps.

Step 1 — Create the file (src/middleware/<name>.middleware.ts)

Rules:

  • Export named functions, not default exports — consistent with the barrel pattern.
  • Type req, res, next as Request, Response, NextFunction from express. No any.
  • Use the Pino logger from src/config/logger.ts if logging is needed — never console.*.
  • Use config values from src/config/env.ts — never process.env directly.
  • Throw from src/errors/ for error conditions and call next(error) — never res.status().json() directly.
  • No floating promises — always await or .catch().

Auth guard pattern:

import type { Request, Response, NextFunction } from 'express';
import { AuthenticationError } from '../errors';

export const requireAdmin = (req: Request, _res: Response, next: NextFunction): void => {
    if (!req.user || req.user.role !== 'admin') {
        return next(new AuthenticationError('Admin access required'));
    }
    next();
};

Async middleware pattern:

import type { Request, Response, NextFunction } from 'express';
import { NotFoundError } from '../errors';
import logger from '../config/logger';

export const someAsyncGuard = async (req: Request, _res: Response, next: NextFunction): Promise<void> => {
    try {
        // async work
        next();
    } catch (error) {
        logger.error(error, 'someAsyncGuard failed');
        next(error);
    }
};

Rate limiter pattern (if adding a new limiter):

import rateLimit from 'express-rate-limit';

export const myLimiter = rateLimit({
    windowMs: 15 * 60 * 1000,
    max: 100,
    standardHeaders: true,
    legacyHeaders: false,
    message: { success: false, message: 'Too many requests' },
});

Step 2 — Export from the barrel (src/middleware/index.ts)

export { myMiddleware } from './<name>.middleware';

Step 3 — Apply it

App-wide (applies to every request) — add to src/app.ts in the correct position in the middleware chain. Order matters:

correlation → httpLogger → helmet → cors → json → cookie-parser → CSRF → [your middleware] → routes

Route-group-wide — add to the route constructor in src/routes/<name>.route.ts:

protected initializeRoutes(): void {
    this.router.use(myMiddleware);
    // then individual route definitions
}

Per-endpoint — add inline in the route definition:

this.router.post('/', limiter, protect, myMiddleware, createValidation, this.controller.createItem);

Step 4 — Verify

pnpm full-check

Fix every TypeScript and lint error before reporting done.

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.

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.