# thifreal/chatbotapi architecture

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

- Interactive diagram: https://gitdiagram.com/thifreal/chatbotapi
- Repository: https://github.com/thifreal/chatbotapi

## Overview

This repository exposes a FastAPI chatbot: a client submits a message, the chat route validates it, calls the chat service, and returns a typed reply. The service reads cached settings and calls Azure OpenAI; separate routes render a small HTML interface and save an API key to .env. The README describes a RAG pipeline with ingestion and FAISS, but those implementation files are absent from the supplied tree. That documented capability is shown as unimplemented here; the sampled runtime instead calls Azure chat directly.

Main entry points: [`ChatbotAPI/app/api/routes.py`](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/api/routes.py) (Routes), [`ChatbotAPI/app/services/chat_service.py`](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/services/chat_service.py) (Chat service), [`ChatbotAPI/app/config.py`](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/config.py) (Settings), [`ChatbotAPI/app/main.py`](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/main.py) (FastAPI app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and UI"]
  node_fastapi["FastAPI app<br/>[main.py]"]
  node_routes["Routes<br/>[routes.py]"]
  node_chat_ui["Chat template<br/>[index.html]"]
end

subgraph group_chat["Chat runtime"]
  node_request_schema["Chat request<br/>[chat.py]"]
  node_response_schema["Chat response<br/>[chat.py]"]
  node_service["Chat service<br/>[chat_service.py]"]
end

subgraph group_config["Configuration"]
  node_settings["Settings<br/>[config.py]"]
  node_env_file[".env settings"]
end

subgraph group_rag["Documented RAG"]
  node_rag_pipeline["RAG pipeline"]
  node_ingestion["Document ingestion"]
  node_faiss[("FAISS index")]
  node_openai_embeddings["OpenAI embeddings"]
end

node_client(("Chat client"))
node_azure["Azure OpenAI"]

node_client -->|"sends requests"| node_fastapi
node_fastapi -->|"includes router"| node_routes
node_routes -->|"validates payload"| node_request_schema
node_routes -->|"calls"| node_service
node_service -->|"loads settings"| node_settings
node_settings -->|"reads settings"| node_env_file
node_service -->|"requests completion"| node_azure
node_routes -->|"builds response"| node_response_schema
node_routes -->|"renders template"| node_chat_ui
node_routes -->|"loads settings"| node_settings
node_routes -->|"writes API key"| node_env_file
node_client -.->|"asks questions"| node_rag_pipeline
node_rag_pipeline -.->|"uses indexed documents"| node_ingestion
node_ingestion -.->|"generates embeddings"| node_openai_embeddings
node_ingestion -.->|"saves index"| node_faiss
node_rag_pipeline -.->|"searches index"| node_faiss

click node_fastapi "https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/main.py"
click node_routes "https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/api/routes.py"
click node_chat_ui "https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/templates/index.html"
click node_request_schema "https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/schemas/chat.py"
click node_response_schema "https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/schemas/chat.py"
click node_service "https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/services/chat_service.py"
click node_settings "https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/config.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_fastapi,node_routes,node_chat_ui,node_client toneBlue
class node_request_schema,node_response_schema,node_service toneAmber
class node_settings,node_env_file toneMint
class node_rag_pipeline,node_ingestion,node_faiss,node_openai_embeddings toneRose
class node_azure toneIndigo
```

## Components

### API and UI

- [FastAPI app](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/main.py): `ChatbotAPI/app/main.py`
- [Routes](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/api/routes.py): `ChatbotAPI/app/api/routes.py`
- [Chat template](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/templates/index.html): `ChatbotAPI/app/templates/index.html`

### Chat runtime

- [Chat request](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/schemas/chat.py): `ChatbotAPI/app/schemas/chat.py`
- [Chat response](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/schemas/chat.py): `ChatbotAPI/app/schemas/chat.py`
- [Chat service](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/services/chat_service.py): `ChatbotAPI/app/services/chat_service.py`

### Configuration

- [Settings](https://github.com/thifreal/chatbotapi/blob/main/ChatbotAPI/app/config.py): `ChatbotAPI/app/config.py`
- **.env settings**

### Documented RAG

- **RAG pipeline**
- **Document ingestion**
- **FAISS index**
- **OpenAI embeddings**

### Other components

- **Chat client**
- **Azure OpenAI**

## Connections

- Chat client → FastAPI app: sends requests (evidence: `README.md`)
- FastAPI app → Routes: includes router (evidence: `ChatbotAPI/app/main.py`)
- Routes → Chat request: validates payload (evidence: `ChatbotAPI/app/api/routes.py`)
- Routes → Chat service: calls (evidence: `ChatbotAPI/app/api/routes.py`)
- Chat service → Settings: loads settings (evidence: `ChatbotAPI/app/services/chat_service.py`)
- Settings → .env settings: reads settings (evidence: `ChatbotAPI/app/config.py`)
- Chat service → Azure OpenAI: requests completion (evidence: `ChatbotAPI/app/services/chat_service.py`)
- Routes → Chat response: builds response (evidence: `ChatbotAPI/app/api/routes.py`)
- Routes → Chat template: renders template (evidence: `ChatbotAPI/app/api/routes.py`)
- Routes → Settings: loads settings (evidence: `ChatbotAPI/app/api/routes.py`)
- Routes → .env settings: writes API key (evidence: `ChatbotAPI/app/api/routes.py`)
- Chat client → RAG pipeline: asks questions (evidence: `README.md`)
- RAG pipeline → Document ingestion: uses indexed documents (evidence: `README.md`)
- Document ingestion → OpenAI embeddings: generates embeddings (evidence: `README.md`)
- Document ingestion → FAISS index: saves index (evidence: `README.md`)
- RAG pipeline → FAISS index: searches index (evidence: `README.md`)
