# ankurdotio/cohort-1-project-chat-gpt architecture

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

- Interactive diagram: https://gitdiagram.com/ankurdotio/cohort-1-project-chat-gpt
- Repository: https://github.com/ankurdotio/cohort-1-project-chat-gpt

## Overview

This is a full-stack chat application with account registration/login, persistent chat history, and AI replies. Users enter through the web app, create or select a chat, send a message over Socket.IO, and receive an AI response; chat lists and message history use the HTTP API. The backend also exposes authentication routes and persists users, chats, and messages. The frontend pages for login and registration are included, but their request flows were not shown, so those links are omitted. Backend socket internals are represented from the source index; their detailed behavior was not excerpted.

Main entry points: [`Frontend/src/pages/Home.jsx`](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/pages/Home.jsx) (Chat workspace), [`Backend/src/sockets/socket.server.js`](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/sockets/socket.server.js) (Socket server), [`Backend/src/app.js`](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/app.js) (HTTP application), [`Frontend/src/AppRoutes.jsx`](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/AppRoutes.jsx) (Page routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_routes["Page routing<br/>[AppRoutes.jsx]"]
  node_home["Chat workspace<br/>[Home.jsx]"]
  node_login["Login page<br/>[Login.jsx]"]
  node_register["Registration page<br/>[Register.jsx]"]
  node_chat_ui["Chat components"]
  node_chat_state["Chat state<br/>[chatSlice.js]"]
end

subgraph group_api["HTTP API"]
  node_api_app["HTTP application<br/>[app.js]"]
  node_auth_routes["Auth routes<br/>[auth.routes.js]"]
  node_chat_routes["Chat routes<br/>[chat.routes.js]"]
  node_auth_controller["Account handling<br/>[auth.controller.js]"]
  node_auth_middleware["Request authentication<br/>[auth.middleware.js]"]
  node_chat_controller["Chat handling<br/>[chat.controller.js]"]
end

subgraph group_realtime["Realtime AI"]
  node_socket["Socket server<br/>[socket.server.js]"]
  node_ai["AI service<br/>[ai.service.js]"]
  node_vector["Vector service<br/>[vector.service.js]"]
end

subgraph group_data["Persistence"]
  node_db_connector["Database connection<br/>[db.js]"]
  node_users[("User records<br/>[user.model.js]")]
  node_chats[("Chat records<br/>[chat.model.js]")]
  node_messages[("Message records<br/>[message.model.js]")]
end

node_visitor(("User"))

node_visitor -->|"opens"| node_routes
node_routes -->|"routes to"| node_home
node_routes -->|"routes to"| node_login
node_routes -->|"routes to"| node_register
node_home -->|"renders"| node_chat_ui
node_home -->|"dispatches"| node_chat_state
node_home -->|"requests chats"| node_api_app
node_home -->|"exchanges messages"| node_socket
node_api_app -->|"mounts"| node_auth_routes
node_api_app -->|"mounts"| node_chat_routes
node_auth_routes -->|"dispatches"| node_auth_controller
node_chat_routes -->|"authenticates"| node_auth_middleware
node_chat_routes -->|"dispatches"| node_chat_controller
node_auth_controller -->|"reads and writes"| node_users
node_auth_middleware -->|"reads"| node_users
node_chat_controller -->|"reads and writes"| node_chats
node_chat_controller -->|"reads"| node_messages
node_socket -->|"requests replies"| node_ai
node_socket -->|"uses"| node_vector
node_socket -->|"reads"| node_users
node_socket -->|"writes"| node_messages
node_visitor -->|"starts service"| node_api_app
node_api_app -->|"connects database"| node_db_connector

click node_routes "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/AppRoutes.jsx"
click node_home "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/pages/Home.jsx"
click node_login "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/pages/Login.jsx"
click node_register "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/pages/Register.jsx"
click node_chat_ui "https://github.com/ankurdotio/cohort-1-project-chat-gpt/tree/main/Frontend/src/components/chat"
click node_chat_state "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/store/chatSlice.js"
click node_api_app "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/app.js"
click node_auth_routes "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/routes/auth.routes.js"
click node_chat_routes "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/routes/chat.routes.js"
click node_auth_controller "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/controllers/auth.controller.js"
click node_auth_middleware "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/middlewares/auth.middleware.js"
click node_chat_controller "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/controllers/chat.controller.js"
click node_socket "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/sockets/socket.server.js"
click node_ai "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/services/ai.service.js"
click node_vector "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/services/vector.service.js"
click node_db_connector "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/db/db.js"
click node_users "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/models/user.model.js"
click node_chats "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/models/chat.model.js"
click node_messages "https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/models/message.model.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_routes,node_home,node_login,node_register,node_chat_ui,node_chat_state,node_visitor toneBlue
class node_api_app,node_auth_routes,node_chat_routes,node_auth_controller,node_auth_middleware,node_chat_controller toneAmber
class node_socket,node_ai,node_vector toneMint
class node_db_connector,node_users,node_chats,node_messages toneRose
```

## Components

### Web application

- [Page routing](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/AppRoutes.jsx): `Frontend/src/AppRoutes.jsx`
- [Chat workspace](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/pages/Home.jsx): `Frontend/src/pages/Home.jsx`
- [Login page](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/pages/Login.jsx): `Frontend/src/pages/Login.jsx`
- [Registration page](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/pages/Register.jsx): `Frontend/src/pages/Register.jsx`
- [Chat components](https://github.com/ankurdotio/cohort-1-project-chat-gpt/tree/main/Frontend/src/components/chat): `Frontend/src/components/chat`
- [Chat state](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Frontend/src/store/chatSlice.js): `Frontend/src/store/chatSlice.js`

### HTTP API

- [HTTP application](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/app.js): `Backend/src/app.js`
- [Auth routes](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/routes/auth.routes.js): `Backend/src/routes/auth.routes.js`
- [Chat routes](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/routes/chat.routes.js): `Backend/src/routes/chat.routes.js`
- [Account handling](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/controllers/auth.controller.js): `Backend/src/controllers/auth.controller.js`
- [Request authentication](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/middlewares/auth.middleware.js): `Backend/src/middlewares/auth.middleware.js`
- [Chat handling](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/controllers/chat.controller.js): `Backend/src/controllers/chat.controller.js`

### Realtime AI

- [Socket server](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/sockets/socket.server.js): `Backend/src/sockets/socket.server.js`
- [AI service](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/services/ai.service.js): `Backend/src/services/ai.service.js`
- [Vector service](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/services/vector.service.js): `Backend/src/services/vector.service.js`

### Persistence

- [Database connection](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/db/db.js): `Backend/src/db/db.js`
- [User records](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/models/user.model.js): `Backend/src/models/user.model.js`
- [Chat records](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/models/chat.model.js): `Backend/src/models/chat.model.js`
- [Message records](https://github.com/ankurdotio/cohort-1-project-chat-gpt/blob/main/Backend/src/models/message.model.js): `Backend/src/models/message.model.js`

### Other components

- **User**

## Connections

- User → Page routing: opens (evidence: `Frontend/src/AppRoutes.jsx`)
- Page routing → Chat workspace: routes to (evidence: `Frontend/src/AppRoutes.jsx`)
- Page routing → Login page: routes to (evidence: `Frontend/src/AppRoutes.jsx`)
- Page routing → Registration page: routes to (evidence: `Frontend/src/AppRoutes.jsx`)
- Chat workspace → Chat components: renders (evidence: `Frontend/src/pages/Home.jsx`)
- Chat workspace → Chat state: dispatches (evidence: `Frontend/src/pages/Home.jsx`)
- Chat workspace → HTTP application: requests chats (evidence: `Frontend/src/pages/Home.jsx`)
- Chat workspace → Socket server: exchanges messages (evidence: `Frontend/src/pages/Home.jsx`)
- HTTP application → Auth routes: mounts (evidence: `Backend/src/app.js`)
- HTTP application → Chat routes: mounts (evidence: `Backend/src/app.js`)
- Auth routes → Account handling: dispatches (evidence: `Backend/src/routes/auth.routes.js`)
- Chat routes → Request authentication: authenticates (evidence: `Backend/src/routes/chat.routes.js`)
- Chat routes → Chat handling: dispatches (evidence: `Backend/src/routes/chat.routes.js`)
- Account handling → User records: reads and writes (evidence: `Backend/src/controllers/auth.controller.js`)
- Request authentication → User records: reads (evidence: `Backend/src/middlewares/auth.middleware.js`)
- Chat handling → Chat records: reads and writes (evidence: `Backend/src/controllers/chat.controller.js`)
- Chat handling → Message records: reads (evidence: `Backend/src/controllers/chat.controller.js`)
- Socket server → AI service: requests replies (evidence: `Backend/src/sockets/socket.server.js`)
- Socket server → Vector service: uses (evidence: `Backend/src/sockets/socket.server.js`)
- Socket server → User records: reads (evidence: `Backend/src/sockets/socket.server.js`)
- Socket server → Message records: writes (evidence: `Backend/src/sockets/socket.server.js`)
- User → HTTP application: starts service
- HTTP application → Database connection: connects database (evidence: `Backend/server.js`)
