# shivankkumar09/alpha_bot architecture

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

- Interactive diagram: https://gitdiagram.com/shivankkumar09/alpha_bot
- Repository: https://github.com/shivankkumar09/alpha_bot

## Overview

Alpha Bot is a full-stack Gemini chatbot. Users sign up or log in, open the protected chat workspace, create and manage persistent chat sessions, and send messages for AI responses. The frontend owns navigation, authentication state, chat interaction, and API calls; Express routes dispatch those calls to authentication and chat controllers, which use MongoDB-backed user records and the AI service. The README documents Gemini integration and persistent history; unsampled service details are not inferred beyond that documented integration.

Main entry points: [`server/src/routes/user-routes.ts`](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/routes/user-routes.ts) (User routes), [`server/src/routes/chat-routes.ts`](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/routes/chat-routes.ts) (Chat routes), [`client/src/helper/api.jsx`](https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/helper/api.jsx) (HTTP API client), [`client/src/App.jsx`](https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/App.jsx) (App routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["App routing<br/>[App.jsx]"]
  node_authui["Auth state<br/>[AuthContext.jsx]"]
  node_authpages["Login and signup"]
  node_chatui["Chat workspace<br/>[Chat.jsx]"]
  node_sidebar["Session sidebar<br/>[ChatSidebar.jsx]"]
  node_chatitem["Message rendering<br/>[ChatItem.jsx]"]
  node_chatstate["Chat state<br/>[ChatContext.jsx]"]
  node_api["HTTP API client<br/>[api.jsx]"]
end

subgraph group_backend["API and identity"]
  node_express["Express app<br/>[app.ts]"]
  node_useroutes["User routes<br/>[user-routes.ts]"]
  node_userctrl["User operations"]
  node_authguard["JWT verification<br/>[token-manager.ts]"]
  node_validators["Request validation<br/>[validators.ts]"]
end

subgraph group_chat["Chat domain"]
  node_chatroutes["Chat routes<br/>[chat-routes.ts]"]
  node_chatctrl["Session and messages"]
  node_userstore[("User and chat records<br/>[User.ts]")]
  node_ai["Gemini service<br/>[ai.service.ts]"]
end

subgraph group_integrations["External services"]
  node_mongo[("MongoDB")]
  node_gemini{{"Google Gemini API"}}
end

node_user(("Chat user"))

node_user -->|"uses"| node_app
node_app -->|"checks auth"| node_authui
node_app -->|"routes to"| node_authpages
node_app -->|"routes to"| node_chatui
node_authpages -->|"authenticates via"| node_authui
node_chatui -->|"renders"| node_sidebar
node_chatui -->|"renders"| node_chatitem
node_chatui -->|"requests"| node_api
node_chatstate -->|"requests"| node_api
node_authui -->|"requests"| node_api
node_api -->|"HTTP requests"| node_useroutes
node_api -->|"HTTP requests"| node_chatroutes
node_express -->|"mounts routes"| node_useroutes
node_express -->|"mounts routes"| node_chatroutes
node_useroutes -->|"dispatches"| node_userctrl
node_useroutes -->|"verifies token"| node_authguard
node_useroutes -->|"validates input"| node_validators
node_chatroutes -->|"dispatches"| node_chatctrl
node_chatroutes -->|"verifies token"| node_authguard
node_chatroutes -->|"validates input"| node_validators
node_userctrl -->|"reads and writes"| node_userstore
node_userctrl -->|"creates tokens"| node_authguard
node_chatctrl -->|"reads and saves"| node_userstore
node_chatctrl -->|"generates response"| node_ai
node_userstore -->|"persists records"| node_mongo
node_ai -.->|"generates content"| node_gemini

click node_app "https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/App.jsx"
click node_authui "https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/context/AuthContext.jsx"
click node_authpages "https://github.com/shivankkumar09/alpha_bot/tree/main/client/src/pages"
click node_chatui "https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/pages/Chat.jsx"
click node_sidebar "https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/components/ChatSidebar.jsx"
click node_chatitem "https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/components/ChatItem.jsx"
click node_chatstate "https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/context/ChatContext.jsx"
click node_api "https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/helper/api.jsx"
click node_express "https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/app.ts"
click node_useroutes "https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/routes/user-routes.ts"
click node_chatroutes "https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/routes/chat-routes.ts"
click node_userctrl "https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/controllers/user-controllers.ts"
click node_authguard "https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/utils/token-manager.ts"
click node_validators "https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/utils/validators.ts"
click node_chatctrl "https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/controllers/chat-controllers.ts"
click node_userstore "https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/models/User.ts"
click node_ai "https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/services/ai.service.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_app,node_authui,node_authpages,node_chatui,node_sidebar,node_chatitem,node_chatstate,node_api,node_user toneBlue
class node_express,node_useroutes,node_userctrl,node_authguard,node_validators toneAmber
class node_chatroutes,node_chatctrl,node_userstore,node_ai toneMint
class node_mongo,node_gemini toneRose
```

## Components

### Web application

- [App routing](https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Auth state](https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/context/AuthContext.jsx): `client/src/context/AuthContext.jsx`
- [Login and signup](https://github.com/shivankkumar09/alpha_bot/tree/main/client/src/pages): `client/src/pages`
- [Chat workspace](https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/pages/Chat.jsx): `client/src/pages/Chat.jsx`
- [Session sidebar](https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/components/ChatSidebar.jsx): `client/src/components/ChatSidebar.jsx`
- [Message rendering](https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/components/ChatItem.jsx): `client/src/components/ChatItem.jsx`
- [Chat state](https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/context/ChatContext.jsx): `client/src/context/ChatContext.jsx`
- [HTTP API client](https://github.com/shivankkumar09/alpha_bot/blob/main/client/src/helper/api.jsx): `client/src/helper/api.jsx`

### API and identity

- [Express app](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/app.ts): `server/src/app.ts`
- [User routes](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/routes/user-routes.ts): `server/src/routes/user-routes.ts`
- [User operations](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/controllers/user-controllers.ts): `server/src/controllers/user-controllers.ts`
- [JWT verification](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/utils/token-manager.ts): `server/src/utils/token-manager.ts`
- [Request validation](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/utils/validators.ts): `server/src/utils/validators.ts`

### Chat domain

- [Chat routes](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/routes/chat-routes.ts): `server/src/routes/chat-routes.ts`
- [Session and messages](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/controllers/chat-controllers.ts): `server/src/controllers/chat-controllers.ts`
- [User and chat records](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/models/User.ts): `server/src/models/User.ts`
- [Gemini service](https://github.com/shivankkumar09/alpha_bot/blob/main/server/src/services/ai.service.ts): `server/src/services/ai.service.ts`

### External services

- **MongoDB**
- **Google Gemini API**

### Other components

- **Chat user**

## Connections

- Chat user → App routing: uses (evidence: `README.md`)
- App routing → Auth state: checks auth (evidence: `client/src/App.jsx`)
- App routing → Login and signup: routes to (evidence: `client/src/App.jsx`)
- App routing → Chat workspace: routes to (evidence: `client/src/App.jsx`)
- Login and signup → Auth state: authenticates via (evidence: `client/src/pages/Login.jsx`)
- Chat workspace → Session sidebar: renders (evidence: `client/src/pages/Chat.jsx`)
- Chat workspace → Message rendering: renders (evidence: `client/src/pages/Chat.jsx`)
- Chat workspace → HTTP API client: requests (evidence: `client/src/pages/Chat.jsx`)
- Chat state → HTTP API client: requests (evidence: `client/src/context/ChatContext.jsx`)
- Auth state → HTTP API client: requests (evidence: `client/src/context/AuthContext.jsx`)
- HTTP API client → User routes: HTTP requests (evidence: `client/src/helper/api.jsx`)
- HTTP API client → Chat routes: HTTP requests (evidence: `client/src/helper/api.jsx`)
- Express app → User routes: mounts routes (evidence: `server/src/app.ts`)
- Express app → Chat routes: mounts routes (evidence: `server/src/app.ts`)
- User routes → User operations: dispatches (evidence: `server/src/routes/user-routes.ts`)
- User routes → JWT verification: verifies token (evidence: `server/src/routes/user-routes.ts`)
- User routes → Request validation: validates input (evidence: `server/src/routes/user-routes.ts`)
- Chat routes → Session and messages: dispatches (evidence: `server/src/routes/chat-routes.ts`)
- Chat routes → JWT verification: verifies token (evidence: `server/src/routes/chat-routes.ts`)
- Chat routes → Request validation: validates input (evidence: `server/src/routes/chat-routes.ts`)
- User operations → User and chat records: reads and writes (evidence: `server/src/controllers/user-controllers.ts`)
- User operations → JWT verification: creates tokens (evidence: `server/src/controllers/user-controllers.ts`)
- Session and messages → User and chat records: reads and saves (evidence: `server/src/controllers/chat-controllers.ts`)
- Session and messages → Gemini service: generates response (evidence: `server/src/controllers/chat-controllers.ts`)
- User and chat records → MongoDB: persists records (evidence: `README.md`)
- Gemini service → Google Gemini API: generates content (evidence: `README.md`)
