← All Projects
03 Case Study

mchatly: Multi-Tenant AI Chatbot SaaS Platform

A multi-tenant SaaS platform that lets businesses create, customize, and deploy AI-powered chatbots with an end-to-end RAG pipeline, zero hallucinations, and real-time human handover.

Category Full-Stack & AI Systems
Reading Time ~2 min read
02 Case Study Breakdown

Overview

mchatly is a production multi-tenant SaaS platform that allows businesses to create, customize, and deploy AI-powered chatbots on their websites with a single embed snippet. The platform features an end-to-end RAG (Retrieval-Augmented Generation) pipeline that grounds chatbot responses in business-specific knowledge bases, eliminating hallucinations and ensuring factual accuracy.

Key Architectural Highlights

1. End-to-End Grounded RAG Pipeline

  • User queries are embedded via Gemini Embedding API and matched against a Pinecone vector store for semantic retrieval across uploaded PDFs, documentation, and business FAQs.
  • Retrieved context is streamed in real-time through Gemini 2.5 Flash with a custom system prompt engine that enforces brand tone, persona guidelines, and strict anti-hallucination safeguards.

2. Real-Time Live Chat & Human Handover

  • Built a bidirectional real-time communication system using Ably WebSockets.
  • Allows business admins to monitor conversations in real-time, seamlessly take over sessions from the AI, and chat directly with website visitors with zero dropped messages.

3. Subscription & Usage Billing Engine

  • Implemented a 3-tier subscription architecture (Free / Pro / Premium) using LemonSqueezy billing.
  • Automated usage-based overage tracking and invoice reconciliation powered by Vercel Cron and plan-gated feature access guards.

4. High-Performance Analytics Dashboard

  • Session tracking, lead capture forms, geographic user maps, device breakdowns, and conversation resolution trend charts powered by Recharts.
  • Optimized database query costs with a bounded 180-day Firestore read window and an Upstash Redis caching layer.
  • Full CSV export capability for CRM integration.

5. Universal Embeddable Widget

  • Zero-dependency embeddable chat widget packaged as an iframe with a bidirectional postMessage protocol for dynamic auto-resizing.
  • Auto-generated snippet builder supporting 10+ frameworks including React, Next.js, Vue, Angular, Svelte, Shopify, WordPress, Webflow, and vanilla HTML.

6. Multi-Channel Notification Orchestration

  • Instant alert routing across multiple channels: Web Push (VAPID), Telegram Bot API, WhatsApp Business API, and Upstash QStash for scheduled and delayed retry queues.

Tech Stack

  • Frontend & App Architecture: Next.js 16 (App Router), React 19, TypeScript, Tailwind CSS, Recharts
  • Backend & Real-Time: Firebase Firestore (Admin SDK), Ably WebSockets, Upstash Redis, Upstash QStash
  • AI & Vector Search: Google Gemini API (Gemini 2.5 Flash, Gemini Embeddings), Pinecone Vector DB
  • Payments & Deployment: LemonSqueezy, Vercel Cron, Cloudinary, Zod