How ayushgupta2408/brain works
Purpose and entry points
Brain is a MERN multi-agent AI chat platform. It accepts authenticated user prompts and runs them through a staged AI pipeline, streaming progress and results back to the client. Backend startup and HTTP composition are in backend/server.js; the React/Vite client starts from frontend/src/main.jsx and frontend/src/App.jsx.
Client application
The frontend provides authentication, chat interaction, and live pipeline visibility. frontend/src/pages/ChatPage.jsx composes the main chat experience; frontend/src/components/ChatWindow.jsx handles conversation display/input, while frontend/src/components/AgentPipeline.jsx renders stage-by-stage status from server-sent events. Redux state separates auth and chat concerns in frontend/src/store/authSlice.js and frontend/src/store/chatSlice.js.
API, identity, and persistence boundary
Express routes expose registration/login and chat endpoints through backend/src/routes/authRoutes.js and backend/src/routes/chatRoutes.js. JWT validation is centralized in backend/src/middleware/auth.js, protecting chat operations. MongoDB persists user accounts and chat history through backend/src/models/User.js and backend/src/models/Chat.js, with connection setup in backend/src/config/db.js.
Agent orchestration pipeline
backend/src/agents/orchestrator.js is the central control-flow boundary: it carries request state through Planner → Retriever → Coder → Executor → Reviewer and emits each stage’s progress for SSE consumers. The stages are implemented in backend/src/agents/planner.js, backend/src/agents/retriever.js, backend/src/agents/coder.js, backend/src/agents/executor.js, and backend/src/agents/reviewer.js. Groq-backed LLM access and model selection are isolated in backend/src/config/groq.js.
Retrieval and cache layers
The Retriever obtains contextual material through the vector-store abstraction in backend/src/rag/vectorStore.js. Qdrant integration is encapsulated by backend/src/rag/qdrantClient.js; the application can use an in-memory cosine-similarity fallback when Qdrant is unavailable. Redis connectivity, caching, and fixed-window rate-limit support are centralized in backend/src/config/redis.js, also with in-memory degradation. Repeated query pipeline results are cacheable independently of Mongo conversation persistence.
Specialized output modes and execution
The Executor runs JavaScript extracted from generated drafts in a demo-grade in-process vm2 sandbox (backend/src/agents/executor.js), bounded by a timeout. Output formatting supports generation of PowerPoint artifacts via backend/src/agents/formatter.js, with produced files represented under backend/generated/. Image-oriented requests are delegated to Pollinations.ai through backend/src/agents/imageProvider.js; this is an external anonymous, rate-limited service.
Runtime and deployment
The runtime is Node.js/Express plus React 18/Vite. Docker definitions for each application tier live in backend/Dockerfile and frontend/Dockerfile; docker-compose.yml provisions the full local stack, including MongoDB, Redis, and Qdrant. Required operational secrets include Groq API credentials and JWT configuration; MongoDB is the durable system of record, while Redis and Qdrant are optional accelerators due to fallbacks.
Main entry points: orchestrator.js Orchestrator · server.js Express server · ChatPage.jsx Chat page · ChatWindow.jsx Chat window
Components 22
React client
- React/Vite app
frontend/src/main.jsx - Chat page
frontend/src/pages/ChatPage.jsx - Chat window
frontend/src/components/ChatWindow.jsx - Pipeline status
frontend/src/components/AgentPipeline.jsx - Chat state
frontend/src/store/chatSlice.js
Express API
- Express server
backend/server.js - Auth routes
backend/src/routes/authRoutes.js - Chat routes
backend/src/routes/chatRoutes.js - JWT middleware
backend/src/middleware/auth.js
Agent pipeline
- Orchestrator · Carries request state and emits stage progress.
backend/src/agents/orchestrator.js - Planner
backend/src/agents/planner.js - Retriever
backend/src/agents/retriever.js - Coder
backend/src/agents/coder.js - Executor · Runs extracted JavaScript with a timeout.
backend/src/agents/executor.js - Reviewer
backend/src/agents/reviewer.js - Groq access
backend/src/config/groq.js - Artifact formatter · Produces files under backend/generated/.
backend/src/agents/formatter.js - Image provider
backend/src/agents/imageProvider.js
Data and acceleration
- Mongo models
backend/src/models/User.js - Vector store
backend/src/rag/vectorStore.js - Qdrant client · Falls back to in-memory cosine similarity.
backend/src/rag/qdrantClient.js - Redis layer · Falls back to in-memory storage.
backend/src/config/redis.js
Connections 23
- React/Vite app → Chat page: renders
- Chat page → Chat window: composes
- Chat page → Pipeline status: composes
- Chat window → Chat state: reads and updates
- Chat window → Express server: authenticated chat requests
- Pipeline status → Express server: consumes SSE progress
- Express server → Auth routes: mounts
- Express server → Chat routes: mounts
- Auth routes → Mongo models: stores accounts
- Chat routes → JWT middleware: requires
- JWT middleware → Orchestrator: authorizes pipeline
- Chat routes → Mongo models: persists conversations
- Orchestrator → Planner: plans
- Planner → Retriever: queries context
- Retriever → Vector store: retrieves context
- Vector store → Qdrant client: uses when available
- Retriever → Coder: supplies context
- Coder → Executor: sends generated code
- Executor → Reviewer: returns execution result
- Orchestrator → Groq access: invokes LLM
- Reviewer → Artifact formatter: formats artifacts
- Orchestrator → Image provider: delegates image requests
- Orchestrator → Redis layer: caches repeated results