# bjukic2/python-rag-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/bjukic2/python-rag-chatbot
- Repository: https://github.com/bjukic2/python-rag-chatbot

## Overview

This repository is a RAG chatbot: users submit questions in a Next.js chat, FastAPI streams a response, and the backend embeds the question, retrieves document context from ChromaDB, then asks a local Ollama model to generate an answer. A separate ingestion script chunks documents, embeds each chunk, and stores it for retrieval. The README also documents the chat UI, streaming, vector search, and CORS. The graph follows shown calls and documented integration; retrieval internals and other unsampled modules are not inferred.

Main entry points: [`backend/app/rag/pipeline.py`](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/rag/pipeline.py) (RAG pipeline), [`frontend/app/components/Chat.tsx`](https://github.com/bjukic2/python-rag-chatbot/blob/main/frontend/app/components/Chat.tsx) (Chat UI), [`backend/ingest.py`](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/ingest.py) (Ingestion script), [`backend/app/api/chat.py`](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/api/chat.py) (Streaming route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Chat interface"]
  node_chat_ui["Chat UI<br/>[Chat.tsx]"]
  node_page["Chat page<br/>[page.tsx]"]
end

subgraph group_api["API service"]
  node_api_app["FastAPI app<br/>[main.py]"]
  node_chat_route["Streaming route<br/>[chat.py]"]
end

subgraph group_rag["Retrieval and generation"]
  node_pipeline["RAG pipeline<br/>[pipeline.py]"]
  node_embedder["Text embedder<br/>[embedder.py]"]
  node_vector_store[("Vector store<br/>[vector_store.py]")]
  node_config["Store config<br/>[config.py]"]
end

subgraph group_ingest["Document ingestion"]
  node_ingest_script["Ingestion script<br/>[ingest.py]"]
  node_splitter["Text splitter<br/>[text_splitter.py]"]
end

node_user(("Chat user"))
node_ollama{{"Ollama service"}}

node_user -->|"enters question"| node_chat_ui
node_page -->|"renders"| node_chat_ui
node_chat_ui -->|"POSTs question"| node_chat_route
node_api_app -->|"mounts route"| node_chat_route
node_chat_route -->|"streams tokens"| node_pipeline
node_pipeline -->|"embeds query"| node_embedder
node_pipeline -->|"searches vectors"| node_vector_store
node_pipeline -->|"requests generation"| node_ollama
node_embedder -->|"requests embedding"| node_ollama
node_vector_store -->|"reads path"| node_config
node_ingest_script -->|"chunks documents"| node_splitter
node_ingest_script -->|"embeds chunks"| node_embedder
node_ingest_script -->|"stores chunks"| node_vector_store
node_api_app -.->|"enables CORS"| node_chat_ui

click node_chat_ui "https://github.com/bjukic2/python-rag-chatbot/blob/main/frontend/app/components/Chat.tsx"
click node_page "https://github.com/bjukic2/python-rag-chatbot/blob/main/frontend/app/page.tsx"
click node_api_app "https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/main.py"
click node_chat_route "https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/api/chat.py"
click node_pipeline "https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/rag/pipeline.py"
click node_embedder "https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/rag/embedder.py"
click node_vector_store "https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/db/vector_store.py"
click node_config "https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/core/config.py"
click node_ingest_script "https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/ingest.py"
click node_splitter "https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/utils/text_splitter.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_chat_ui,node_page,node_user toneBlue
class node_api_app,node_chat_route toneAmber
class node_pipeline,node_embedder,node_vector_store,node_config toneMint
class node_ingest_script,node_splitter toneRose
class node_ollama toneIndigo
```

## Components

### Chat interface

- [Chat UI](https://github.com/bjukic2/python-rag-chatbot/blob/main/frontend/app/components/Chat.tsx): `frontend/app/components/Chat.tsx`
- [Chat page](https://github.com/bjukic2/python-rag-chatbot/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`

### API service

- [FastAPI app](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/main.py): `backend/main.py`
- [Streaming route](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/api/chat.py): `backend/app/api/chat.py`

### Retrieval and generation

- [RAG pipeline](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/rag/pipeline.py): `backend/app/rag/pipeline.py`
- [Text embedder](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/rag/embedder.py): `backend/app/rag/embedder.py`
- [Vector store](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/db/vector_store.py): `backend/app/db/vector_store.py`
- [Store config](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/core/config.py): `backend/app/core/config.py`

### Document ingestion

- [Ingestion script](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/ingest.py): `backend/ingest.py`
- [Text splitter](https://github.com/bjukic2/python-rag-chatbot/blob/main/backend/app/utils/text_splitter.py): `backend/app/utils/text_splitter.py`

### Other components

- **Chat user**
- **Ollama service**

## Connections

- Chat user → Chat UI: enters question (evidence: `frontend/app/components/Chat.tsx`)
- Chat page → Chat UI: renders (evidence: `frontend/app/page.tsx`)
- Chat UI → Streaming route: POSTs question (evidence: `frontend/app/components/Chat.tsx`)
- FastAPI app → Streaming route: mounts route (evidence: `backend/main.py`)
- Streaming route → RAG pipeline: streams tokens (evidence: `backend/app/api/chat.py`)
- RAG pipeline → Text embedder: embeds query (evidence: `backend/app/rag/pipeline.py`)
- RAG pipeline → Vector store: searches vectors (evidence: `backend/app/rag/pipeline.py`)
- RAG pipeline → Ollama service: requests generation (evidence: `backend/app/rag/pipeline.py`)
- Text embedder → Ollama service: requests embedding (evidence: `backend/app/rag/embedder.py`)
- Vector store → Store config: reads path (evidence: `backend/app/db/vector_store.py`)
- Ingestion script → Text splitter: chunks documents (evidence: `backend/ingest.py`)
- Ingestion script → Text embedder: embeds chunks (evidence: `backend/ingest.py`)
- Ingestion script → Vector store: stores chunks (evidence: `backend/ingest.py`)
- FastAPI app → Chat UI: enables CORS (evidence: `README.md`)
