# manish3-4/aichatbot architecture

> Architecture diagram of the GitHub repository manish3-4/aichatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/manish3-4/aichatbot
- Repository: https://github.com/manish3-4/aichatbot

## Overview

MERN-GPT is a React chat application with an Express API, user authentication, and MongoDB-backed accounts and conversation history. The visible login path runs from the login page through shared auth state and an Axios helper to the user API, where validation and controller logic authenticate against the User model and issue a JWT cookie. The README documents AI responses and saved-chat operations, but the chat route and page excerpts are empty or minimal, so those capabilities are shown as documented rather than verified implementations.

Main entry points: [`frontend/src/App.tsx`](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/App.tsx) (Page routing), [`backend/src/routes/user-routes.ts`](https://github.com/manish3-4/aichatbot/blob/main/backend/src/routes/user-routes.ts) (User routes), [`backend/src/routes/chat-routes.ts`](https://github.com/manish3-4/aichatbot/blob/main/backend/src/routes/chat-routes.ts) (Chat routes), [`frontend/src/main.tsx`](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/main.tsx) (React app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_webapp["React app<br/>[main.tsx]"]
  node_routing["Page routing<br/>[App.tsx]"]
  node_login["Login form<br/>[Login.tsx]"]
  node_authstate["Auth context<br/>[AuthContext.tsx]"]
  node_apihelper["API helper"]
  node_input["Form input"]
  node_header["Navigation header<br/>[index.tsx]"]
  node_home["Home page<br/>[HomePage.tsx]"]
  node_signup["Signup page<br/>[Signup.tsx]"]
end

subgraph group_backend["Backend API"]
  node_backendapp["Express app<br/>[app.ts]"]
  node_apiroutes["API router<br/>[index.ts]"]
end

subgraph group_identity["Identity and data"]
  node_userroutes["User routes<br/>[user-routes.ts]"]
  node_validation["Request validation<br/>[validators.ts]"]
  node_usercontroller["User controller<br/>[user-controller.ts]"]
  node_token["JWT creation<br/>[token-manager.ts]"]
  node_userstore[("User model<br/>[User.ts]")]
  node_dbconnection["Mongo connection<br/>[connection.ts]"]
end

subgraph group_chat["Chat capabilities"]
  node_chatui["Chat page<br/>[Chat.tsx]"]
  node_chatroutes["Chat routes<br/>[chat-routes.ts]"]
end

node_visitor(("User"))
node_mongodb[("MongoDB")]
node_openai(("OpenAI service"))

node_visitor -->|"uses"| node_webapp
node_webapp -->|"renders"| node_routing
node_webapp -->|"provides auth"| node_authstate
node_routing -->|"routes to"| node_login
node_routing -->|"routes to"| node_signup
node_routing -->|"routes to"| node_home
node_routing -->|"routes to"| node_chatui
node_routing -->|"renders"| node_header
node_login -->|"renders"| node_input
node_login -->|"calls login"| node_authstate
node_authstate -->|"calls login API"| node_apihelper
node_apihelper -->|"posts credentials"| node_userroutes
node_backendapp -->|"mounts routes"| node_apiroutes
node_apiroutes -->|"registers"| node_userroutes
node_apiroutes -->|"registers"| node_chatroutes
node_userroutes -->|"validates requests"| node_validation
node_userroutes -->|"dispatches"| node_usercontroller
node_usercontroller -->|"reads and writes"| node_userstore
node_usercontroller -->|"creates token"| node_token
node_dbconnection -->|"connects"| node_mongodb
node_userstore -.->|"persists users"| node_mongodb
node_chatui -.->|"requests chats"| node_chatroutes
node_chatroutes -.->|"gets AI responses"| node_openai
node_chatroutes -.->|"stores chat history"| node_mongodb

click node_webapp "https://github.com/manish3-4/aichatbot/blob/main/frontend/src/main.tsx"
click node_routing "https://github.com/manish3-4/aichatbot/blob/main/frontend/src/App.tsx"
click node_login "https://github.com/manish3-4/aichatbot/blob/main/frontend/src/pages/Login.tsx"
click node_authstate "https://github.com/manish3-4/aichatbot/blob/main/frontend/src/context/AuthContext.tsx"
click node_apihelper "https://github.com/manish3-4/aichatbot/blob/main/frontend/src/helpers/api-communicators.ts"
click node_input "https://github.com/manish3-4/aichatbot/blob/main/frontend/src/components/input/customizedInput.tsx"
click node_header "https://github.com/manish3-4/aichatbot/blob/main/frontend/src/components/header/index.tsx"
click node_home "https://github.com/manish3-4/aichatbot/blob/main/frontend/src/pages/HomePage.tsx"
click node_signup "https://github.com/manish3-4/aichatbot/blob/main/frontend/src/pages/Signup.tsx"
click node_chatui "https://github.com/manish3-4/aichatbot/blob/main/frontend/src/pages/Chat.tsx"
click node_backendapp "https://github.com/manish3-4/aichatbot/blob/main/backend/src/app.ts"
click node_apiroutes "https://github.com/manish3-4/aichatbot/blob/main/backend/src/routes/index.ts"
click node_userroutes "https://github.com/manish3-4/aichatbot/blob/main/backend/src/routes/user-routes.ts"
click node_chatroutes "https://github.com/manish3-4/aichatbot/blob/main/backend/src/routes/chat-routes.ts"
click node_validation "https://github.com/manish3-4/aichatbot/blob/main/backend/src/utils/validators.ts"
click node_usercontroller "https://github.com/manish3-4/aichatbot/blob/main/backend/src/controllers/user-controller.ts"
click node_token "https://github.com/manish3-4/aichatbot/blob/main/backend/src/utils/token-manager.ts"
click node_userstore "https://github.com/manish3-4/aichatbot/blob/main/backend/src/models/User.ts"
click node_dbconnection "https://github.com/manish3-4/aichatbot/blob/main/backend/src/db/connection.ts"

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_webapp,node_routing,node_login,node_authstate,node_apihelper,node_input,node_header,node_home,node_signup,node_visitor toneBlue
class node_backendapp,node_apiroutes,node_mongodb toneAmber
class node_userroutes,node_validation,node_usercontroller,node_token,node_userstore,node_dbconnection toneMint
class node_chatui,node_chatroutes toneRose
class node_openai toneIndigo
```

## Components

### Frontend

- [React app](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/main.tsx): `frontend/src/main.tsx`
- [Page routing](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Login form](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/pages/Login.tsx): `frontend/src/pages/Login.tsx`
- [Auth context](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [API helper](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/helpers/api-communicators.ts): `frontend/src/helpers/api-communicators.ts`
- [Form input](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/components/input/customizedInput.tsx): `frontend/src/components/input/customizedInput.tsx`
- [Navigation header](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/components/header/index.tsx): `frontend/src/components/header/index.tsx`
- [Home page](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/pages/HomePage.tsx): `frontend/src/pages/HomePage.tsx`
- [Signup page](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/pages/Signup.tsx): `frontend/src/pages/Signup.tsx`

### Backend API

- [Express app](https://github.com/manish3-4/aichatbot/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [API router](https://github.com/manish3-4/aichatbot/blob/main/backend/src/routes/index.ts): `backend/src/routes/index.ts`

### Identity and data

- [User routes](https://github.com/manish3-4/aichatbot/blob/main/backend/src/routes/user-routes.ts): `backend/src/routes/user-routes.ts`
- [Request validation](https://github.com/manish3-4/aichatbot/blob/main/backend/src/utils/validators.ts): `backend/src/utils/validators.ts`
- [User controller](https://github.com/manish3-4/aichatbot/blob/main/backend/src/controllers/user-controller.ts): `backend/src/controllers/user-controller.ts`
- [JWT creation](https://github.com/manish3-4/aichatbot/blob/main/backend/src/utils/token-manager.ts): `backend/src/utils/token-manager.ts`
- [User model](https://github.com/manish3-4/aichatbot/blob/main/backend/src/models/User.ts): `backend/src/models/User.ts`
- [Mongo connection](https://github.com/manish3-4/aichatbot/blob/main/backend/src/db/connection.ts): `backend/src/db/connection.ts`

### Chat capabilities

- [Chat page](https://github.com/manish3-4/aichatbot/blob/main/frontend/src/pages/Chat.tsx): `frontend/src/pages/Chat.tsx`
- [Chat routes](https://github.com/manish3-4/aichatbot/blob/main/backend/src/routes/chat-routes.ts): `backend/src/routes/chat-routes.ts`

### Other components

- **User**
- **MongoDB**
- **OpenAI service**

## Connections

- User → React app: uses (evidence: `README.md`)
- React app → Page routing: renders (evidence: `frontend/src/main.tsx`)
- React app → Auth context: provides auth (evidence: `frontend/src/main.tsx`)
- Page routing → Login form: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → Signup page: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → Home page: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → Chat page: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → Navigation header: renders (evidence: `frontend/src/App.tsx`)
- Login form → Form input: renders (evidence: `frontend/src/pages/Login.tsx`)
- Login form → Auth context: calls login (evidence: `frontend/src/pages/Login.tsx`)
- Auth context → API helper: calls login API (evidence: `frontend/src/context/AuthContext.tsx`)
- API helper → User routes: posts credentials (evidence: `frontend/src/helpers/api-communicators.ts`)
- Express app → API router: mounts routes (evidence: `backend/src/app.ts`)
- API router → User routes: registers (evidence: `backend/src/routes/index.ts`)
- API router → Chat routes: registers (evidence: `backend/src/routes/index.ts`)
- User routes → Request validation: validates requests (evidence: `backend/src/routes/user-routes.ts`)
- User routes → User controller: dispatches (evidence: `backend/src/routes/user-routes.ts`)
- User controller → User model: reads and writes (evidence: `backend/src/controllers/user-controller.ts`)
- User controller → JWT creation: creates token (evidence: `backend/src/controllers/user-controller.ts`)
- Mongo connection → MongoDB: connects (evidence: `README.md`)
- User model → MongoDB: persists users (evidence: `README.md`)
- Chat page → Chat routes: requests chats (evidence: `README.md`)
- Chat routes → OpenAI service: gets AI responses (evidence: `README.md`)
- Chat routes → MongoDB: stores chat history (evidence: `README.md`)
