How apna-college/sigmagpt works
Project Type and Purpose
• SigmaGPT is a full-stack MERN (MongoDB, Express, React, Node.js) application that replicates ChatGPT functionality by proxying requests to OpenAI’s API.
• The goal is to provide a web-based chat interface, store and retrieve conversation threads, and orchestrate OpenAI calls from the backend.
File Structure
• Top-level folders:
• Backend – an Express server with routes, Mongoose models, and OpenAI helper
• Frontend – a React/Vite single-page application
• Backend details:
• server.js – entry point, sets up Express, connects to MongoDB, loads routes
• /routes/chat.js – REST API endpoints for messaging and thread retrieval
• /models/Thread.js – Mongoose schema to persist conversation history
• /utils/openai.js – wrapper around OpenAI client configuration and calls
• Frontend details:
• src/App.jsx, Chat.jsx, ChatWindow.jsx, Sidebar.jsx – core React components
• src/MyContext.jsx – React Context for shared state (current thread, messages)
• public/index.html + vite.config.js – bootstrapping the dev/build environment
• Config & deployment files:
• package.json in both layers, .gitignore, ESLint config – standard JS build/tooling
Extract Insights from the README
• Confirms MERN stack and OpenAI integration
a. Frontend (React SPA)
• Chat UI components (Sidebar, ChatWindow)
• State management (React Context)
• HTTP client to backend API
b. Backend (Express API Server)
• API Layer (chat route handlers)
• Business Logic (openai.js)
• Data Layer (Thread model with MongoDB)
c. Database (MongoDB Atlas or local MongoDB)
d. External Service (OpenAI API)
e. Deployment/Hosting (optional: Vercel/Netlify for frontend, Heroku/AWS for backend)
Relationships and Data Flows
• Frontend → Backend: HTTP POST for new messages, GET for thread history
• Backend → OpenAI API: REST calls with chat history, receives AI response
• Backend → Database:
• Save incoming user messages + AI replies into Thread documents
• Query Thread collection for history on client request
• Backend → Frontend: returns JSON payloads with updated thread data
Architectural Patterns & Design Principles
• Separation of concerns: UI, API, business logic, persistence
• Stateless API servers with state stored in MongoDB
• Use of React Context for client-side state propagation
• Single-page application communicating via REST endpoints
Technologies & Frameworks to Annotate
• React + Vite, React Context, CSS modules
• Node.js, Express.js, Mongoose
• OpenAI SDK
• MongoDB (with connection URI in environment variables)