A full-stack AI chat platform powered by LangChain, built for Indian developers.
Chat Codebhaiya is a production-grade AI chat application with real-time streaming, multi-model support, and multimodal file analysis. It's built with a clean monorepo structure — a Next.js 16 frontend and a Node.js/Express backend — and is designed to make AI accessible to Indian developers with support for both English and Hinglish (Hindi+English mix).
The platform intelligently auto-selects the best AI model for each query, supports web search grounding, and allows users to attach images, audio, PDFs, and code files directly in chat.
| Feature | Description |
|---|---|
| 🔄 Real-Time Streaming | Token-by-token streaming via Server-Sent Events (SSE) |
| 🤖 Multi-Model AI | Groq (Llama), Google Gemini, OpenAI GPT, Ollama Cloud |
| ⚡ Auto Model Selection | Automatically picks the right model based on query complexity |
| 🌐 Web Search Grounding | AI can search the web for up-to-date information |
| 📎 Multimodal Uploads | Images, audio, PDFs, and code files (up to 10 MB) |
| 📄 PDF Export | Export any chat conversation as a styled PDF |
| 🇮🇳 Hinglish Mode | AI responds in a friendly mix of Hindi and English |
| 🔐 JWT Auth | Secure access/refresh token pair with 15-min access expiry |
| 🌗 Dark / Light Theme | User-level theme preference persisted in MongoDB |
| ♾️ Infinite Scroll | Cursor-based paginated message loading |
chat.codebhaiya/
├── web/ # Next.js 16 Frontend
│ └── src/
│ ├── app/ # App Router (routes, layouts, pages)
│ ├── components/
│ │ ├── chat/ # Chat UI (sidebar, composer, messages)
│ │ └── ui/ # shadcn/ui base components
│ └── lib/ # Shared utilities & API client
│
├── server/ # Express 5 REST API
│ └── src/
│ ├── config/ # Environment validation (Zod)
│ ├── lib/ # DB, LangChain agents, model registry
│ ├── middleware/ # JWT authentication
│ ├── models/ # Mongoose schemas (User, Chat, Message)
│ ├── routes/ # auth, chat, upload
│ └── services/ # Business logic (auth, search, messages)
│
├── docker-compose.yml # Local MongoDB
└── architecture.md # Detailed system design doc
Browser → Next.js (SSR/Client) → Express API → LangChain Agent
↓
Model Registry (Groq / Gemini / OpenAI / Ollama)
↓
[optional] Ollama Web Search
↓
SSE stream → Browser
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 16 | App Router, SSR, routing |
| React | 19 | UI rendering |
| TypeScript | 5 | Type safety |
| Tailwind CSS | 4 | Utility-first styling |
| shadcn/ui | 3 | Component library |
| Framer Motion | 12 | Animations |
| react-markdown | 10 | Markdown rendering |
| react-syntax-highlighter | 16 | Code block highlighting |
| Lucide React | 0.5 | Icon set |
| react-hot-toast | 2 | Toast notifications |
| Technology | Version | Purpose |
|---|---|---|
| Node.js | 18+ | Runtime |
| Express | 5 | REST API framework |
| TypeScript | 5 | Type safety |
| LangChain | 1.x | LLM orchestration & agent framework |
| MongoDB / Mongoose | 9 | Database & ODM |
| bcrypt | 6 | Password hashing |
| jsonwebtoken | 9 | JWT auth |
| multer | 2 | File uploads |
| pdf-parse | 1 | PDF text extraction |
| pdfkit | 0.17 | PDF generation |
| Zod | 4 | Schema validation |
| Provider | Models | Capabilities |
|---|---|---|
| Groq | Llama 3.3 70B, Llama 3.1 8B | Fast text inference |
| Gemini 2.5 Flash | Vision, audio, multimodal | |
| OpenAI | GPT-5 Nano | Vision, audio, multimodal |
| Ollama Cloud | GLM-5, Kimi K2.5 | Vision, large context |
- Node.js 18+
- pnpm 10+
- Docker (for local MongoDB) or a MongoDB Atlas connection string
- At least one LLM API key (Groq is recommended — it has a free tier)
git clone https://github.com/abhinayjangde/chat.codebhaiya.git
cd chat.codebhaiyadocker compose up -d mongodbcd server
cp .env.example .envEdit server/.env and fill in your keys:
# Server
PORT=9000
CORS_ORIGINS=http://localhost:3000
# Database
MONGODB_URL=mongodb://abhinayjangde:abhinayjangde@localhost:27017/chatbhaiya?authSource=admin
# Auth — use any 32+ character random strings
JWT_SECRET=replace_with_a_long_random_secret_at_least_32_chars
JWT_REFRESH_SECRET=replace_with_another_long_random_secret_32_chars
JWT_ACCESS_EXPIRY=15m
JWT_REFRESH_EXPIRY=7d
# LLM — add at least one
GROQ_API_KEY=gsk_...
OPENAI_API_KEY=sk-...
GOOGLE_API_KEY=...
OLLAMA_API_KEY=...cd ../web
cp .env.example .env.local # or create .env.local manuallyNEXT_PUBLIC_API_URL=http://localhost:9000Open two terminals:
Terminal 1 — Backend:
cd server
pnpm install
pnpm dev
# → Server running at http://localhost:9000Terminal 2 — Frontend:
cd web
pnpm install
pnpm dev
# → App running at http://localhost:3000One of the standout features of Chat Codebhaiya is its intelligent model router. When the model is set to Auto (default), the backend:
- Detects attachments — if images or audio are present, it immediately routes to a multimodal-capable model.
- Checks message length — messages over 1,000 characters are sent to a heavy model.
- Classifies intent — a cheap/fast model is invoked first to classify the query as
SIMPLEorCOMPLEX:SIMPLE→ routed to the cheapest available model (e.g. Llama 3.1 8B on Groq)COMPLEX→ routed to the best available heavy model (e.g. Llama 3.3 70B or Gemini 2.5 Flash)
- Falls back gracefully — if classification fails, keyword heuristics are applied.
Available models are determined at runtime based on which API keys are present in server/.env. You only need one key for the app to work.
Base URL: http://localhost:9000/api
Authentication uses Bearer <access_token> in the Authorization header.
| Method | Endpoint | Auth | Description |
|---|---|---|---|
GET |
/health |
— | Health & DB status |
POST |
/auth/register |
— | Create account |
POST |
/auth/login |
— | Get tokens |
POST |
/auth/refresh |
— | Rotate tokens |
POST |
/auth/logout |
✓ | Invalidate session |
GET |
/auth/me |
✓ | Current user |
PUT |
/auth/password |
✓ | Change password |
DELETE |
/auth/account |
✓ | Delete account |
GET |
/chat/models |
— | Available AI models |
GET |
/chat |
✓ | List user's chats |
POST |
/chat |
✓ | Create new chat |
GET |
/chat/:id/messages |
✓ | Paginated messages |
POST |
/chat/:id |
✓ | Send message (sync) |
POST |
/chat/:id/stream |
✓ | Send message (SSE stream) |
PATCH |
/chat/:id |
✓ | Rename chat |
DELETE |
/chat/:id |
✓ | Delete chat + messages |
GET |
/chat/:id/pdf |
✓ | Export chat as PDF |
POST |
/upload |
✓ | Upload file attachment |
See
server/API.mdfor full request/response schemas.
The /api/upload endpoint handles multimodal attachments with a 10 MB size limit.
| File Type | Handling |
|---|---|
Images (jpg, png, webp) |
Converted to base64 and sent as image_url to the model |
Audio (mp3, wav, etc.) |
Converted to base64 and sent as audio media to the model |
| PDFs | Text extracted with pdf-parse and appended as document context |
Code / Text (.py, .ts, .js, .c, .md, .csv, .log, etc.) |
Read as UTF-8 and appended as document context |
Register / Login
↓
{ accessToken (15 min), refreshToken (7 days) }
↓
Client stores tokens
↓
API requests → Authorization: Bearer <accessToken>
↓
When expired → POST /auth/refresh with refreshToken
↓
New token pair issued
Passwords are hashed with bcrypt (12 salt rounds). Tokens are signed with HS256 using separate secrets for access and refresh.
{
_id: ObjectId;
email: string; // unique, indexed, lowercase
password: string; // bcrypt hashed, never returned in queries
name: string; // 2–50 chars
preferences: {
theme: "light" | "dark";
defaultModel: string;
};
createdAt: Date;
updatedAt: Date;
}{
_id: ObjectId;
userId: ObjectId; // owner reference
title: string; // AI-generated from first message
createdAt: Date;
updatedAt: Date;
}{
_id: ObjectId;
chatId: ObjectId;
userId: ObjectId;
role: "user" | "assistant";
content: string;
modelName?: string; // which model generated this response
attachments?: Attachment[];
sources?: SearchResult[]; // web search citations
usedTools?: ToolCall[]; // tool execution trace
createdAt: Date;
}| Route | Description |
|---|---|
/ |
Landing page — animated hero with feature showcase |
/login |
Sign in with email & password |
/register |
Create a new account |
/forgot-password |
Password recovery flow |
/chat |
Main chat interface (requires auth) |
The chat interface features:
- Collapsible sidebar — chat history, new chat, rename, delete
- Model selector — switch between available models mid-conversation
- Language toggle — English / Hinglish response mode
- Composer — rich input with drag-and-drop file attachment
- Streaming messages — live token display with source citation cards
- Syntax highlighting — code blocks with copy button
- Dark / Light mode — toggleable via the navbar
cd web && pnpm lint# Backend
cd server && pnpm build && pnpm start
# Frontend
cd web && pnpm build && pnpm startcd server && pnpm smoke:test| Command | Where | What it does |
|---|---|---|
pnpm dev |
web/ |
Next.js dev server (port 3000) |
pnpm build |
web/ |
Production Next.js build |
pnpm lint |
web/ |
ESLint (next + TS rules) |
pnpm dev |
server/ |
tsc-watch + auto-restart (port 9000) |
pnpm build |
server/ |
Compile TS → dist/ |
pnpm start |
server/ |
Run compiled dist/index.js |
docker compose up -d mongodb |
root | Start local MongoDB |
- The server includes a keep-alive self-ping mechanism (
server/src/lib/keep-alive.ts) to prevent the API from sleeping on free-tier hosting (e.g. Render). Set theRENDER_EXTERNAL_URLenv variable to enable it. - CORS origins are validated as a Set for O(1) lookup; configure
CORS_ORIGINSas a comma-separated list. - The
/healthendpoint returns503when MongoDB is disconnected — suitable for use as a load-balancer health check.
- Fork the repository
- Create a feature branch:
git checkout -b feat/my-feature - Follow the coding style — 2-space indent, TypeScript strict, role-based file suffixes
- Run
pnpm lintandpnpm buildin bothweb/andserver/before committing - Use short, lowercase, imperative commit messages:
add streaming support - Open a PR with a clear summary, verification steps, and screenshots for UI changes
This project is open source and available under the MIT License.
Built with ❤️ by Abhinay Jangde