# rohit2902/-brain-blitz architecture

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

- Interactive diagram: https://gitdiagram.com/rohit2902/-brain-blitz
- Repository: https://github.com/rohit2902/-brain-blitz

## Overview

Brain Blitz is an AI chat application with account registration, verification, login, and password recovery alongside persistent, streamed conversations. Users enter through the React app: auth flows use shared auth state and API services, while the protected dashboard uses chat state and services. On the server, HTTP routes dispatch to auth and chat controllers; chat requests load and save conversation data while streaming generated responses. Email and AI providers are external integrations. The chat socket files exist, but their runtime relationship is not established by the excerpts. No README was provided, so some frontend-to-backend links remain unverified.

Main entry points: [`frontend/src/features/chat/hook/useChat.js`](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/hook/useChat.js) (Chat Workflow), [`backend/src/controllers/auth.controller.js`](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/controllers/auth.controller.js) (Auth Controller), [`backend/src/controllers/chat.controller.js`](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/controllers/chat.controller.js) (Chat Controller), [`frontend/src/features/auth/hook/useAuth.js`](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/auth/hook/useAuth.js) (Auth Workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_app["React App<br/>[App.jsx]"]
  node_routes["Page Routes<br/>[app.route.jsx]"]
  node_authpages["Auth Pages"]
  node_authhook["Auth Workflow<br/>[useAuth.js]"]
  node_authapi["Auth API Client<br/>[auth.api.js]"]
  node_authstate["Auth State<br/>[auth.slice.js]"]
  node_dashboard["Chat Dashboard<br/>[Dashboard.jsx]"]
  node_chatui["Chat Components"]
  node_chathook["Chat Workflow<br/>[useChat.js]"]
  node_chatapi["Chat API Client<br/>[chat.api.js]"]
  node_chatstate["Chat State<br/>[chat.slice.js]"]
  node_socketclient["Socket Client<br/>[chat.socket.js]"]
end

subgraph group_http["HTTP API"]
  node_server["HTTP Server<br/>[server.js]"]
  node_appserver["Express App<br/>[app.js]"]
  node_authroutes["Auth Routes<br/>[auth.route.js]"]
  node_chatroutes["Chat Routes<br/>[chat..route.js]"]
  node_socketserver["Socket Server<br/>[server.socket.js]"]
end

subgraph group_domain["Auth and Chat"]
  node_authcontroller["Auth Controller<br/>[auth.controller.js]"]
  node_chatcontroller["Chat Controller<br/>[chat.controller.js]"]
end

subgraph group_integrations["Persistence and Integrations"]
  node_userstore[("User Records<br/>[user.model.js]")]
  node_chatstore[("Chat Records<br/>[chat.model.js]")]
  node_messagestore[("Message Records<br/>[message.model.js]")]
  node_ai["AI Generation<br/>[Ai.service.js]"]
  node_email["Email Delivery<br/>[mail.service.js]"]
  node_verificationtemplate["Verify Email Template"]
  node_dbconfig["Database Connection<br/>[db.js]"]
end

node_user(("User"))
node_mailprovider["Email Provider"]
node_aiprovider["Gemini Provider"]

node_user -->|"uses"| node_app
node_app -->|"loads session"| node_authhook
node_app -->|"mounts routes"| node_routes
node_routes -->|"routes to"| node_authpages
node_authpages -->|"uses workflow"| node_authhook
node_authhook -->|"calls"| node_authapi
node_authhook -->|"updates"| node_authstate
node_routes -->|"routes to"| node_dashboard
node_dashboard -->|"uses workflow"| node_chathook
node_dashboard -->|"renders"| node_chatui
node_chathook -->|"calls"| node_chatapi
node_chathook -->|"updates"| node_chatstate
node_chathook -->|"initializes"| node_socketclient
node_authapi -.->|"HTTP requests"| node_authroutes
node_chatapi -.->|"HTTP requests"| node_chatroutes
node_server -->|"serves"| node_appserver
node_server -->|"connects database"| node_dbconfig
node_server -->|"initializes"| node_socketserver
node_appserver -->|"mounts"| node_authroutes
node_appserver -->|"mounts"| node_chatroutes
node_authroutes -->|"dispatches"| node_authcontroller
node_chatroutes -->|"dispatches"| node_chatcontroller
node_authcontroller -->|"reads and writes"| node_userstore
node_authcontroller -->|"sends email"| node_email
node_authcontroller -->|"renders"| node_verificationtemplate
node_chatcontroller -->|"reads and writes"| node_chatstore
node_chatcontroller -->|"reads and writes"| node_messagestore
node_chatcontroller -->|"generates response"| node_ai
node_ai -->|"streams generation"| node_aiprovider
node_email -->|"sends mail"| node_mailprovider

click node_app "https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/app/App.jsx"
click node_routes "https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/app/app.route.jsx"
click node_authpages "https://github.com/rohit2902/-brain-blitz/tree/main/frontend/src/features/auth/pages"
click node_authhook "https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/auth/hook/useAuth.js"
click node_authapi "https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/auth/services/auth.api.js"
click node_authstate "https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/auth/auth.slice.js"
click node_dashboard "https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/pages/Dashboard.jsx"
click node_chatui "https://github.com/rohit2902/-brain-blitz/tree/main/frontend/src/features/chat/pages/components"
click node_chathook "https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/hook/useChat.js"
click node_chatapi "https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/services/chat.api.js"
click node_chatstate "https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/chat.slice.js"
click node_socketclient "https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/services/chat.socket.js"
click node_server "https://github.com/rohit2902/-brain-blitz/blob/main/backend/server.js"
click node_appserver "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/app.js"
click node_authroutes "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/routes/auth.route.js"
click node_chatroutes "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/routes/chat..route.js"
click node_authcontroller "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/controllers/auth.controller.js"
click node_chatcontroller "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/controllers/chat.controller.js"
click node_userstore "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/models/user.model.js"
click node_chatstore "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/models/chat.model.js"
click node_messagestore "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/models/message.model.js"
click node_ai "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/services/Ai.service.js"
click node_email "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/services/mail.service.js"
click node_verificationtemplate "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/services/email/verify-email.template.js"
click node_dbconfig "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/config/db.js"
click node_socketserver "https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/sockets/server.socket.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_app,node_routes,node_authpages,node_authhook,node_authapi,node_authstate,node_dashboard,node_chatui,node_chathook,node_chatapi,node_chatstate,node_socketclient,node_user toneBlue
class node_server,node_appserver,node_authroutes,node_chatroutes,node_socketserver toneAmber
class node_authcontroller,node_chatcontroller toneMint
class node_userstore,node_chatstore,node_messagestore,node_ai,node_email,node_verificationtemplate,node_dbconfig toneRose
class node_mailprovider,node_aiprovider toneIndigo
```

## Components

### Frontend

- [React App](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/app/App.jsx): `frontend/src/app/App.jsx`
- [Page Routes](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/app/app.route.jsx): `frontend/src/app/app.route.jsx`
- [Auth Pages](https://github.com/rohit2902/-brain-blitz/tree/main/frontend/src/features/auth/pages): `frontend/src/features/auth/pages`
- [Auth Workflow](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/auth/hook/useAuth.js): `frontend/src/features/auth/hook/useAuth.js`
- [Auth API Client](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/auth/services/auth.api.js): `frontend/src/features/auth/services/auth.api.js`
- [Auth State](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/auth/auth.slice.js): `frontend/src/features/auth/auth.slice.js`
- [Chat Dashboard](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/pages/Dashboard.jsx): `frontend/src/features/chat/pages/Dashboard.jsx`
- [Chat Components](https://github.com/rohit2902/-brain-blitz/tree/main/frontend/src/features/chat/pages/components): `frontend/src/features/chat/pages/components`
- [Chat Workflow](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/hook/useChat.js): `frontend/src/features/chat/hook/useChat.js`
- [Chat API Client](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/services/chat.api.js): `frontend/src/features/chat/services/chat.api.js`
- [Chat State](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/chat.slice.js): `frontend/src/features/chat/chat.slice.js`
- [Socket Client](https://github.com/rohit2902/-brain-blitz/blob/main/frontend/src/features/chat/services/chat.socket.js): `frontend/src/features/chat/services/chat.socket.js`

### HTTP API

- [HTTP Server](https://github.com/rohit2902/-brain-blitz/blob/main/backend/server.js): `backend/server.js`
- [Express App](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/app.js): `backend/src/app.js`
- [Auth Routes](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/routes/auth.route.js): `backend/src/routes/auth.route.js`
- [Chat Routes](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/routes/chat..route.js): `backend/src/routes/chat..route.js`
- [Socket Server](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/sockets/server.socket.js): `backend/src/sockets/server.socket.js`

### Auth and Chat

- [Auth Controller](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/controllers/auth.controller.js): `backend/src/controllers/auth.controller.js`
- [Chat Controller](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/controllers/chat.controller.js): `backend/src/controllers/chat.controller.js`

### Persistence and Integrations

- [User Records](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/models/user.model.js): `backend/src/models/user.model.js`
- [Chat Records](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/models/chat.model.js): `backend/src/models/chat.model.js`
- [Message Records](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/models/message.model.js): `backend/src/models/message.model.js`
- [AI Generation](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/services/Ai.service.js): `backend/src/services/Ai.service.js`
- [Email Delivery](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/services/mail.service.js): `backend/src/services/mail.service.js`
- [Verify Email Template](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/services/email/verify-email.template.js): `backend/src/services/email/verify-email.template.js`
- [Database Connection](https://github.com/rohit2902/-brain-blitz/blob/main/backend/src/config/db.js): `backend/src/config/db.js`

### Other components

- **User**
- **Email Provider**
- **Gemini Provider**

## Connections

- User → React App: uses
- React App → Auth Workflow: loads session (evidence: `frontend/src/app/App.jsx`)
- React App → Page Routes: mounts routes (evidence: `frontend/src/app/App.jsx`)
- Page Routes → Auth Pages: routes to (evidence: `frontend/src/app/app.route.jsx`)
- Auth Pages → Auth Workflow: uses workflow (evidence: `frontend/src/features/auth/pages/Login.jsx`)
- Auth Workflow → Auth API Client: calls (evidence: `frontend/src/features/auth/hook/useAuth.js`)
- Auth Workflow → Auth State: updates (evidence: `frontend/src/features/auth/hook/useAuth.js`)
- Page Routes → Chat Dashboard: routes to (evidence: `frontend/src/app/app.route.jsx`)
- Chat Dashboard → Chat Workflow: uses workflow (evidence: `frontend/src/features/chat/pages/Dashboard.jsx`)
- Chat Dashboard → Chat Components: renders (evidence: `frontend/src/features/chat/pages/Dashboard.jsx`)
- Chat Workflow → Chat API Client: calls (evidence: `frontend/src/features/chat/hook/useChat.js`)
- Chat Workflow → Chat State: updates (evidence: `frontend/src/features/chat/hook/useChat.js`)
- Chat Workflow → Socket Client: initializes (evidence: `frontend/src/features/chat/hook/useChat.js`)
- Auth API Client → Auth Routes: HTTP requests
- Chat API Client → Chat Routes: HTTP requests
- HTTP Server → Express App: serves (evidence: `backend/server.js`)
- HTTP Server → Database Connection: connects database (evidence: `backend/server.js`)
- HTTP Server → Socket Server: initializes (evidence: `backend/server.js`)
- Express App → Auth Routes: mounts (evidence: `backend/src/app.js`)
- Express App → Chat Routes: mounts (evidence: `backend/src/app.js`)
- Auth Routes → Auth Controller: dispatches (evidence: `backend/src/routes/auth.route.js`)
- Chat Routes → Chat Controller: dispatches (evidence: `backend/src/routes/chat..route.js`)
- Auth Controller → User Records: reads and writes (evidence: `backend/src/controllers/auth.controller.js`)
- Auth Controller → Email Delivery: sends email (evidence: `backend/src/controllers/auth.controller.js`)
- Auth Controller → Verify Email Template: renders (evidence: `backend/src/controllers/auth.controller.js`)
- Chat Controller → Chat Records: reads and writes (evidence: `backend/src/controllers/chat.controller.js`)
- Chat Controller → Message Records: reads and writes (evidence: `backend/src/controllers/chat.controller.js`)
- Chat Controller → AI Generation: generates response (evidence: `backend/src/controllers/chat.controller.js`)
- AI Generation → Gemini Provider: streams generation (evidence: `backend/src/services/Ai.service.js`)
- Email Delivery → Email Provider: sends mail (evidence: `backend/src/services/mail.service.js`)
