Patterns
Production-ready infrastructure code. Copy what you need, customize as required.
30 patterns
Database
3 patternsConnection Pooling
beginnerDatabase connection pooling for serverless and edge environments. Prevents connection exhaustion and handles cold starts gracefully.
Prisma Edge Setup
intermediateConfigure Prisma for edge runtime with Accelerate connection pooling.
Drizzle Config
intermediateType-safe Drizzle ORM setup with migrations for PostgreSQL.
Auth
3 patternsOAuth Setup
intermediateProduction-ready OAuth authentication with Auth.js (NextAuth v5). Includes GitHub and Google providers with database session storage.
Session Management
intermediateSecure session handling with database storage and automatic cleanup.
RBAC Patterns
advancedRole-based access control with permissions, roles, and middleware.
API
3 patternsRate Limiting
intermediateAPI rate limiting with sliding window algorithm using Upstash Redis.
API Validation
beginnerType-safe request/response validation with Zod schemas.
Error Handling
beginnerConsistent error handling with custom error classes and structured responses.
Testing
4 patternsVitest Setup
beginnerUnit and integration testing with Vitest and React Testing Library.
Playwright E2E
intermediateEnd-to-end testing with Playwright and page object patterns.
MSW Mocking
intermediateAPI mocking with Mock Service Worker for tests and development.
Component Testing
beginnerReact component testing with Testing Library, user events, and accessibility testing.
Caching
3 patternsRedis Cache
intermediateRedis caching with Upstash. Includes cache utilities, automatic serialization, and cache invalidation patterns.
Next.js Cache
beginnerNext.js built-in caching with unstable_cache, revalidatePath, and revalidateTag.
In-Memory Cache
beginnerSimple LRU in-memory caching for serverless. No external dependencies.
Resend Email
beginnerTransactional email with Resend and React Email templates.
Nodemailer Setup
beginnerFree email sending with Nodemailer. Supports SMTP, Gmail, and other providers.
AWS SES
intermediateCost-effective email at scale with AWS Simple Email Service.
Payments
3 patternsStripe Payments
intermediateStripe integration with checkout sessions, webhook handling, and subscription management.
LemonSqueezy
intermediatePayment integration with LemonSqueezy. Includes checkout, webhooks, and subscriptions with built-in tax handling.
Usage-Based Billing
advancedMetered billing with Stripe. Track usage, report to Stripe, and charge customers based on consumption.
Monitoring
3 patternsSentry Monitoring
beginnerError tracking and performance monitoring with Sentry. Includes source maps and custom context.
OpenTelemetry
intermediateOpen standard observability with OpenTelemetry. Works with Jaeger, Zipkin, and commercial backends.
Structured Logging
beginnerStructured JSON logging with Pino. Fast, low-overhead logging with log levels and context.
Environment
2 patternsDeployment
3 patternsDocker Config
intermediateMulti-stage Docker builds optimized for Next.js.
GitHub Actions
intermediateCI/CD pipelines for testing, building, and deploying.
Vercel Config
beginnerVercel deployment configuration with edge functions, environment setup, and build optimizations.