Skip to content

tusharg007/Cortex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CortexAI

A full-stack, multi-agent AI workspace for chat, research, code generation, document creation, and multimodal retrieval

CortexAI abstract layered graphic

CortexAI is a portfolio-scale AI engineering project built around a LangGraph supervisor that routes requests to specialized agents. A React workspace provides authenticated conversations, agent selection, file upload, Markdown responses, code artifacts, and billing controls. Behind it, an API gateway coordinates independently packaged Node.js services for authentication, chat persistence, agent execution, and payments.

Project status: The core application and deployment assets are implemented. The repository includes service-level Dockerfiles, a Redis Compose configuration, environment-based configuration, and production build scripts. The final cloud deployment, production environment wiring, and live URL are intentionally pending and planned as the next milestone. Until then, the complete system can be reproduced locally with the provider credentials described below.

Why this project is relevant to AI engineering

  • Agent orchestration: a LangGraph state machine routes explicit or automatically classified requests to task-specific agents.
  • Retrieval-augmented generation: uploaded PDFs are parsed, chunked, embedded, indexed in Qdrant, and queried for grounded answers.
  • Multimodal workflows: the system accepts images for Gemini-based vision analysis and PDFs for document question answering.
  • Tool and model routing: Groq, Gemini, OpenRouter, Tavily, and Pollinations are used for different workload profiles.
  • Conversation memory: recent history is cached in Redis and backed by persisted MongoDB conversations.
  • Generated artifacts: code projects, PDFs, presentations, and images are returned through an artifact-aware UI; binary outputs use S3 and presigned links.
  • Platform concerns: Firebase authentication, gateway-level session validation, rate limits, credit accounting, and Razorpay payment flows are separated from agent logic.

Implemented capabilities

Capability Implementation
General assistant Conversational responses with persisted history and Redis-backed memory
Web research Tavily search followed by an LLM response path
Coding assistant Intent-aware generation, review, explanation, debugging, and structured multi-file artifacts
PDF generation LLM-authored content rendered with PDFKit and stored in S3
Presentation generation Structured slide content rendered to .pptx with PptxGenJS and stored in S3
Image generation Prompt enhancement plus generated-image retrieval and S3 delivery
Vision Image upload and analysis using a multimodal Gemini model
PDF RAG PDF parsing, recursive chunking, Google embeddings, Qdrant similarity search, and grounded generation
Authentication Google sign-in through Firebase, Firebase Admin token verification, and Redis sessions
Billing Razorpay order and signature-verification flow with plan and credit updates
Frontend workspace Responsive chat UI, conversation sidebar, voice input, Markdown/code rendering, Monaco artifact viewer, and sandboxed HTML preview

Architecture

flowchart LR
    UI["React + Vite workspace"] -->|"HTTP + session cookie"| GW["Express API gateway :8000"]

    GW --> AUTH["Auth service :8001"]
    GW --> CHAT["Chat service :8002"]
    GW --> AGENT["Agent service :8003"]
    GW --> BILLING["Billing service :8004"]

    AUTH --> MONGO[(MongoDB)]
    CHAT --> MONGO
    AGENT --> MONGO
    BILLING --> MONGO

    GW --> REDIS[(Redis)]
    AUTH --> REDIS
    AGENT --> REDIS

    AGENT --> GRAPH["LangGraph supervisor"]
    GRAPH --> SPECIALISTS["Chat / Search / Code / PDF / PPT / Image / Vision / PDF RAG"]
    SPECIALISTS --> MODELS["Groq / Gemini / OpenRouter"]
    SPECIALISTS --> TOOLS["Tavily / Qdrant / S3 / Pollinations"]
    BILLING --> RAZORPAY["Razorpay"]
    AUTH --> FIREBASE["Firebase Auth"]
Loading

Request flow

  1. The React client authenticates with Google through Firebase and sends the ID token to the auth service.
  2. The auth service verifies the token, creates or retrieves the user, and stores a session in Redis.
  3. The gateway validates the session and forwards the user identity to the appropriate internal service.
  4. The agent service invokes the LangGraph supervisor, which respects an explicitly selected agent or automatically routes the request.
  5. The selected agent calls its model/tool dependencies and returns text, images, or structured artifacts.
  6. Conversation messages are persisted in MongoDB and cached in Redis for subsequent context.

Technology stack

Layer Technologies
Frontend React 19, Vite, Redux Toolkit, Tailwind CSS, Framer Motion, Monaco Editor, React Markdown
API and services Node.js, Express 5, gateway proxying, Multer
Agent system LangGraph, LangChain, Groq, Gemini, OpenRouter
Retrieval and tools Qdrant, Google embeddings, Tavily, PDF Parse
Data and cache MongoDB/Mongoose, Redis/ioredis
Generated files PDFKit, PptxGenJS, AWS S3 presigned URLs
Identity and payments Firebase Authentication, Firebase Admin, Razorpay
Deployment assets Dockerfiles for all five backend services and Docker Compose for Redis

Repository structure

cortex-ai/
|-- frontend/                    # React/Vite client
|   |-- src/components/          # Chat, navigation, billing, and artifact UI
|   |-- src/features/            # API adapters
|   |-- src/redux/               # Client state
|   `-- firebase.js              # Firebase web-client initialization
|-- backend/
|   |-- gateway/                 # Public API gateway and session middleware
|   |-- services/
|   |   |-- auth/                # Firebase verification, users, Redis sessions
|   |   |-- chat/                # Conversations and messages
|   |   |-- agent/               # LangGraph and specialized AI agents
|   |   `-- billing/             # Razorpay and plan/credit updates
|   |-- shared/redis/            # Shared Redis client
|   `-- docker-compose.yml       # Local Redis service
`-- README.md

Local reproduction

1. Prerequisites

  • Node.js 22.x (the project was verified with Node 22.21.0)
  • npm 10 or newer
  • Docker Desktop with Docker Compose, or a separately installed Redis server
  • A MongoDB instance (local MongoDB or MongoDB Atlas)
  • Provider accounts/credentials for Firebase, Groq, Google AI, OpenRouter, Tavily, Qdrant, AWS S3, and Razorpay

The base chat path needs MongoDB, Redis, Firebase, and the configured LLM provider. Search, PDF RAG, generated-file, and billing features additionally require their corresponding external services.

2. Clone the private repository

git clone https://github.com/tusharg007/Cortex.git
cd cortex-ai

Because the repository is private, GitHub access must first be granted to the GitHub account performing the clone.

3. Install dependencies

Each service has its own lockfile and is intentionally installed independently.

cd backend
npm ci

cd gateway && npm ci && cd ..
cd services/auth && npm ci && cd ../..
cd services/chat && npm ci && cd ../..
cd services/agent && npm ci && cd ../..
cd services/billing && npm ci && cd ../../..

cd frontend
npm ci
cd ..

On Windows PowerShell, use npm.cmd in place of npm if script execution policy blocks npm.ps1.

4. Configure environment files

Create the following local files. They are deliberately ignored by Git and must never be committed.

frontend/.env

VITE_FIREBASE_API_KEY=<firebase-web-api-key>
VITE_SERVER_URL=http://localhost:8000
VITE_RAZORPAY_KEY=<razorpay-public-key-id>

backend/gateway/.env

PORT=8000
REDIS_URL=redis://127.0.0.1:6379
AUTH_SERVICE=http://localhost:8001
CHAT_SERVICE=http://localhost:8002
AGENT_SERVICE=http://localhost:8003
BILLING_SERVICE=http://localhost:8004

backend/services/auth/.env

PORT=8001
MONGODB_URL=mongodb://127.0.0.1:27017/cortex_auth
FRONTEND_URL=http://localhost:5173
REDIS_URL=redis://127.0.0.1:6379

backend/services/chat/.env

PORT=8002
MONGODB_URL=mongodb://127.0.0.1:27017/cortex_chat

backend/services/agent/.env

PORT=8003
MONGODB_URL=mongodb://127.0.0.1:27017/cortex_agent
REDIS_URL=redis://127.0.0.1:6379

CHAT_SERVICE=http://localhost:8002
AUTH_SERVICE=http://localhost:8001
GATEWAY_URL=http://localhost:8000

GROQ_API_KEY=<groq-api-key>
GOOGLE_API_KEY=<google-ai-api-key>
OPENROUTER_API_KEY=<openrouter-api-key>
TAVILY_API_KEY=<tavily-api-key>

QDRANT_URL=<qdrant-cluster-url>
QDRANT_API_KEY=<qdrant-api-key>

AWS_ACCESS_KEY_ID=<aws-access-key-id>
AWS_SECRET_ACCESS_KEY=<aws-secret-access-key>
AWS_REGION=<aws-region>
AWS_BUCKET_NAME=<s3-bucket-name>

backend/services/billing/.env

PORT=8004
MONGODB_URL=mongodb://127.0.0.1:27017/cortex_billing
AUTH_SERVICE=http://localhost:8001
RAZORPAY_KEY_ID=<razorpay-key-id>
RAZORPAY_KEY_SECRET=<razorpay-key-secret>

REDIS_URL is consumed by the shared Redis client. Defining it for every process that imports that client keeps local and deployed configuration explicit, even where an older local file may not yet contain the key.

5. Configure Firebase authentication

  1. Create a Firebase project and web app.

  2. Enable Google in Firebase Authentication providers.

  3. Generate a Firebase Admin service-account key.

  4. Save the downloaded JSON locally as:

    backend/services/auth/serviceAccount.json
    
  5. Add http://localhost to the authorized domains in Firebase Authentication.

The service-account file is ignored by Git. Never reuse a key that has previously been committed or shared. The current frontend module reads the API key from frontend/.env; if the Firebase project requires the remaining web-app fields (authDomain, projectId, appId, and related values), complete the placeholders in frontend/firebase.js with that project's public web configuration before starting the client.

6. Start infrastructure

Start Redis from the repository root:

docker compose -f backend/docker-compose.yml up -d

Also ensure the MongoDB connection strings resolve and that the configured Qdrant collection service and S3 bucket are reachable.

7. Start backend services

Open five terminals from the repository root.

# Terminal 1 - authentication
cd backend/services/auth
npm start
# Terminal 2 - conversations
cd backend/services/chat
npm start
# Terminal 3 - AI agents
cd backend/services/agent
npm start
# Terminal 4 - billing
cd backend/services/billing
npm start
# Terminal 5 - public API gateway
cd backend/gateway
npm start

Expected local ports are 8000 through 8004. A gateway health request should return a JSON response:

curl http://localhost:8000/

8. Start the frontend

cd frontend
npm run dev

Open http://localhost:5173, sign in with an authorized Google account, and create a conversation.

9. Optional local checks

# Production frontend build
cd frontend
npm run build

# Backend JavaScript syntax check (PowerShell, from the repository root)
$files = rg --files backend -g '*.js' -g '!**/node_modules/**'
foreach ($file in $files) { node --check $file }

# Validate the Redis Compose definition
docker compose -f backend/docker-compose.yml config

API surface

All browser-facing requests enter through the gateway at http://localhost:8000.

Route group Purpose
/api/auth/* Login and logout through the auth service
/api/me Read the Redis-backed authenticated user session
/api/chat/* Create, list, update, and read conversations/messages
/api/agent/chat Submit prompts, selected agent type, and optional PDF/image files
/api/billing/* Create and verify Razorpay orders

Verification snapshot

Validated locally on July 15, 2026:

  • Frontend production build: passed (vite build, 3,137 modules transformed)
  • Backend syntax validation: passed (52 JavaScript files checked with node --check)
  • Docker Compose configuration: passed for the Redis service
  • Frontend lint: not yet clean (existing unused-import, hook-dependency, and nested-component findings)
  • End-to-end provider integration: requires valid private credentials and was not claimed as part of this repository-only verification

There is currently no automated backend test suite. This repository should be evaluated as a substantial, locally runnable engineering prototype, not as a claim of a production-operated SaaS.

Deployment readiness and remaining milestone

The repository already contains the core inputs needed to package the backend services:

  • independent service manifests and lockfiles;
  • Dockerfiles for the gateway, auth, chat, agent, and billing services;
  • a Redis Compose definition;
  • environment-based provider and service configuration;
  • a Vite production build for the frontend;
  • root secret-exclusion rules for GitHub publication.

The remaining deployment milestone is to provision the managed services, inject production secrets, publish images/static assets, connect the public domains, update the gateway CORS and cookie policy for HTTPS, add production health checks, and run an end-to-end smoke test. A live URL will be added only after those checks pass.

Security notes

  • .env files and backend/services/auth/serviceAccount.json are intentionally excluded from version control.
  • Rotate any credential that has ever been pasted into a terminal, shared, or committed to another repository.
  • Use separate development and production Firebase, Razorpay, AWS, MongoDB, and Qdrant credentials.
  • Treat internal service routes as private network endpoints in production.
  • The current local cookie and CORS settings are development-oriented and must be hardened for the final HTTPS deployment.

Current limitations

  • Final cloud hosting and a public live URL are pending.
  • The provided Compose file currently starts Redis only; application services are packaged with individual Dockerfiles.
  • Firebase web configuration may require completing the remaining public app fields for a newly created Firebase project.
  • Frontend lint findings and automated integration tests remain pre-deployment quality work.
  • External AI, search, payment, vector-database, and object-storage behavior depends on the configured third-party services and their quotas.

Resume-safe project summary

Built a full-stack multi-agent AI workspace using React, Node.js microservices, LangGraph, Redis, MongoDB, and Qdrant; implemented task routing across chat, web search, coding, document generation, vision, and PDF-RAG workflows, with Firebase authentication, S3 artifact delivery, rate/credit controls, and Razorpay billing integration.

This summary describes functionality present in the repository. It does not imply public production traffic, uptime, user counts, or a completed live deployment.

About

Full-stack multi-agent AI workspace with LangGraph supervision, Qdrant PDF RAG, Redis memory, multimodal workflows and artifact generation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors