CortexAI is a full-stack multi-agent AI workspace with a React frontend and a Node.js microservice backend.
It supports:
- Google login (Firebase)
- Multi-conversation chat history
- Agent routing (chat, coding, search, pdf, ppt, vision)
- PDF/image upload workflows
- Artifact preview for generated code (Monaco + live iframe)
- Credit-based billing with Razorpay
CortexAI/
├── frontend/ # React + Vite client
├── backend/
│ ├── gateway/ # API gateway + auth middleware + proxy
│ ├── services/
│ │ ├── auth/ # Login/session + user credits
│ │ ├── chat/ # Conversations + messages
│ │ ├── agent/ # LangGraph orchestration + AI agents
│ │ └── billing/ # Razorpay order/payment verification
│ ├── shared/redis/ # Shared Redis client
│ └── docker-compose.yml # Redis container
└── README.md
flowchart LR
UI[React Frontend] --> GW[Gateway Service]
GW -->|/api/auth| AUTH[Auth Service]
GW -->|/api/chat| CHAT[Chat Service]
GW -->|/api/agent| AGENT[Agent Service]
GW -->|/api/billing| BILLING[Billing Service]
AUTH --> MONGO[(MongoDB)]
CHAT --> MONGO
AGENT --> MONGO
BILLING --> MONGO
GW --> REDIS[(Redis)]
AUTH --> REDIS
AGENT --> REDIS
AGENT --> TAVILY[Tavily Search]
AGENT --> QDRANT[Qdrant Vector Store]
AGENT --> S3[AWS S3]
AGENT --> LLM[LLM Providers]
BILLING --> RAZORPAY[Razorpay]
BILLING --> AUTH
- Entry point for frontend API traffic.
- Uses
cookie-parser,cors,morgan, andexpress-http-proxy. - Routes:
/api/auth-> Auth service/api/chat-> Chat service (protected)/api/agent-> Agent service (protected)/api/billing-> Billing service (protected)/api/me-> returns user from session (protected)
- Protection middleware reads
sessioncookie, resolvessession-<id>from Redis, and injectsreq.user. - For protected proxy calls, forwards
x-user-idheader to downstream services.
- Verifies Firebase ID token (
firebase-admin). - Creates/loads user in MongoDB.
- Creates Redis-backed session and sets
sessioncookie. - Maintains plan + credits.
- Endpoints:
POST /loginGET /logoutPOST /update-planPOST /deduct-credits
- Stores conversations and messages in MongoDB.
- Endpoints:
GET /create-conversationGET /get-conversationsPOST /update-conversationPOST /save-messageGET /get-messages/:conversationId
- Runs LangGraph state machine.
- Main endpoint:
POST /chat(multer.single("file")) - Supported upload types: PDF and images (max 20MB).
routerchatsearchcodingpdfpptvisionpdfRagimageAnalyzer
Routing behavior:
- If explicit agent is passed (not
auto), it is used. - If file is PDF ->
pdfRag. - If file is image ->
imageAnalyzer. - Otherwise router LLM classifies prompt.
Special edge:
search -> chatso search results are passed into chat response synthesis.
Other flows in Agent service:
- Loads/stores short conversation memory in Redis (
messages-<conversationId>). - Persists user + assistant messages via Chat service API.
- Deducts credits through Auth service.
- Creates Razorpay orders for plan upgrades.
- Verifies payment signature.
- Stores payment record in MongoDB.
- Calls Auth service
/update-planafter successful payment. - Endpoints:
POST /createPOST /verify
- React 19 + Vite + Tailwind CSS v4.
- Global state via Redux Toolkit slices:
userSliceconversationSlicemessageSlice
- Main layout:
SideBar(sessions, profile, billing)ChatArea(header, messages, input)Artifactpanel (Monaco + preview iframe)
- On app load, calls
/api/meto restore logged-in session. - If no user, shows Google login overlay.
- Creates/selects conversation.
- Sends prompt (and optional file) to
/api/agent/chat. - Renders assistant response, images, and artifacts.
- Artifact panel previews generated code (
index.html,style.css,script.js) with responsive viewport modes.
- User signs in with Google in frontend.
- Frontend sends Firebase token to
POST /api/auth/login. - Auth service verifies token, upserts user, creates Redis session, sets cookie.
- Gateway uses cookie for protected routes and
/api/me.
- Frontend creates or selects a conversation.
- Frontend sends
prompt,conversationId,agent, and optionalfile. - Agent service stores user message.
- LangGraph routes to correct agent.
- Agent executes tools/models (search, generation, RAG, image, etc.).
- Credits are deducted.
- Agent stores assistant message.
- Response returns to frontend.
- Frontend opens billing drawer and selects plan.
POST /api/billing/createcreates Razorpay order.- Razorpay checkout completes and returns payment details.
- Frontend calls
POST /api/billing/verify. - Billing verifies signature, marks payment paid, calls Auth service
/update-plan. - User plan and credits are updated.
Credit deduction (auth.controller.js):
chat: 1search: 5coding: 10pdf: 10ppt: 10vision: 10
Rate limits (per user/agent, 60s Redis window, agentLimit.js):
chat: 20coding: 5pdf: 5ppt: 5image: 5search: 5
Create .env files for each service (gateway, services/auth, services/chat, services/agent, services/billing) and for frontend/.env.
PORTFRONTEND_URLAUTH_SERVICECHAT_SERVICEAGENT_SERVICEBILLING_SERVICEREDIS_URL
PORTMONGODB_URIREDIS_URL- Firebase Admin credentials file at
backend/services/auth/serviceAccountKey.json
PORTMONGODB_URI
PORTMONGODB_URICHAT_SERVICEAUTH_SERVICEQDRANT_URLTAVILY_API_KEYGOOGLE_API_KEYGROQ_API_KEYOPENROUTER_API_KEYAWS_REGIONAWS_ACCESS_KEY_IDAWS_SECRET_KEYAWS_BUCKET_NAME
PORTMONGODB_URIAUTH_SERVICERAZORPAY_KEY_IDRAZORPAY_KEY_SECRET
VITE_SERVER_URLVITE_FIREBASE_API_KEYVITE_RAZORPAY_KEY_ID
From backend/:
docker compose up -d# frontend
cd frontend
npm install
# backend services
cd ../backend/gateway && npm install
cd ../services/auth && npm install
cd ../chat && npm install
cd ../agent && npm install
cd ../billing && npm install# gateway
cd backend/gateway && npm run dev
# auth
cd backend/services/auth && npm run dev
# chat
cd backend/services/chat && npm run dev
# agent
cd backend/services/agent && npm run dev
# billing
cd backend/services/billing && npm run dev
# frontend
cd frontend && npm run devbackend/services/auth/serviceAccountKey.jsonshould be treated as sensitive and should not be committed with real credentials.- Temporary uploads in Agent service are stored in
backend/services/agent/tempand deleted after processing for PDF/image analysis flows.