# surbhi20-hub/python-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/surbhi20-hub/python-chatbot
- Repository: https://github.com/surbhi20-hub/python-chatbot

## Overview

This NiceGUI chatbot takes user messages, optional attachments, language, and recent chat history; the frontend sends them to a FastAPI endpoint, which prepares model input and requests a reply from OpenRouter. The UI also manages persistent chat sessions, exports, greeting, theme, and voice input. README capabilities are included, though some frontend implementations were not sampled; those are represented only where the tree supports them.

Main entry points: [`frontend-python/app.py`](https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py) (Chat interface), [`backend/main.py`](https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/main.py) (Chat endpoint), [`backend/openrouter_client.py`](https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/openrouter_client.py) (Model client), [`backend/file_utils.py`](https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/file_utils.py) (File text extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["NiceGUI frontend"]
  node_ui["Chat interface<br/>[app.py]"]
  node_sessions[("Chat sessions<br/>[app.py]")]
  node_exports["Chat export<br/>[app.py]"]
  node_attachments["Attachment picker<br/>[app.py]"]
  node_voice["Voice input<br/>[app.py]"]
end

subgraph group_backend["Chat backend"]
  node_chat_api["Chat endpoint<br/>[main.py]"]
  node_request_model["Request model<br/>[main.py]"]
  node_file_extract["File text extraction<br/>[file_utils.py]"]
end

subgraph group_ai["AI integration"]
  node_prompt_builder["Language prompt"]
  node_model_client["Model client"]
end

node_user(("Chat user"))
node_speech_api["Web Speech API"]
node_openrouter["OpenRouter"]

node_user -->|"sends messages"| node_ui
node_ui -->|"reads and writes"| node_sessions
node_ui -->|"exports chats"| node_exports
node_ui -->|"selects files"| node_attachments
node_ui -->|"starts voice input"| node_voice
node_voice -->|"transcribes speech"| node_speech_api
node_ui -->|"posts chat request"| node_chat_api
node_chat_api -->|"validates request"| node_request_model
node_chat_api -->|"builds language prompt"| node_prompt_builder
node_chat_api -->|"extracts file text"| node_file_extract
node_chat_api -->|"requests reply"| node_model_client
node_model_client -->|"sends model request"| node_openrouter
node_openrouter -->|"returns completion"| node_model_client
node_model_client -->|"returns reply"| node_chat_api
node_chat_api -->|"returns chat reply"| node_ui

click node_ui "https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py"
click node_sessions "https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py"
click node_exports "https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py"
click node_attachments "https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py"
click node_voice "https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py"
click node_chat_api "https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/main.py"
click node_request_model "https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/main.py"
click node_file_extract "https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/file_utils.py"
click node_prompt_builder "https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/openrouter_client.py"
click node_model_client "https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/openrouter_client.py"

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_ui,node_sessions,node_exports,node_attachments,node_voice,node_user toneBlue
class node_chat_api,node_request_model,node_file_extract toneAmber
class node_prompt_builder,node_model_client,node_speech_api,node_openrouter toneMint
```

## Components

### NiceGUI frontend

- [Chat interface](https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py): `frontend-python/app.py`
- [Chat sessions](https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py): `frontend-python/app.py`
- [Chat export](https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py): `frontend-python/app.py`
- [Attachment picker](https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py): `frontend-python/app.py`
- [Voice input](https://github.com/surbhi20-hub/python-chatbot/blob/main/frontend-python/app.py): `frontend-python/app.py`

### Chat backend

- [Chat endpoint](https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/main.py): `backend/main.py`
- [Request model](https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/main.py): `backend/main.py`
- [File text extraction](https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/file_utils.py): `backend/file_utils.py`

### AI integration

- [Language prompt](https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/openrouter_client.py): `backend/openrouter_client.py`
- [Model client](https://github.com/surbhi20-hub/python-chatbot/blob/main/backend/openrouter_client.py): `backend/openrouter_client.py`

### Other components

- **Chat user**
- **Web Speech API**
- **OpenRouter**

## Connections

- Chat user → Chat interface: sends messages
- Chat interface → Chat sessions: reads and writes
- Chat interface → Chat export: exports chats
- Chat interface → Attachment picker: selects files
- Chat interface → Voice input: starts voice input
- Voice input → Web Speech API: transcribes speech
- Chat interface → Chat endpoint: posts chat request
- Chat endpoint → Request model: validates request
- Chat endpoint → Language prompt: builds language prompt
- Chat endpoint → File text extraction: extracts file text
- Chat endpoint → Model client: requests reply
- Model client → OpenRouter: sends model request
- OpenRouter → Model client: returns completion
- Model client → Chat endpoint: returns reply
- Chat endpoint → Chat interface: returns chat reply
