# puneet987720-creator/ai-chatbot architecture

> Architecture diagram of the GitHub repository puneet987720-creator/ai-chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/puneet987720-creator/ai-chatbot
- Repository: https://github.com/puneet987720-creator/ai-chatbot

## Overview

This is a mobile/web conversational assistant with a Laravel API. Users authenticate, send messages, and manage conversation history; the backend retrieves document context, calls Gemini, and stores messages. The frontend also presents chat content and history. Backend control flow is supported by controller and service excerpts; some frontend-to-API details and authentication-provider wiring are not shown, so those links are omitted or marked unverified.

Main entry points: [`chatbot-backend/app/Http/Controllers/Api/ChatbotController.php`](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Http/Controllers/Api/ChatbotController.php) (Chat API), [`chatbot-frontend/api/chatBot.ts`](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/api/chatBot.ts) (API client), [`chatbot-frontend/app/(drawer)/chatTab.tsx`](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/app/(drawer)/chatTab.tsx) (Chat screen), [`chatbot-backend/app/Services/VectorSearchService.php`](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Services/VectorSearchService.php) (Context retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Client experience"]
  node_login["Sign-in screen<br/>[index.tsx]"]
  node_chatui["Chat screen<br/>[chatTab.tsx]"]
  node_chatcontent["Message views"]
  node_usercontent["User message view<br/>[userContent.tsx]"]
  node_historyui["History screen<br/>[sideTab.tsx]"]
  node_historyitem["History item<br/>[chatHistory.tsx]"]
  node_api_client["API client<br/>[chatBot.ts]"]
  node_token["Token storage<br/>[getToken.tsx]"]
end

subgraph group_api["API and auth"]
  node_backend_api["Chat API"]
  node_routes["API routing<br/>[api.php]"]
  node_auth["User authentication<br/>[userAuth.php]"]
end

subgraph group_chat["Conversation domain"]
  node_conversation[("Conversations<br/>[Conversation.php]")]
  node_messages[("Messages<br/>[Message.php]")]
  node_user_model[("User account<br/>[User.php]")]
end

subgraph group_knowledge["Knowledge and generation"]
  node_vector["Context retrieval"]
  node_documents[("Embedded documents<br/>[Document.php]")]
  node_generation["Gemini service<br/>[OpenAiService.php]"]
end

node_user(("User"))
node_gemini{{"Google Gemini"}}

node_user -->|"signs in"| node_login
node_user -.->|"chats"| node_chatui
node_login -->|"imports"| node_api_client
node_api_client -->|"gets token"| node_token
node_historyui -->|"uses"| node_api_client
node_historyui -->|"renders"| node_historyitem
node_chatui -->|"renders"| node_chatcontent
node_chatui -->|"renders"| node_usercontent
node_api_client -.->|"sends requests"| node_backend_api
node_routes -->|"routes to"| node_backend_api
node_routes -->|"routes to"| node_auth
node_backend_api -->|"creates and reads"| node_conversation
node_backend_api -->|"reads and writes"| node_messages
node_backend_api -->|"retrieves context"| node_vector
node_backend_api -->|"requests completion"| node_generation
node_vector -->|"generates embedding"| node_generation
node_vector -->|"queries embeddings"| node_documents
node_generation -->|"calls API"| node_gemini
node_conversation -->|"relates messages"| node_messages

click node_login "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/app/index.tsx"
click node_chatui "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/app/(drawer)/chatTab.tsx"
click node_chatcontent "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/component/assistantContent.tsx"
click node_usercontent "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/component/userContent.tsx"
click node_historyui "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/app/(drawer)/sideTab.tsx"
click node_historyitem "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/component/chatHistory.tsx"
click node_api_client "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/api/chatBot.ts"
click node_token "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/utils/getToken.tsx"
click node_backend_api "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Http/Controllers/Api/ChatbotController.php"
click node_routes "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/routes/api.php"
click node_auth "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Http/Controllers/userAuth.php"
click node_conversation "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Models/Conversation.php"
click node_messages "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Models/Message.php"
click node_user_model "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Models/User.php"
click node_vector "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Services/VectorSearchService.php"
click node_documents "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Models/Document.php"
click node_generation "https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Services/OpenAiService.php"

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_login,node_chatui,node_chatcontent,node_usercontent,node_historyui,node_historyitem,node_api_client,node_token,node_user toneBlue
class node_backend_api,node_routes,node_auth toneAmber
class node_conversation,node_messages,node_user_model toneMint
class node_vector,node_documents,node_generation toneRose
class node_gemini toneIndigo
```

## Components

### Client experience

- [Sign-in screen](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/app/index.tsx): `chatbot-frontend/app/index.tsx`
- [Chat screen](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/app/(drawer)/chatTab.tsx): `chatbot-frontend/app/(drawer)/chatTab.tsx`
- [Message views](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/component/assistantContent.tsx): `chatbot-frontend/component/assistantContent.tsx`
- [User message view](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/component/userContent.tsx): `chatbot-frontend/component/userContent.tsx`
- [History screen](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/app/(drawer)/sideTab.tsx): `chatbot-frontend/app/(drawer)/sideTab.tsx`
- [History item](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/component/chatHistory.tsx): `chatbot-frontend/component/chatHistory.tsx`
- [API client](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/api/chatBot.ts): `chatbot-frontend/api/chatBot.ts`
- [Token storage](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-frontend/utils/getToken.tsx): `chatbot-frontend/utils/getToken.tsx`

### API and auth

- [Chat API](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Http/Controllers/Api/ChatbotController.php): `chatbot-backend/app/Http/Controllers/Api/ChatbotController.php`
- [API routing](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/routes/api.php): `chatbot-backend/routes/api.php`
- [User authentication](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Http/Controllers/userAuth.php): `chatbot-backend/app/Http/Controllers/userAuth.php`

### Conversation domain

- [Conversations](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Models/Conversation.php): `chatbot-backend/app/Models/Conversation.php`
- [Messages](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Models/Message.php): `chatbot-backend/app/Models/Message.php`
- [User account](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Models/User.php): `chatbot-backend/app/Models/User.php`

### Knowledge and generation

- [Context retrieval](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Services/VectorSearchService.php): `chatbot-backend/app/Services/VectorSearchService.php`
- [Embedded documents](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Models/Document.php): `chatbot-backend/app/Models/Document.php`
- [Gemini service](https://github.com/puneet987720-creator/ai-chatbot/blob/main/chatbot-backend/app/Services/OpenAiService.php): `chatbot-backend/app/Services/OpenAiService.php`

### Other components

- **User**
- **Google Gemini**

## Connections

- User → Sign-in screen: signs in (evidence: `chatbot-frontend/app/index.tsx`)
- User → Chat screen: chats
- Sign-in screen → API client: imports (evidence: `chatbot-frontend/app/index.tsx`)
- API client → Token storage: gets token (evidence: `chatbot-frontend/api/chatBot.ts`)
- History screen → API client: uses (evidence: `chatbot-frontend/app/(drawer)/sideTab.tsx`)
- History screen → History item: renders (evidence: `chatbot-frontend/app/(drawer)/sideTab.tsx`)
- Chat screen → Message views: renders (evidence: `chatbot-frontend/app/(drawer)/chatTab.tsx`)
- Chat screen → User message view: renders (evidence: `chatbot-frontend/app/(drawer)/chatTab.tsx`)
- API client → Chat API: sends requests
- API routing → Chat API: routes to (evidence: `chatbot-backend/routes/api.php`)
- API routing → User authentication: routes to (evidence: `chatbot-backend/routes/api.php`)
- Chat API → Conversations: creates and reads (evidence: `chatbot-backend/app/Http/Controllers/Api/ChatbotController.php`)
- Chat API → Messages: reads and writes (evidence: `chatbot-backend/app/Http/Controllers/Api/ChatbotController.php`)
- Chat API → Context retrieval: retrieves context (evidence: `chatbot-backend/app/Http/Controllers/Api/ChatbotController.php`)
- Chat API → Gemini service: requests completion (evidence: `chatbot-backend/app/Http/Controllers/Api/ChatbotController.php`)
- Context retrieval → Gemini service: generates embedding (evidence: `chatbot-backend/app/Services/VectorSearchService.php`)
- Context retrieval → Embedded documents: queries embeddings (evidence: `chatbot-backend/app/Services/VectorSearchService.php`)
- Gemini service → Google Gemini: calls API (evidence: `chatbot-backend/app/Services/OpenAiService.php`)
- Conversations → Messages: relates messages (evidence: `chatbot-backend/app/Models/Conversation.php`)
