49 Production-Ready SaaS Patterns for TypeScript/Next.js and Python/FastAPI
NEW: Use the scaffolding/ system to automatically scaffold enterprise-grade infrastructure before you even know what you're building.
| Document | Time | What It Creates |
|---|---|---|
| 00-MANIFEST | - | Execution guide and dependency map |
| 01-WORKSPACE | 10m | Monorepo, tooling, git, CI, testing setup |
| 02-ENVIRONMENT | 5m | Type-safe env validation |
| 03-TYPES | 10m | Shared types, exceptions, type tests |
| 04-DATABASE | 10m | Schema, migrations, RLS, fixtures, seeding |
| 05-AUTH | 15m | Auth infrastructure, auth tests |
| 06-RESILIENCE | 15m | Circuit breakers, retries, resilience tests |
| 07-WORKERS | 15m | Job system, state machine, worker tests |
| 08-API | 10m | API foundation, middleware, API tests |
| 09-OBSERVABILITY | 10m | Logging, metrics, health |
| 10-INTEGRATIONS | 10m | Stripe, webhooks, email, integration tests |
| 11-FRONTEND | 15m | Design tokens, components, component tests |
| 12-SECURITY | 20m | CSP, CORS, audit logging, input sanitization |
| 13-FILE-STORAGE | 15m | Supabase Storage, uploads, signed URLs |
| 14-CACHING | 15m | Redis client, cache patterns, sessions |
| 15-DEPLOYMENT | 20m | Docker Compose, Dockerfiles, health checks |
Total: ~3 hours for complete enterprise foundation with testing
| Category | Patterns | Description |
|---|---|---|
| 00-foundations | 4 | Environment, TypeScript, Monorepo, Feature Flags |
| 01-auth | 5 | Authentication, Authorization, RLS |
| 02-database | 1 | Migrations, Schema Management |
| 03-resilience | 10 | Circuit Breakers, Retries, Graceful Degradation |
| 04-workers | 4 | Background Jobs, Orchestration, DLQ |
| 05-data-pipeline | 7 | Batch Processing, ETL, Validation |
| 06-api | 5 | API Design, Idempotency, Rate Limiting |
| 07-realtime | 5 | SSE, WebSockets, Multiplayer |
| 08-frontend | 4 | Design Tokens, Mobile, PWA |
| 09-observability | 5 | Metrics, Health, Anomaly Detection |
| 10-integrations | 4 | Stripe, OAuth, Webhooks, Email |
| 11-ai | 4 | Prompt Engine, Provenance, Coaching |
| 12-caching | 1 | Intelligent Cache |
| 13-data-processing | 3 | Fuzzy Matching, Scoring, Analytics |
Core setup patterns for any project.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| ENVIRONMENT_CONFIG | 2h | Low | Environment variable management with validation |
| TYPESCRIPT_STRICT | 1h | Low | Strict TypeScript configuration |
| MONOREPO_STRUCTURE | 4h | Medium | Turborepo/pnpm workspace setup |
| FEATURE_FLAGS | 3h | Medium | Feature flag system with gradual rollout |
Authentication and authorization patterns.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| SUPABASE_AUTH | 4h | Medium | Supabase authentication integration |
| JWT_REFRESH_ROTATION | 3h | Medium | Secure JWT refresh token rotation |
| MIDDLEWARE_PROTECTION | 2h | Low | Route protection middleware |
| ROW_LEVEL_SECURITY | 4h | Medium | PostgreSQL RLS policies |
| TIER_ENTITLEMENTS | 3h | Medium | Subscription tier feature gating |
Database management patterns.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| MIGRATIONS | 2h | Low | Safe migration patterns for zero-downtime deploys |
Fault tolerance and graceful degradation.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| CIRCUIT_BREAKER | 4h | Medium | Prevent cascade failures |
| RETRY_FALLBACK | 2h | Low | Exponential backoff with fallbacks |
| BACKPRESSURE | 4h | Medium | Buffer management under load |
| DISTRIBUTED_LOCK | 3h | Medium | Redis-based distributed locking (TypeScript) |
| DISTRIBUTED_LOCKING | 3h | Medium | Async context manager for locks (Python) |
| GRACEFUL_SHUTDOWN | 3h | Medium | Clean shutdown with job tracking |
| LEADER_ELECTION | 4h | Medium | Single-leader coordination |
| RESILIENT_STORAGE | 6h | High | Multi-backend storage with failover |
| ERROR_SANITIZATION | 2h | Low | Safe error messages for production |
| EXCEPTION_TAXONOMY | 2h | Low | Structured exception hierarchy |
Background job processing.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| ORCHESTRATION | 4h | Medium | Worker coordination and scheduling |
| DEAD_LETTER_QUEUE | 3h | Medium | Failed job handling and replay |
| JOB_STATE_MACHINE | 4h | Medium | State machine for job lifecycle |
| BACKGROUND_JOB_PROCESSING | 4h | Medium | General background job patterns |
Data processing and ETL patterns.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| BATCH_PROCESSING | 4h | Medium | Batched DB operations with fallback |
| CHECKPOINT_RESUME | 4h | Medium | Exactly-once processing semantics |
| DEDUPLICATION | 4h | Medium | Multi-source event deduplication |
| GEOGRAPHIC_CLUSTERING | 5h | Medium | Grid-based geo clustering |
| SECURE_UPLOAD_PIPELINE | 6h | High | File upload with malware scanning |
| SNAPSHOT_AGGREGATION | 4h | Medium | Daily snapshot compression |
| VALIDATION_QUARANTINE | 4h | Medium | Data validation with quarantine |
API design and client patterns.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| API_CLIENT | 3h | Medium | Type-safe API client wrapper |
| IDEMPOTENCY | 4h | Medium | Idempotent API operations |
| TIER_RATE_LIMITS | 4h | Medium | Subscription-based rate limiting (TypeScript) |
| TIER_RATE_LIMITING | 4h | Medium | Subscription-based rate limiting (Python) |
| TRANSFORMERS | 2h | Low | Data transformation utilities |
Real-time communication patterns.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| SSE_STREAMING | 3h | Medium | Server-Sent Events streaming |
| SSE_RESILIENCE | 3h | Medium | Resilient SSE with reconnection |
| WEBSOCKET_CONNECTION_MANAGEMENT | 4h | Medium | WebSocket connection lifecycle |
| ATOMIC_MATCHMAKING | 6h | High | Race-free matchmaking system |
| SERVER_AUTHORITATIVE_TICK | 8h | High | Server-authoritative game loop |
Frontend architecture patterns.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| DESIGN_TOKENS | 4h | Medium | Design token system |
| DESIGN_TOKEN_SYSTEM | 4h | Medium | Comprehensive token architecture |
| MOBILE_COMPONENTS | 3h | Low | Mobile-first components |
| PWA_SETUP | 2h | Low | Progressive Web App setup |
| FIXED_TIMESTEP_GAME_LOOP | 4h | Medium | Deterministic game loop |
Monitoring and alerting patterns.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| METRICS | 3h | Medium | Prometheus-compatible metrics |
| HEALTH_MONITORING | 4h | Medium | Worker health tracking |
| ANOMALY_DETECTION | 5h | Medium | Rule-based anomaly detection |
| LOGGING_OBSERVABILITY | 3h | Medium | Structured logging patterns |
| FILE_STORAGE | 3h | Medium | File storage with tracking |
Third-party service integrations.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| STRIPE_INTEGRATION | 6h | High | Stripe payments and subscriptions |
| OAUTH_INTEGRATION | 4h | Medium | OAuth provider integration |
| WEBHOOK_SECURITY | 4h | Medium | Secure webhook handling |
| EMAIL_SERVICE | 4h | Medium | SendGrid email with rate limits |
AI/ML integration patterns.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| PROMPT_ENGINE | 4h | Medium | Structured prompt management |
| PROVENANCE_AUDIT | 6h | High | AI generation audit trail |
| AI_COACHING_SYSTEM | 8h | High | AI-powered coaching system |
| AI_GENERATION_CLIENT | 4h | Medium | AI generation client wrapper |
Caching strategies.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| INTELLIGENT_CACHE | 4h | Medium | Smart caching with invalidation |
Data processing and analysis.
| Pattern | Time | Complexity | Description |
|---|---|---|---|
| MULTI_STAGE_MATCHING | 5h | Medium | Fuzzy matching pipeline |
| SCORING_ENGINE | 4h | Medium | Configurable scoring system |
| ANALYTICS_PIPELINE | 6h | High | Analytics data pipeline |
| COMMUNITY_FEED | 4h | Medium | Social feed algorithms |
See PATTERN_TEMPLATE.md for the standard format when adding new patterns.
- Follow the pattern template
- Include implementation time estimate
- Add production checklist
- Link to related patterns
- Include both TypeScript and Python where applicable