Most “AI app” tutorials show a one-file script that calls OpenAI. Production needs more. This module is the actual architecture you will run, the choices that scale, and the observability that lets you debug at 2am.
Reference architecture
Layer by layer. Edge / CDN: Cloudflare in front for rate limit, WAF, geo-restriction. Application backend: Next.js or FastAPI on Vercel/Railway/Fly.io. Handles auth, request validation, prompt construction. LLM gateway: LiteLLM or Helicone proxy. Routes between providers (OpenAI/Anthropic/self-hosted). Adds caching, retries, fallback. Vector DB: Qdrant (self-hosted) or Pinecone (managed) for RAG. Embedding model: BGE-M3 (self-hosted) or OpenAI text-embedding-3-small. Cache: Redis for prompt-response cache and rate limit counters. Database: Postgres for user data, conversation history, audit logs. Observability: Langfuse (open source) or LangSmith for AI traces; Sentry for errors; Grafana for metrics.
Book a free 30-minute scoping call
Our senior consultants will review your stack and tell you honestly what to fix first. No slide deck. No obligation. Indian businesses only.