backend-patterns

Implements backend architecture patterns for APIs, databases, caching, and authentication.

Updated Mar 12, 2026
One-click install
npx skills add https://github.com/RavitejaKarra24/dotfiles --skill backend-patterns-ravitejakarra24
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: backend-patterns
Source: https://github.com/RavitejaKarra24/dotfiles/tree/main/agents/.agents/skills/backend-patterns
Command: npx skills add https://github.com/RavitejaKarra24/dotfiles --skill backend-patterns-ravitejakarra24

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building scalable server-side applications requires consistent architectural decisions across API design, data access, caching, and security. This Skill provides proven backend patterns that prevent common pitfalls like N+1 queries, inconsistent error handling, and insecure authentication flows. ## Core Features & Use Cases - API & Layering Patterns: RESTful resource design, repository pattern, service layer separation, and middleware pipelines for auth and request processing. - Database & Caching: Query optimization, N+1 prevention via batch fetching, transaction handling with Supabase RPC, and Redis cache-aside strategies. - Resilience & Security: Centralized error handlers, retry with exponential backoff, JWT validation, role-based access control, and structured logging. - Use Case: When building a Next.js API with Supabase, apply the repository and service layer patterns to keep business logic testable, add Redis caching for hot endpoints, and wrap handlers with auth middleware and RBAC checks. ## Quick Start Ask the agent to design a REST API endpoint with repository, service layer, caching, and JWT authentication following backend patterns.

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 with repository and service layers?

Define resource-based URLs like GET /api/markets/:id, abstract data access behind a repository interface, and place business logic in a service class that depends on the repository. This keeps handlers thin and business rules testable.

How to prevent N+1 query problems in backend code?

Batch fetch related records instead of querying in a loop. Collect foreign keys from the main result set, run one query for all related rows, then join them in memory using a Map keyed by ID.

What caching pattern works with Redis for database queries?

Use the cache-aside pattern: check Redis first, and on a miss fetch from the database and write the result back with a TTL such as 300 seconds. A decorator repository class can wrap the base repository to add caching transparently.

Can I use in-memory rate limiting for production APIs?

No. Per-process in-memory counters reset on deploy, split across replicas, and fail open in serverless environments. Use a shared store like Redis, a gateway, or the platform's native limiter instead.

How do I implement role-based access control with JWT?

Verify the JWT to extract the user's role, map roles to permission lists, and wrap handlers with a higher-order function that checks the required permission before executing. Return 403 when permissions are insufficient.

When should I use database transactions in Supabase?

Use transactions when multiple writes must succeed or fail together, such as creating a market with its initial position. Implement them as Postgres functions via supabase.rpc so rollback happens automatically on error.