backend-implementation-patterns

Implements REST API endpoints, JWT authentication, validation, and error handling for Node.js backends.

Updated May 16, 2026
One-click install
npx skills add https://github.com/organvm-i-theoria/_agent-ontology --skill backend-implementation-patterns-organvm-i-theoria
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: backend-implementation-patterns
Source: https://github.com/organvm-i-theoria/_agent-ontology/tree/main/.agents/skills/backend-implementation-patterns
Command: npx skills add https://github.com/organvm-i-theoria/_agent-ontology --skill backend-implementation-patterns-organvm-i-theoria

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building backend APIs from scratch involves repetitive decisions about routing structure, authentication, validation, and error handling, and inconsistent choices lead to fragile services that are hard to maintain. ## Core Features & Use Cases - RESTful API Patterns: Resource-based routing, nested resources, and a standardized request/response envelope with success, error, and pagination metadata. - Authentication & Authorization: JWT token generation and verification middleware, plus role-based access control for protected routes. - Validation & Error Handling: Zod schema validation middleware, custom error classes, and a centralized error handler covering validation, database, and unknown errors. - Use Case: When scaffolding a new Express API, apply these patterns to get consistent endpoint structure, Zod-validated request bodies, JWT-protected routes, and rate limiting without designing each layer from scratch. ## Quick Start Implement a REST API for users with JWT authentication, Zod request validation, and centralized error handling using these backend patterns.

Frequently Asked Questions about backend-implementation-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure REST API endpoints in Express?▼

Use resource-based routing where HTTP verbs map to operations: GET for list and detail, POST for create, PUT for update, DELETE for removal. Nest related resources under their parent path, such as /api/users/:id/posts for a user's posts.

How to add JWT authentication middleware to Express routes?▼

Extract the Bearer token from the Authorization header, verify it with jwt.verify against your secret, and attach the decoded payload to the request object. Return 401 responses with structured error codes for missing, expired, or invalid tokens.

How do I validate request bodies with Zod in Express?▼

Define a Zod schema for the expected body shape, then call safeParse inside a validation middleware. On failure, return a 400 response with field-level error details; on success, pass the parsed data to the route handler.

What is the correct middleware order in an Express app?▼

Apply security headers first, then CORS, body parsing, request logging, rate limiting, and authentication, followed by routes. The error handling middleware must be registered last so it catches errors from all upstream handlers.

How should Express apps handle database errors like duplicate entries?▼

Catch database-specific error codes in the centralized error handler, such as Postgres code 23505 for unique violations, and map them to appropriate HTTP statuses like 409 Conflict. Unknown errors should return a generic 500 response without leaking internals in production.