kensaurus/cursor-kenji/backend-patterns
Claude Code and agent skill by kensaurus/cursor-kenji
- community
Checking that the SKILL.md file is still in the repository.
Apply backend patterns — queues, caching, rate limits, serverless/edge. Use when "queue jobs", "caching layer", "rate limiting", "server actions", or "edge function". Which architecture to pick → audit-backend-architecture.
Install
npx vskill@latest install kensaurus/cursor-kenji/backend-patternsSKILL.md
Backend Patterns Skill
Degree of freedom: MIXED. Which pattern to apply [HIGH freedom]; existing-architecture probes and the validation list [LOW freedom — run exactly].
This skill vs neighbors
| Skill | Owns | |
|---|---|---|
| backend-patterns (this) | Apply queues, caching, rate limits, and serverless/edge patterns | |
audit-backend-architecture | Read-only architecture audit and pattern advisor: which pattern to pick |
How to reason
- Observe — existing server/api/actions, ORM, queues, cache
- Interpret — missing pattern vs duplicate vs wrong layer
- Classify — reuse / add-queue / add-cache / add-rate-limit / edge-fn
- Severity — unauthenticated mutation outranks a missing cache
Worked example
Observe:createOrdersends email inline; no Inngest/queue; checkout p95 4s.Interpret: confirmation is post-response work, not request-path.Classify:after()or anorder/createdjob; keep the write transactional.Verify: order row commits; email/inventory run after response; retries do not double-charge.
Self-critique before reporting
- Existing first — searched server/api/actions before adding a second pattern
- Auth + validate — every mutation checks session and Zod
- Idempotent — retries on the new path do not double-apply
- Right owner — which architecture to pick →
audit-backend-architecture
Design scalable, maintainable backend architectures using modern patterns and best practices.
Code examples lean on Next.js App Router + Supabase/Prisma. The patterns arestack-agnostic — adapt ORMs, client libraries, and deploy targets to your detectedecosystem.
Check existing first [LOW freedom — run exactly]
Before implementing ANY backend pattern, verify:
- Check existing architecture:
- Check existing patterns:
- Check database setup:
Why: Backend changes have wide impact. Understand existing architecture first.
Server Actions (Next.js 16+) [HIGH freedom]
Next.js 16: Turbopack default; 'use cache' + cacheComponents; reactCompiler: true; middleware.ts → proxy.ts (grep both). Instant navigations → enhance-web-instant-nav.
- Order inside every action: auth check → Zod
safeParse→ execute → map known errors (PrismaP2002) → generic failure message. - Return
ActionResult<T>:{ success: true, data }or{ success: false, error, fieldErrors? }; never throw to the client. revalidatePathafter a successful write.- Post-response work (confirmation email, inventory, notifications) goes in
after()fromnext/server, keeping the write transactional.
Full createUser action and the after() example: references/request-patterns.md §Server Actions.
tRPC Setup [HIGH freedom]
publicProcedurefor reads anyone may do;protectedProcedurefor anything that usesctx.session.- Every procedure has a Zod
.input(); mutations stampcreatedByIdfrom the session, not the input. - List endpoints paginate by cursor: fetch
limit + 1, pop the extra row asnextCursor.
Full usersRouter (getById, create, cursor-paginated list): references/request-patterns.md §tRPC router definition.
Supabase Edge Functions [HIGH freedom]
Deno.serve; answerOPTIONSwith the CORS headers first.- Verify the webhook signature against the raw body before parsing JSON;
401on mismatch. - Admin client from
SUPABASE_SERVICE_ROLE_KEYbypasses RLS; use it only inside the function. - Catch everything; log server-side, return a generic
500JSON body with CORS headers.
Full process-webhook function: references/request-patterns.md §Supabase Edge Function.
Database Patterns [HIGH freedom]
- Optimistic locking —
version INTcolumn;UPDATE ... WHERE id = $1 AND version = $2and treat 0 rows as a concurrent update. - Soft deletes — nullable
deletedAtwith an index; every read filtersdeletedAt: null; delete sets the timestamp. - Audit logging —
audit_logs(table_name, record_id, action, old_data, new_data, user_id)filled by aSECURITY DEFINERtrigger usingTG_OP,row_to_json,auth.uid().
Soft-delete Prisma model and the full audit trigger: references/data-and-jobs.md §Soft deletes, §Audit logging.
Caching Patterns [HIGH freedom]
- Next.js:
fetch(url, { next: { revalidate, tags } });revalidateTagon demand;unstable_cachearound DB queries with tags. - Redis (Upstash): one
getCachedData(key, fetcher, ttl)helper, cache-aside; key by entity and id (user:${id}). - Pick TTL by staleness tolerance, and always tag so a write can bust the cache.
Next.js cache calls and the Redis helper: references/data-and-jobs.md §Next.js cache, §Redis caching.
Background Jobs [HIGH freedom]
- Default: Inngest.
inngest.createFunction({ id }, { event }, async ({ event, step }) => ...); each side effect in its ownstep.runso retries resume, not restart. - Trigger with
inngest.send({ name: 'order/created', data })from the Server Action after the write commits. - Early exit (out of stock) is a
step.run+return { status: 'cancelled' }, not a throw.
Full Inngest function and the Trigger.dev scheduled-task alternative: references/data-and-jobs.md §Background jobs, §Alternatives.
Rate Limiting [HIGH freedom]
@upstash/ratelimitwithRatelimit.slidingWindow(10, '10 s')overRedis.fromEnv().- Key by user id (or IP for anonymous); on
!successreturnToo many requestswithretryAfterseconds fromreset.
Full rateLimitedAction: references/request-patterns.md §Rate limiting.
Architecture patterns (distributed systems) [HIGH freedom]
Gateway, BFF, bulkhead, circuit breaker, outbox+CDC, saga, hexagonal, ACL, and strangler-fig → references/architecture-patterns.md. Pick the pattern for the topology (no mesh on a monolith; no CQRS unless reads/writes diverge). Timeouts/retries/idempotency → audit-resilience; structural gap report → audit-backend-architecture.
Validation [LOW freedom — do not skip]
After implementing backend patterns:
- Error handling → All errors caught, logged, safe response returned
- Auth checks → Every mutation verifies authentication
- Input validation → Zod schema on all inputs
- Rate limiting → Sensitive endpoints protected
- Idempotency → Critical operations handle retries
- Logging → Structured logs without sensitive data
- Testing → Unit tests for business logic, integration for APIs
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/backend-patterns/SKILL.md
Popularity
- Repository stars
- 9
- 7-day trend score
- 12
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/kensaurus/cursor-kenji/backend-patterns)