# varun-reddy-2105/smart-ai-assistant architecture

> Architecture diagram of the GitHub repository varun-reddy-2105/smart-ai-assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/varun-reddy-2105/smart-ai-assistant
- Repository: https://github.com/varun-reddy-2105/smart-ai-assistant

## Overview

SigmaGPT is a MERN-based ChatGPT replica. A user starts or selects a conversation in the sidebar, sends a prompt from the chat window, and receives an OpenAI-generated reply that the backend saves with the thread in MongoDB. The sidebar also lists, loads, and deletes threads; the chat view renders message history and formats assistant replies as Markdown. The excerpts show the main UI, API, model, and provider wiring. They do not show every runtime detail, so the graph omits unsupported links and treats external services as dependencies.

Main entry points: [`Frontend/src/ChatWindow.jsx`](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/ChatWindow.jsx) (Chat window), [`Backend/routes/chat.js`](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Backend/routes/chat.js) (Chat routes), [`Frontend/src/App.jsx`](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/App.jsx) (App state), [`Frontend/src/Sidebar.jsx`](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/Sidebar.jsx) (Thread sidebar)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Chat interface"]
  node_entry["React entry<br/>[main.jsx]"]
  node_app["App state<br/>[App.jsx]"]
  node_context["Shared context<br/>[MyContext.jsx]"]
  node_sidebar["Thread sidebar<br/>[Sidebar.jsx]"]
  node_chatwindow["Chat window<br/>[ChatWindow.jsx]"]
  node_chatview["Message renderer<br/>[Chat.jsx]"]
end

subgraph group_api["Chat API"]
  node_server["Express server<br/>[server.js]"]
  node_routes["Chat routes<br/>[chat.js]"]
  node_openai_client["OpenAI client<br/>[openai.js]"]
end

subgraph group_persistence["Thread persistence"]
  node_thread_model["Thread model<br/>[Thread.js]"]
end

subgraph group_integration["External services"]
  node_mongodb[("MongoDB")]
  node_openai["OpenAI API"]
end

node_user(("User"))

node_user -->|"selects threads"| node_sidebar
node_user -->|"sends prompts"| node_chatwindow
node_entry -->|"renders"| node_app
node_app -->|"provides state"| node_context
node_app -->|"renders"| node_sidebar
node_app -->|"renders"| node_chatwindow
node_sidebar -->|"reads and updates"| node_context
node_chatwindow -->|"reads and updates"| node_context
node_chatview -->|"reads chat state"| node_context
node_chatwindow -->|"renders"| node_chatview
node_chatwindow -->|"posts chat"| node_routes
node_sidebar -->|"manages threads"| node_routes
node_server -->|"mounts at /api"| node_routes
node_server -->|"connects"| node_mongodb
node_routes -->|"queries and saves"| node_thread_model
node_routes -->|"requests reply"| node_openai_client
node_openai_client -->|"sends completion request"| node_openai

click node_entry "https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/main.jsx"
click node_app "https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/App.jsx"
click node_context "https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/MyContext.jsx"
click node_sidebar "https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/Sidebar.jsx"
click node_chatwindow "https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/ChatWindow.jsx"
click node_chatview "https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/Chat.jsx"
click node_server "https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Backend/server.js"
click node_routes "https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Backend/routes/chat.js"
click node_openai_client "https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Backend/utils/openai.js"
click node_thread_model "https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Backend/models/Thread.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_app,node_context,node_sidebar,node_chatwindow,node_chatview,node_user toneBlue
class node_server,node_routes,node_openai_client toneAmber
class node_thread_model toneMint
class node_mongodb,node_openai toneRose
```

## Components

### Chat interface

- [React entry](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/main.jsx): `Frontend/src/main.jsx`
- [App state](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/App.jsx): `Frontend/src/App.jsx`
- [Shared context](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/MyContext.jsx): `Frontend/src/MyContext.jsx`
- [Thread sidebar](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/Sidebar.jsx): `Frontend/src/Sidebar.jsx`
- [Chat window](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/ChatWindow.jsx): `Frontend/src/ChatWindow.jsx`
- [Message renderer](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Frontend/src/Chat.jsx): `Frontend/src/Chat.jsx`

### Chat API

- [Express server](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Backend/server.js): `Backend/server.js`
- [Chat routes](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Backend/routes/chat.js): `Backend/routes/chat.js`
- [OpenAI client](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Backend/utils/openai.js): `Backend/utils/openai.js`

### Thread persistence

- [Thread model](https://github.com/varun-reddy-2105/smart-ai-assistant/blob/main/Backend/models/Thread.js): `Backend/models/Thread.js`

### External services

- **MongoDB**
- **OpenAI API**

### Other components

- **User**

## Connections

- User → Thread sidebar: selects threads (evidence: `Frontend/src/Sidebar.jsx`)
- User → Chat window: sends prompts (evidence: `Frontend/src/ChatWindow.jsx`)
- React entry → App state: renders (evidence: `Frontend/src/main.jsx`)
- App state → Shared context: provides state (evidence: `Frontend/src/App.jsx`)
- App state → Thread sidebar: renders (evidence: `Frontend/src/App.jsx`)
- App state → Chat window: renders (evidence: `Frontend/src/App.jsx`)
- Thread sidebar → Shared context: reads and updates (evidence: `Frontend/src/Sidebar.jsx`)
- Chat window → Shared context: reads and updates (evidence: `Frontend/src/ChatWindow.jsx`)
- Message renderer → Shared context: reads chat state (evidence: `Frontend/src/Chat.jsx`)
- Chat window → Message renderer: renders (evidence: `Frontend/src/ChatWindow.jsx`)
- Chat window → Chat routes: posts chat (evidence: `Frontend/src/ChatWindow.jsx`)
- Thread sidebar → Chat routes: manages threads (evidence: `Frontend/src/Sidebar.jsx`)
- Express server → Chat routes: mounts at /api (evidence: `Backend/server.js`)
- Express server → MongoDB: connects (evidence: `Backend/server.js`)
- Chat routes → Thread model: queries and saves (evidence: `Backend/routes/chat.js`)
- Chat routes → OpenAI client: requests reply (evidence: `Backend/routes/chat.js`)
- OpenAI client → OpenAI API: sends completion request (evidence: `Backend/utils/openai.js`)
