backend-patterns

Implements backend architecture patterns for Node.js, Express, and Next.js API routes.

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill backend-patterns-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: backend-patterns
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/backend-patterns
Command: npx skills add https://github.com/Femad-6/my-skills --skill backend-patterns-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building scalable server-side applications requires consistent patterns for API design, database access, caching, and error handling, and this Skill provides proven implementations that prevent common pitfalls like N+1 queries and unstructured error responses. ## Core Features & Use Cases - API Design Patterns: RESTful endpoint structure, repository pattern, service layer separation, and middleware composition for authentication and logging. - Database Optimization: Query optimization, N+1 prevention through batch fetching, and transaction handling with Supabase RPC functions. - Caching & Resilience: Redis cache-aside patterns, retry logic with exponential backoff, rate limiting, and background job queues. - Use Case: When building a Next.js API route that fetches markets with their creators, apply the batch-fetch pattern to avoid N+1 queries and wrap the handler with JWT authentication middleware. ## Quick Start Ask the AI to design a REST API endpoint with authentication middleware, caching, and proper error handling for your Node.js backend.

Frequently Asked Questions about backend-patterns

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

FAQPage Schema
How do I prevent N+1 queries in Node.js backends?

Prevent N+1 queries by batch-fetching related records instead of querying in a loop. Collect all foreign keys, fetch related records in one query, then map them back using a Map keyed by ID for O(1) lookups.

How to implement JWT authentication middleware in Next.js API routes?

Create a higher-order function that extracts the Bearer token from the authorization header, verifies it with jsonwebtoken, and attaches the user to the request. Wrap your route handler with this middleware to reject unauthenticated requests with 401 responses.

What is the cache-aside pattern with Redis?

Cache-aside checks Redis first for a key, and on a miss fetches from the database and populates the cache with a TTL. This pattern keeps frequently accessed data like market records in memory while falling back to the database on cache misses.

Does the repository pattern work with Supabase?

Yes, define a repository interface with methods like findAll and findById, then implement it with a Supabase client class that builds queries with filters and pagination. This abstracts data access so business logic stays independent of the database client.

When should I use a background job queue instead of synchronous processing?

Use a job queue for non-blocking tasks like indexing or notifications that would slow down API responses. The simple in-memory queue pattern works for single-process apps, but distributed systems need persistent queues like Redis-backed solutions.