Building a Production AI Chatbot for an Educational Institute: Architecture, Lessons & Full Stack Deep-Dive Here is a factual summary of the article: The article describes the architecture and development of a full-stack AI chatbot platform built for IFDA, an Indian educational institute, using a Next.js 14 monorepo deployed on Vercel with a Neon PostgreSQL backend. The chatbot handles course discovery, lead capture, appointment scheduling, and WhatsApp messaging, employing a two-tier approach that uses scripted responses for routine queries and GPT only when necessary to reduce costs and latency. The system features a block-based response architecture that allows the same engine output to be rendered for both the web UI and WhatsApp through separate channel-specific renderers. TL;DR:I built a full-stack AI chatbot platform for IFDA, an Indian educational institute. It handles course discovery, lead capture, appointment scheduling, WhatsApp messaging, and comes with a complete admin CRM — all deployed on Vercel with a Neon PostgreSQL backend. Here's everything I learned, every system I built, and why I made the choices I did. Why This Project Exists Educational institutes spend enormous resources on human admissions counselors. Prospects ask the same questions repeatedly: What courses do you offer? How long is the program? What will I earn afterwards? And every unanswered query at 11 PM is a lost lead. IFDA needed something smarter than a static FAQ page and cheaper than a 24/7 call center. The solution: a hybrid AI chatbot that could hold intelligent conversations about courses, capture leads, book counseling appointments, and hand off hot prospects to human staff — all while syncing with WhatsApp. This is the full technical story of how I built it. The Architecture at a Glance The project is a Next.js 14 App Router monorepo — one codebase serving the public-facing chatbot widget, the admin CRM dashboard, and all API routes. Every component was chosen deliberately: | Layer | Technology | |---|---| | Framework | Next.js 14 App Router | | Language | TypeScript throughout | | Database | Neon PostgreSQL + Prisma ORM | | AI / LLM | OpenAI GPT for intent, embeddings, and response generation | | Deployment | Vercel Edge-compatible | | DoubleTick API | | | Auth | Custom JWT + RBAC middleware | | Session | Server-side session store | The graph of this codebase has 1,259 nodes files, functions, types and 3,276 edges calls, contains, references distributed across 55+ community clusters — from the bot engine core, to the Prisma edge runtime, to the admin dashboard pages. Let's walk through each major system. System 1: The Bot Engine lib/bot/engine.ts The heart of the project is processMessage in lib/bot/engine.ts . This single function is the traffic controller for every incoming message — whether it arrives from the web widget or WhatsApp. Hybrid Scripted + LLM Architecture The bot does not send every message to GPT. That would be slow and expensive. Instead, it uses a two-tier approach: - Scripted funnel stages — structured flows for lead capture name, phone, course interest, city where deterministic logic is faster and more reliable than an LLM. - LLM fallback — for open-ended questions, course comparisons, career queries, or anything outside a defined stage. The stage management lives in lib/ai/intent.ts : // intent.ts — simplified export function resolveStage session: Session : FunnelStage { ... } export function getMissingFields lead: Partial