# ulugbek-lab/claritylm-rag architecture

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

- Interactive diagram: https://gitdiagram.com/ulugbek-lab/claritylm-rag
- Repository: https://github.com/ulugbek-lab/claritylm-rag

## Overview

ClarityLM RAG is a single-user document-question-answering application. A user uploads a PDF, TXT, or Markdown file through the React workspace; FastAPI delegates extraction, chunking, embedding, and indexing to the RAG backend. For questions, the backend optionally retrieves and filters Qdrant excerpts, builds a bounded context, and invokes the local TinyLlama/LoRA model; the API returns an answer and formatted sources to the UI. The README documents optional, disabled-by-default filesystem ingestion. Edges reflect shown calls or README-documented behavior; unsampled frontend client and model wiring is not inferred beyond documented API use.

Main entry points: [`app/main.py`](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/main.py) (FastAPI application), [`app/api/routes.py`](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/api/routes.py) (API routes), [`app/services/rag_service.py`](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/services/rag_service.py) (RAG orchestration), [`app/services/qdrant_service.py`](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/services/qdrant_service.py) (Vector store adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Chat workspace"]
  node_workspace["Chat workspace<br/>[App.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["HTTP interface"]
  node_backend["FastAPI application<br/>[main.py]"]
  node_routes["API routes<br/>[routes.py]"]
  node_schemas["Request schemas<br/>[Rag.py]"]
  node_source_format["Source formatting"]
end

subgraph group_rag["RAG processing"]
  node_rag_service["RAG orchestration<br/>[rag_service.py]"]
end

subgraph group_runtime["Runtime services"]
  node_embeddings["Embedding model"]
  node_qdrant_service["Vector store adapter<br/>[qdrant_service.py]"]
  node_qdrant[("Qdrant collection")]
  node_llm["Local language model<br/>[llm_service.py]"]
  node_settings["Runtime settings<br/>[config.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_workspace
node_workspace -->|"calls"| node_api_client
node_api_client -->|"requests"| node_routes
node_routes -.->|"returns answers"| node_workspace
node_backend -->|"registers"| node_routes
node_backend -->|"loads"| node_settings
node_backend -->|"constructs"| node_embeddings
node_backend -->|"constructs"| node_qdrant_service
node_backend -->|"constructs"| node_llm
node_backend -->|"constructs"| node_rag_service
node_routes -->|"validates and responds"| node_schemas
node_routes -->|"delegates"| node_rag_service
node_routes -->|"formats sources"| node_source_format
node_rag_service -->|"embeds text"| node_embeddings
node_rag_service -->|"indexes and searches"| node_qdrant_service
node_rag_service -->|"generates answer"| node_llm
node_qdrant_service -->|"vectorizes documents"| node_embeddings
node_qdrant_service -->|"reads and writes"| node_qdrant

click node_workspace "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/frontend/src/App.tsx"
click node_api_client "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/frontend/src/api.ts"
click node_backend "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/main.py"
click node_routes "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/api/routes.py"
click node_schemas "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/dto/Rag.py"
click node_source_format "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/utils/source_formatting.py"
click node_rag_service "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/services/rag_service.py"
click node_embeddings "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/services/embeddings_service.py"
click node_qdrant_service "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/services/qdrant_service.py"
click node_llm "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/services/llm_service.py"
click node_settings "https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/core/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_workspace,node_api_client,node_user toneBlue
class node_backend,node_routes,node_schemas,node_source_format toneAmber
class node_rag_service toneMint
class node_embeddings,node_qdrant_service,node_qdrant,node_llm,node_settings toneRose
```

## Components

### Chat workspace

- [Chat workspace](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/frontend/src/App.tsx): `frontend/src/App.tsx`
- [API client](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/frontend/src/api.ts): `frontend/src/api.ts`

### HTTP interface

- [FastAPI application](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/main.py): `app/main.py`
- [API routes](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/api/routes.py): `app/api/routes.py`
- [Request schemas](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/dto/Rag.py): `app/dto/Rag.py`
- [Source formatting](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/utils/source_formatting.py): `utils/source_formatting.py`

### RAG processing

- [RAG orchestration](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/services/rag_service.py): `app/services/rag_service.py`

### Runtime services

- [Embedding model](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/services/embeddings_service.py): `app/services/embeddings_service.py`
- [Vector store adapter](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/services/qdrant_service.py): `app/services/qdrant_service.py`
- **Qdrant collection**
- [Local language model](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/services/llm_service.py): `app/services/llm_service.py`
- [Runtime settings](https://github.com/ulugbek-lab/claritylm-rag/blob/develop/app/core/config.py): `app/core/config.py`

### Other components

- **User**

## Connections

- User → Chat workspace: uses (evidence: `README.md`)
- Chat workspace → API client: calls (evidence: `frontend/src/App.tsx`)
- API client → API routes: requests (evidence: `README.md`)
- API routes → Chat workspace: returns answers
- FastAPI application → API routes: registers (evidence: `app/main.py`)
- FastAPI application → Runtime settings: loads (evidence: `app/main.py`)
- FastAPI application → Embedding model: constructs (evidence: `app/main.py`)
- FastAPI application → Vector store adapter: constructs (evidence: `app/main.py`)
- FastAPI application → Local language model: constructs (evidence: `app/main.py`)
- FastAPI application → RAG orchestration: constructs (evidence: `app/main.py`)
- API routes → Request schemas: validates and responds (evidence: `app/api/routes.py`)
- API routes → RAG orchestration: delegates (evidence: `app/api/routes.py`)
- API routes → Source formatting: formats sources (evidence: `app/api/routes.py`)
- RAG orchestration → Embedding model: embeds text (evidence: `app/services/rag_service.py`)
- RAG orchestration → Vector store adapter: indexes and searches (evidence: `app/services/rag_service.py`)
- RAG orchestration → Local language model: generates answer (evidence: `app/services/rag_service.py`)
- Vector store adapter → Embedding model: vectorizes documents (evidence: `app/services/qdrant_service.py`)
- Vector store adapter → Qdrant collection: reads and writes (evidence: `README.md`)
