agentleFS
jhonatan-oliveiradevjhonatan-oliveiradev/agent-skills/skills/building-reliable-node-api-boundaries/SKILL.md

building-reliable-node-api-boundaries

Skill1 starsChanged 3 months agoMITView on GitHub

Use when implementing or reviewing Node.js API or service endpoints that cross trust or data boundaries and require explicit validation, authorization, failure semantics, observability, or retry behavior.

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Treat every API boundary as a trust boundary.

    line 9
  2. Distinctive:

    Keep one clear business operation per boundary.

    line 15
  3. Very specific:

    Add request correlation and structured diagnostics.

    line 18
  4. Distinctive:

    Put timeouts, cancellation, pagination, and resource ceilings around downstream or potentially expensive work.

    line 19
  5. Distinctive:

    Do not rely on a client to hide forbidden identifiers or fields.

    line 26

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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

Building Reliable Node API Boundaries

Core principle

Treat every API boundary as a trust boundary. Make authentication, authorization, validation, mutation scope, and failure behavior explicit before optimizing handler structure or framework ergonomics.

Request path

  1. Parse the request into a bounded shape. Reject malformed or oversized input before business work begins.
  2. Authenticate the caller, then authorize the requested object and properties. Never infer object-level authorization only from a valid session.
  3. Validate domain input separately from transport parsing. Reject fields the caller is not allowed to set instead of mass-assigning request bodies.
  4. Keep one clear business operation per boundary. Put atomic database mutations inside an intentional transaction boundary.
  5. For externally retryable writes, define idempotency or conflict semantics before shipping the endpoint.
  6. Map internal failures to stable public error responses without leaking implementation details.
  7. Add request correlation and structured diagnostics. Use framework context when adequate; otherwise Node.js AsyncLocalStorage can carry request-scoped context across asynchronous work.
  8. Put timeouts, cancellation, pagination, and resource ceilings around downstream or potentially expensive work.

Authorization checks

Cover both:

  • object-level access: may this caller act on this specific record?
  • property/function-level access: may this caller read or mutate these fields or operations?

Do not rely on a client to hide forbidden identifiers or fields.

Verification

Exercise at minimum:

  • a valid request;
  • malformed and oversized input;
  • valid identity with unauthorized object access;
  • partial/property-level permission failure;
  • repeated write or replay behavior where relevant;
  • downstream timeout/failure;
  • transaction rollback after a mid-operation error.

Logs should carry correlation and outcome context without storing secrets or unnecessary personal data.

References

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.