Skip to content

Repository files navigation

🎧 HelpDesk β€” AI-Powered Customer Support Platform

An intelligent help desk that lets businesses deploy a customizable AI chat widget on their website. Visitors chat with a LangGraph-powered AI agent backed by a knowledge base β€” and when needed, conversations seamlessly escalate to human agents in real-time.


πŸ—οΈ Architecture

To update this diagram, open .excalidraw in VSCode and export it as architecture.png to the root folder.


✨ Features

πŸ€– AI Agent

  • LangGraph StateGraph orchestration with automatic tool-calling loops
  • Google Gemini LLM (configurable model, temperature, tone, response length)
  • MongoDB Atlas Vector Search for RAG-based knowledge retrieval
  • Confidence thresholds β€” AI only answers when it's sure; otherwise escalates or admits uncertainty
  • Persistent memory via MongoDBSaver checkpointer β€” the AI remembers the full conversation

πŸ’¬ Embeddable Chat Widget

  • Drop-in <script> tag β€” works on any website
  • Real-time AI responses via Next.js Server Actions
  • Automatic lead capture (name, email, phone)
  • Seamless handoff to human agents via Socket.IO
  • Continue / Start New Chat flows for returning visitors

πŸ–₯️ Admin Dashboard

  • Inbox β€” Real-time human chat with visitors (claim, assign, resolve)
  • Leads β€” Auto-captured visitor contacts with search & filtering
  • Knowledge Base β€” Upload docs, scrape URLs, manage AI training data
  • Team β€” Invite members, assign roles (owner / admin / agent)
  • Settings β€” Configure AI agent personality, model, thresholds
  • Widget Customizer β€” Customize colors, branding, welcome messages

πŸ”Œ Real-Time Infrastructure

  • Custom Node.js server running Next.js + Socket.IO on a single port
  • JWT-based auth for both visitors (tickets) and agents (tokens)
  • Workspace-scoped rooms for multi-tenant isolation
  • Routing service: ai β†’ waiting β†’ human β†’ resolved β†’ ai

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Custom Node.js Server                        β”‚
β”‚                    (server.ts β€” port 3000)                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚     Next.js 16        β”‚   β”‚       Socket.IO Server             β”‚ β”‚
β”‚  β”‚  (App Router + RSC)   β”‚   β”‚   (socket-server.ts)               β”‚ β”‚
β”‚  β”‚                       β”‚   β”‚                                    β”‚ β”‚
β”‚  β”‚  Server Actions:      β”‚   β”‚  Events:                           β”‚ β”‚
β”‚  β”‚  β€’ sendMessageToAi()  β”‚   β”‚  β€’ message:send / message:created  β”‚ β”‚
β”‚  β”‚  β€’ captureLeadAction()β”‚   β”‚  β€’ conversation:claim / assign     β”‚ β”‚
β”‚  β”‚  β€’ getChatHistory()   β”‚   β”‚  β€’ conversation:route-changed      β”‚ β”‚
β”‚  β”‚                       β”‚   β”‚  β€’ visitor:profile-updated          β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     LangGraph AI Agent                              β”‚
β”‚                       (graph.ts)                                    β”‚
β”‚                                                                     β”‚
β”‚   START ──► chatBot ◄──► tools ──► chatBot ──► END                  β”‚
β”‚               β”‚           β”‚                                         β”‚
β”‚               β”‚           β”œβ”€ πŸ” search_knowledge_base               β”‚
β”‚               β”‚           β”‚    └─ MongoDB Atlas Vector Search        β”‚
β”‚               β”‚           β”œβ”€ πŸ“§ capture_user_details                β”‚
β”‚               β”‚           β”‚    └─ Save lead + Socket.IO emit        β”‚
β”‚               β”‚           └─ 🚨 escalate_to_human                   β”‚
β”‚               β”‚                └─ Status β†’ "waiting"                β”‚
β”‚               β”‚                                                     β”‚
β”‚               β–Ό                                                     β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
β”‚   β”‚  Google Gemini LLM  β”‚  β”‚  MongoDBSaver            β”‚             β”‚
β”‚   β”‚  (ChatGoogle)       β”‚  β”‚  (Checkpointer/Memory)   β”‚             β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       MongoDB Atlas                                 β”‚
β”‚                                                                     β”‚
β”‚   Collections:                                                      β”‚
β”‚   β€’ workspaces        β€” Multi-tenant workspace config               β”‚
β”‚   β€’ conversations     β€” Chat sessions (status, visitor info)        β”‚
β”‚   β€’ messages          β€” All chat messages (visitor/ai/agent/system)  β”‚
β”‚   β€’ agents            β€” AI agent configuration per workspace        β”‚
β”‚   β€’ knowledge_entries β€” Uploaded knowledge base documents            β”‚
β”‚   β€’ vectors           β€” Embeddings for semantic search              β”‚
β”‚   β€’ checkpoints       β€” LangGraph conversation memory               β”‚
β”‚   β€’ users / members   β€” Auth & team management                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Layer Technology
Framework Next.js 16 (App Router, React 19, Server Actions)
AI Orchestration LangGraph (@langchain/langgraph)
LLM Google Gemini via @langchain/google
Embeddings Gemini Embedding 001 (1536 dims)
Vector Search MongoDB Atlas Vector Search
Database MongoDB + Mongoose 9
Real-Time Socket.IO 4
Auth NextAuth v4 + JWT
Styling Tailwind CSS 4 + shadcn/ui
State Zustand
Storage Cloudflare R2 (S3-compatible)
Background Jobs Inngest
Email Nodemailer
Runtime Node.js with TSX loader

πŸ“ Project Structure

help-desk/
β”œβ”€β”€ server.ts                  # Custom Node.js server (Next.js + Socket.IO)
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ actions/               # Server Actions (chat, leads, knowledge, team)
β”‚   β”œβ”€β”€ queries/               # Cached queries with "use cache" (leads, knowledge, dashboard)
β”‚   β”œβ”€β”€ dashboard/             # Admin dashboard pages
β”‚   β”‚   β”œβ”€β”€ inbox/             # Real-time human chat inbox
β”‚   β”‚   β”œβ”€β”€ leads/             # Captured leads table
β”‚   β”‚   β”œβ”€β”€ knowledge/         # Knowledge base management
β”‚   β”‚   β”œβ”€β”€ team/              # Team member management
β”‚   β”‚   β”œβ”€β”€ settings/          # AI agent & workspace settings
β”‚   β”‚   └── widget/            # Widget customizer
β”‚   β”œβ”€β”€ widget/                # Embeddable chat widget (iframe)
β”‚   β”œβ”€β”€ login/ signup/         # Auth pages
β”‚   └── onboarding/            # Workspace setup flow
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ ai/
β”‚   β”‚   β”œβ”€β”€ graph.ts           # LangGraph StateGraph definition
β”‚   β”‚   β”œβ”€β”€ tools.ts           # AI tools (search KB, capture details, escalate)
β”‚   β”‚   β”œβ”€β”€ llm.ts             # Google Gemini singleton factory
β”‚   β”‚   β”œβ”€β”€ vector-store.ts    # MongoDB Atlas Vector Search client
β”‚   β”‚   β”œβ”€β”€ embeddings.ts      # Gemini embedding model config
β”‚   β”‚   β”œβ”€β”€ checkpoint.ts      # MongoDBSaver for conversation memory
β”‚   β”‚   β”œβ”€β”€ agent-cache.ts     # Agent config caching
β”‚   β”‚   └── agent-instructions.ts  # Dynamic system prompt builder
β”‚   β”œβ”€β”€ chat/
β”‚   β”‚   β”œβ”€β”€ socket-server.ts   # Socket.IO server (all real-time events)
β”‚   β”‚   β”œβ”€β”€ socket-auth.ts     # JWT auth middleware (visitor + agent)
β”‚   β”‚   β”œβ”€β”€ socket-notify.ts   # HTTP-based socket emit helper
β”‚   β”‚   β”œβ”€β”€ routing-service.ts # Conversation routing (claim/assign/resolve)
β”‚   β”‚   └── use-socket.ts      # React hook for Socket.IO client
β”‚   β”œβ”€β”€ db/
β”‚   β”‚   β”œβ”€β”€ models/            # Mongoose models
β”‚   β”‚   └── connect.ts         # MongoDB connection singleton
β”‚   └── auth/                  # Auth utilities & workspace resolver
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ widget/                # Chat widget UI components
β”‚   β”œβ”€β”€ inbox/                 # Inbox sidebar & chat window
β”‚   β”œβ”€β”€ helpdesk/              # Dashboard UI (leads table, etc.)
β”‚   β”œβ”€β”€ knowledge/             # Knowledge base UI
β”‚   └── dashboard/             # Dashboard overview components
└── store/                     # Zustand stores

πŸš€ Getting Started

Prerequisites

  • Node.js β‰₯ 20
  • MongoDB Atlas cluster with Vector Search index
  • Google API Key (Gemini)
  • pnpm (recommended)

1. Clone & Install

git clone https://github.com/sunil8521/help-desk.git
cd help-desk
pnpm install

2. Environment Variables

Create a .env.local file:

# Database
MONGODB_URI=mongodb+srv://...

# Auth
NEXTAUTH_SECRET=your-secret
NEXTAUTH_URL=http://localhost:3000

# AI
GOOGLE_API_KEY=your-gemini-api-key

# Storage (Cloudflare R2)
CLOUDFLARE_R2_ACCESS_KEY_ID=...
CLOUDFLARE_R2_SECRET_ACCESS_KEY=...
CLOUDFLARE_R2_BUCKET_NAME=...
CLOUDFLARE_R2_ENDPOINT=...
CLOUDFLARE_R2_PUBLIC_URL=...

# Server
PORT=3000

3. MongoDB Atlas Setup

  1. Create a Vector Search Index named vector_index on the vectors collection:
{
  "fields": [
    {
      "type": "vector",
      "path": "embedding",
      "numDimensions": 1536,
      "similarity": "cosine"
    },
    {
      "type": "filter",
      "path": "workspaceId"
    }
  ]
}

4. Run

pnpm run dev

This starts the custom Node.js server with both Next.js and Socket.IO on http://localhost:3000.


πŸ”„ How the AI Works

  1. Visitor sends message β†’ sendMessageToAi() server action
  2. Message saved to MongoDB, then LangGraph invoked
  3. LangGraph loads conversation memory from MongoDBSaver checkpointer
  4. Gemini LLM receives system prompt (tone, role, threshold) + conversation history
  5. LLM decides whether to respond directly or call a tool:
    • search_knowledge_base β†’ Vector search on MongoDB Atlas β†’ Returns relevant docs
    • capture_user_details β†’ Saves visitor name/email β†’ Emits socket event
    • escalate_to_human β†’ Sets status to waiting β†’ Notifies dashboard agents
  6. Tool results loop back to LLM via toolsCondition edge
  7. Final response saved as AI message β†’ returned to widget

Conversation States

πŸ€– ai  ──►  ⏳ waiting  ──►  πŸ‘¨β€πŸ’Ό human  ──►  βœ… resolved
  β–²                                              β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                (return to AI / continue chat)

🧩 Embed the Widget

Add this to any website:

<script
  src="https://your-domain.com/widget/loader.js"
  data-workspace-id="ws_xxxxx"
  async
></script>

The widget loads in an iframe and communicates via server actions (AI mode) and Socket.IO (human mode).


πŸ“„ License

MIT


Built with ❀️ by Sunil Maharana

About

An intelligent help desk that lets businesses deploy a customizable AI chat widget on their website.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages