backend-patterns

Implements API design, database optimization, and caching patterns for Node.js backends.

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/inuishan/PET --skill backend-patterns-inuishan
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: backend-patterns
Source: https://github.com/inuishan/PET/tree/main/.codex/skills/backend-patterns
Command: npx skills add https://github.com/inuishan/PET --skill backend-patterns-inuishan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building scalable server-side applications requires consistent architectural decisions across API design, data access, caching, and error handling, and ad-hoc implementations lead to N+1 queries, inconsistent error responses, and unmaintainable code. ## Core Features & Use Cases - API & Layering Patterns: Provides RESTful endpoint conventions plus repository, service, and middleware patterns for Express and Next.js API routes. - Database & Caching Guidance: Covers query optimization, N+1 prevention, transactions via Supabase RPC, and Redis cache-aside strategies. - Resilience & Security Patterns: Includes centralized error handling, retry with exponential backoff, JWT authentication, role-based access control, rate limiting, and structured logging. - Use Case: When adding a new authenticated endpoint to a Next.js app, apply the withAuth middleware, repository pattern, and centralized error handler to ship a consistent, production-shaped route. ## Quick Start Apply backend patterns to design a new authenticated REST endpoint with caching and proper error handling for my Next.js API.

Frequently Asked Questions about backend-patterns

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

FAQPage Schema
How do I structure a REST API in Next.js?▼

Use resource-based URLs like GET /api/markets and /api/markets/:id, with query parameters for filtering, sorting, and pagination. Separate concerns into repository, service, and middleware layers so business logic stays decoupled from data access.

How to prevent N+1 queries in Supabase?▼

Batch fetch related records instead of querying in a loop: collect foreign keys, run one query for all related rows, then map results back in memory. Also select only needed columns rather than using select('*').

What caching pattern works with Redis and a repository layer?▼

Use the cache-aside pattern: check Redis first, fetch from the database on a miss, then populate the cache with a TTL such as 300 seconds. A CachedMarketRepository decorator can wrap the base repository and expose cache invalidation.

Does the in-memory rate limiter work across multiple servers?▼

No, the simple Map-based rate limiter only tracks requests within a single process. For multi-instance deployments, move the request counters to a shared store such as Redis so limits apply consistently across servers.

How do I implement role-based access control in an API route?▼

Define a role-to-permissions map, verify the JWT to identify the user, then wrap handlers with a requirePermission higher-order function that checks the user's role before executing the handler and returns 403 on failure.