Patterns
Production-ready infrastructure code. Copy what you need, customize as required.
50 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.
developer-experience
5 patternsFeature Flags
intermediateType-safe feature flags with gradual rollouts. Supports percentage-based rollouts, user targeting, and A/B testing using Vercel Edge Config or Upstash.
Analytics
beginnerPrivacy-friendly analytics with PostHog. Includes event tracking, user identification, and feature flag integration.
Search
intermediateFull-text search with typo tolerance, filters, and facets using Meilisearch. Includes indexing utilities and React hooks.
Internationalization
intermediateType-safe internationalization with next-intl. Includes locale detection, server components support, and message formatting.
Content Moderation
intermediateAI-powered content moderation for user-generated content. Uses OpenAI's free moderation API for text.
infrastructure
5 patternsFile Uploads
intermediateServerless file uploads with presigned URLs. Supports AWS S3 and Vercel Blob with file validation.
Background Jobs
intermediateServerless background job processing with Inngest. Event-driven workflows with automatic retries.
Scheduled Tasks
intermediateCron jobs and scheduled tasks for serverless. Use Inngest for complex workflows or Vercel Cron for simple endpoints.
Webhooks
intermediateReceive webhooks securely with signature verification. Includes Stripe and GitHub verification utilities.
Realtime
intermediateReal-time pub/sub updates using Pusher. Includes React hooks for subscribing to channels and events.
ai
5 patternsAI Chat
intermediateProduction-ready AI chat with streaming responses, conversation history, and provider abstraction supporting OpenAI and Anthropic.
AI Embeddings
intermediateVector embeddings for semantic search and RAG applications using Upstash Vector.
AI Tool Calling
advancedFunction/tool calling pattern for agentic AI workflows with type-safe tool definitions.
AI Rate Limits
intermediateToken-aware rate limiting for AI endpoints with per-user quotas and cost tracking.
AI Streaming UI
beginnerReact components for streaming AI responses with typing indicators and message lists.
security
5 patternsAudit Logging
intermediateStructured audit trail for compliance and debugging with immutable logs.
Data Encryption
intermediateField-level encryption for sensitive data using AES-256-GCM.
CSRF Protection
beginnerCross-Site Request Forgery protection for form submissions using Web Crypto API.
CORS Config
beginnerConfigurable CORS setup for API routes with origin validation and preflight handling.
Multi-Factor Auth
intermediateMulti-factor authentication with TOTP, QR code generation, and backup codes.