# omarkhaled4418/rag-chat architecture

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

- Interactive diagram: https://gitdiagram.com/omarkhaled4418/rag-chat
- Repository: https://github.com/omarkhaled4418/rag-chat

## Overview

RAG Chat is a headless REST service for ingesting documents and answering questions from their indexed content. Clients upload PDF/TXT files or submit raw text; the API delegates ingestion to the RAG engine, which extracts and chunks text before indexing it. Search uses hybrid keyword and FAISS retrieval; chat passes retrieved context and session history to an OpenAI-compatible LLM, with JSON and SSE response modes. The API also exposes document, index, health, and history management. Relationships reflect the sampled source and README; unsampled route details are represented only where documented.

Main entry points: [`app/rag_engine.py`](https://github.com/omarkhaled4418/rag-chat/blob/main/app/rag_engine.py) (RAG Orchestrator), [`app/routes.py`](https://github.com/omarkhaled4418/rag-chat/blob/main/app/routes.py) (REST Routes), [`app/vector_store.py`](https://github.com/omarkhaled4418/rag-chat/blob/main/app/vector_store.py) (Hybrid Vector Store), [`app/llm.py`](https://github.com/omarkhaled4418/rag-chat/blob/main/app/llm.py) (LLM Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_routes["REST Routes<br/>[routes.py]"]
  node_engine["RAG Orchestrator<br/>[rag_engine.py]"]
  node_config["Runtime Configuration<br/>[config.py]"]
end

subgraph group_ingestion["Document Ingestion"]
  node_file_ingest["File Ingestion<br/>[routes.py]"]
  node_text_ingest["Raw Text Ingestion<br/>[routes.py]"]
  node_extractor["Text Extraction<br/>[pdf_parser.py]"]
  node_chunker["Text Chunking<br/>[chunker.py]"]
end

subgraph group_retrieval["Retrieval and Index"]
  node_vector_store[("Hybrid Vector Store<br/>[vector_store.py]")]
  node_embedder["Embedding Model<br/>[embedder.py]"]
end

subgraph group_generation["Answer Generation"]
  node_history[("Session History<br/>[chat_history.py]")]
  node_llm["LLM Client<br/>[llm.py]"]
  node_llm_service{{"OpenAI-Compatible LLM"}}
end

node_client(("HTTP Client"))

node_client -->|"sends requests"| node_routes
node_routes -->|"dispatches operations"| node_engine
node_routes -->|"reads settings"| node_config
node_routes -->|"manages sessions"| node_history
node_routes -->|"accepts files"| node_file_ingest
node_routes -->|"accepts text"| node_text_ingest
node_file_ingest -->|"invokes ingestion"| node_engine
node_text_ingest -->|"invokes ingestion"| node_engine
node_engine -->|"extracts text"| node_extractor
node_engine -->|"chunks pages"| node_chunker
node_engine -->|"indexes and searches"| node_vector_store
node_vector_store -->|"generates embeddings"| node_embedder
node_engine -->|"reads and saves turns"| node_history
node_engine -->|"generates answers"| node_llm
node_llm -->|"sends completions"| node_llm_service
node_routes -->|"manages documents and index"| node_engine

click node_routes "https://github.com/omarkhaled4418/rag-chat/blob/main/app/routes.py"
click node_engine "https://github.com/omarkhaled4418/rag-chat/blob/main/app/rag_engine.py"
click node_config "https://github.com/omarkhaled4418/rag-chat/blob/main/app/config.py"
click node_file_ingest "https://github.com/omarkhaled4418/rag-chat/blob/main/app/routes.py"
click node_text_ingest "https://github.com/omarkhaled4418/rag-chat/blob/main/app/routes.py"
click node_extractor "https://github.com/omarkhaled4418/rag-chat/blob/main/app/pdf_parser.py"
click node_chunker "https://github.com/omarkhaled4418/rag-chat/blob/main/app/chunker.py"
click node_vector_store "https://github.com/omarkhaled4418/rag-chat/blob/main/app/vector_store.py"
click node_embedder "https://github.com/omarkhaled4418/rag-chat/blob/main/app/embedder.py"
click node_history "https://github.com/omarkhaled4418/rag-chat/blob/main/app/chat_history.py"
click node_llm "https://github.com/omarkhaled4418/rag-chat/blob/main/app/llm.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_routes,node_engine,node_config,node_client toneBlue
class node_file_ingest,node_text_ingest,node_extractor,node_chunker toneAmber
class node_vector_store,node_embedder toneMint
class node_history,node_llm,node_llm_service toneRose
```

## Components

### HTTP API

- [REST Routes](https://github.com/omarkhaled4418/rag-chat/blob/main/app/routes.py): `app/routes.py`
- [RAG Orchestrator](https://github.com/omarkhaled4418/rag-chat/blob/main/app/rag_engine.py): `app/rag_engine.py`
- [Runtime Configuration](https://github.com/omarkhaled4418/rag-chat/blob/main/app/config.py): `app/config.py`

### Document Ingestion

- [File Ingestion](https://github.com/omarkhaled4418/rag-chat/blob/main/app/routes.py): `app/routes.py`
- [Raw Text Ingestion](https://github.com/omarkhaled4418/rag-chat/blob/main/app/routes.py): `app/routes.py`
- [Text Extraction](https://github.com/omarkhaled4418/rag-chat/blob/main/app/pdf_parser.py): `app/pdf_parser.py`
- [Text Chunking](https://github.com/omarkhaled4418/rag-chat/blob/main/app/chunker.py): `app/chunker.py`

### Retrieval and Index

- [Hybrid Vector Store](https://github.com/omarkhaled4418/rag-chat/blob/main/app/vector_store.py): `app/vector_store.py`
- [Embedding Model](https://github.com/omarkhaled4418/rag-chat/blob/main/app/embedder.py): `app/embedder.py`

### Answer Generation

- [Session History](https://github.com/omarkhaled4418/rag-chat/blob/main/app/chat_history.py): `app/chat_history.py`
- [LLM Client](https://github.com/omarkhaled4418/rag-chat/blob/main/app/llm.py): `app/llm.py`
- **OpenAI-Compatible LLM**

### Other components

- **HTTP Client**

## Connections

- HTTP Client → REST Routes: sends requests (evidence: `README.md`)
- REST Routes → RAG Orchestrator: dispatches operations (evidence: `app/routes.py`)
- REST Routes → Runtime Configuration: reads settings (evidence: `app/routes.py`)
- REST Routes → Session History: manages sessions (evidence: `README.md`)
- REST Routes → File Ingestion: accepts files (evidence: `README.md`)
- REST Routes → Raw Text Ingestion: accepts text (evidence: `app/routes.py`)
- File Ingestion → RAG Orchestrator: invokes ingestion (evidence: `app/routes.py`)
- Raw Text Ingestion → RAG Orchestrator: invokes ingestion (evidence: `app/routes.py`)
- RAG Orchestrator → Text Extraction: extracts text (evidence: `app/rag_engine.py`)
- RAG Orchestrator → Text Chunking: chunks pages (evidence: `app/rag_engine.py`)
- RAG Orchestrator → Hybrid Vector Store: indexes and searches (evidence: `app/rag_engine.py`)
- Hybrid Vector Store → Embedding Model: generates embeddings (evidence: `app/vector_store.py`)
- RAG Orchestrator → Session History: reads and saves turns (evidence: `app/rag_engine.py`)
- RAG Orchestrator → LLM Client: generates answers (evidence: `app/rag_engine.py`)
- LLM Client → OpenAI-Compatible LLM: sends completions (evidence: `app/llm.py`)
- REST Routes → RAG Orchestrator: manages documents and index (evidence: `README.md`)
