# mehmetaliguda/rag_web architecture

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

- Interactive diagram: https://gitdiagram.com/mehmetaliguda/rag_web
- Repository: https://github.com/mehmetaliguda/rag_web

## Overview

This is a multi-PDF RAG chat application: users upload PDFs into isolated rooms, then ask room-scoped questions and receive cited answers. The frontend handles room selection and chat presentation; Flask manages uploads, room lookup, chat requests, and citation URLs. The RAG engine chunks and indexes PDFs, optimizes questions, retrieves and ranks context, and produces answers. Source excerpts are partial, so some internal method wiring and optional behavior are not shown; the graph omits those uncertain links.

Main entry points: [`backend/app.py`](https://github.com/mehmetaliguda/rag_web/blob/main/backend/app.py) (Flask API), [`backend/rag_chat.py`](https://github.com/mehmetaliguda/rag_web/blob/main/backend/rag_chat.py) (Room RAG engine), [`app/components/chat-client.tsx`](https://github.com/mehmetaliguda/rag_web/blob/main/app/components/chat-client.tsx) (Chat client), [`app/page.tsx`](https://github.com/mehmetaliguda/rag_web/blob/main/app/page.tsx) (Document library)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_library["Document library<br/>[page.tsx]"]
  node_room_page["Room page<br/>[page.tsx]"]
  node_chat_client["Chat client<br/>[chat-client.tsx]"]
  node_chat_message["Message and citations<br/>[chat-message.tsx]"]
end

subgraph group_api["API and rooms"]
  node_flask_api["Flask API<br/>[app.py]"]
  node_room_manager["Room manager<br/>[rag_chat.py]"]
  node_citation_assets["PDF and page images<br/>[app.py]"]
end

subgraph group_rag["RAG processing"]
  node_rag_room["Room RAG engine<br/>[rag_chat.py]"]
  node_query_optimizer["Query optimizer<br/>[query_optimizer.py]"]
  node_hybrid_retriever["Hybrid retrieval"]
end

subgraph group_state["Document state"]
  node_shared_store[("Chroma store")]
  node_room_files[("Room files and indexes")]
end

node_visitor(("User"))
node_ollama{{"Ollama models"}}
node_pdf["Uploaded PDF"]

node_visitor -->|"selects or uploads"| node_library
node_library -->|"lists rooms / uploads PDF"| node_flask_api
node_flask_api -->|"creates or lists rooms"| node_room_manager
node_pdf -->|"upload"| node_flask_api
node_room_manager -->|"creates room engine"| node_rag_room
node_rag_room -->|"stores room data"| node_room_files
node_rag_room -->|"persists embeddings"| node_shared_store
node_library -->|"opens room"| node_room_page
node_room_page -->|"renders"| node_chat_client
node_visitor -->|"asks question"| node_chat_client
node_chat_client -->|"posts question"| node_flask_api
node_flask_api -->|"looks up room"| node_room_manager
node_room_manager -->|"returns room engine"| node_rag_room
node_rag_room -->|"optimizes query"| node_query_optimizer
node_query_optimizer -.->|"expands query"| node_ollama
node_rag_room -->|"retrieves and ranks"| node_hybrid_retriever
node_hybrid_retriever -->|"searches vectors"| node_shared_store
node_hybrid_retriever -.->|"embeds query"| node_ollama
node_rag_room -->|"generates answer"| node_ollama
node_flask_api -->|"builds citation URLs"| node_citation_assets
node_flask_api -->|"resolves citation room"| node_room_manager
node_citation_assets -->|"serves PDF or images"| node_room_files
node_flask_api -->|"returns answer and citations"| node_chat_client
node_chat_client -->|"renders messages"| node_chat_message
node_chat_message -->|"opens cited sources"| node_citation_assets

click node_library "https://github.com/mehmetaliguda/rag_web/blob/main/app/page.tsx"
click node_room_page "https://github.com/mehmetaliguda/rag_web/blob/main/app/chat/%5BroomId%5D/page.tsx"
click node_chat_client "https://github.com/mehmetaliguda/rag_web/blob/main/app/components/chat-client.tsx"
click node_chat_message "https://github.com/mehmetaliguda/rag_web/blob/main/app/components/chat-message.tsx"
click node_flask_api "https://github.com/mehmetaliguda/rag_web/blob/main/backend/app.py"
click node_room_manager "https://github.com/mehmetaliguda/rag_web/blob/main/backend/rag_chat.py"
click node_rag_room "https://github.com/mehmetaliguda/rag_web/blob/main/backend/rag_chat.py"
click node_query_optimizer "https://github.com/mehmetaliguda/rag_web/blob/main/backend/query_optimizer.py"
click node_hybrid_retriever "https://github.com/mehmetaliguda/rag_web/blob/main/backend/hybrid_retriever.py"
click node_shared_store "https://github.com/mehmetaliguda/rag_web/tree/main/chroma_db"
click node_room_files "https://github.com/mehmetaliguda/rag_web/tree/main/rag_rooms"
click node_citation_assets "https://github.com/mehmetaliguda/rag_web/blob/main/backend/app.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_library,node_room_page,node_chat_client,node_chat_message,node_visitor toneBlue
class node_flask_api,node_room_manager,node_citation_assets toneAmber
class node_rag_room,node_query_optimizer,node_hybrid_retriever toneMint
class node_shared_store,node_room_files toneRose
class node_ollama,node_pdf toneIndigo
```

## Components

### Web interface

- [Document library](https://github.com/mehmetaliguda/rag_web/blob/main/app/page.tsx): `app/page.tsx`
- [Room page](https://github.com/mehmetaliguda/rag_web/blob/main/app/chat/%5BroomId%5D/page.tsx): `app/chat/[roomId]/page.tsx`
- [Chat client](https://github.com/mehmetaliguda/rag_web/blob/main/app/components/chat-client.tsx): `app/components/chat-client.tsx`
- [Message and citations](https://github.com/mehmetaliguda/rag_web/blob/main/app/components/chat-message.tsx): `app/components/chat-message.tsx`

### API and rooms

- [Flask API](https://github.com/mehmetaliguda/rag_web/blob/main/backend/app.py): `backend/app.py`
- [Room manager](https://github.com/mehmetaliguda/rag_web/blob/main/backend/rag_chat.py): `backend/rag_chat.py`
- [PDF and page images](https://github.com/mehmetaliguda/rag_web/blob/main/backend/app.py): `backend/app.py`

### RAG processing

- [Room RAG engine](https://github.com/mehmetaliguda/rag_web/blob/main/backend/rag_chat.py): `backend/rag_chat.py`
- [Query optimizer](https://github.com/mehmetaliguda/rag_web/blob/main/backend/query_optimizer.py): `backend/query_optimizer.py`
- [Hybrid retrieval](https://github.com/mehmetaliguda/rag_web/blob/main/backend/hybrid_retriever.py): `backend/hybrid_retriever.py`

### Document state

- [Chroma store](https://github.com/mehmetaliguda/rag_web/tree/main/chroma_db): `chroma_db`
- [Room files and indexes](https://github.com/mehmetaliguda/rag_web/tree/main/rag_rooms): `rag_rooms`

### Other components

- **User**
- **Ollama models**
- **Uploaded PDF**

## Connections

- User → Document library: selects or uploads
- Document library → Flask API: lists rooms / uploads PDF
- Flask API → Room manager: creates or lists rooms
- Uploaded PDF → Flask API: upload
- Room manager → Room RAG engine: creates room engine
- Room RAG engine → Room files and indexes: stores room data
- Room RAG engine → Chroma store: persists embeddings
- Document library → Room page: opens room
- Room page → Chat client: renders
- User → Chat client: asks question
- Chat client → Flask API: posts question
- Flask API → Room manager: looks up room
- Room manager → Room RAG engine: returns room engine
- Room RAG engine → Query optimizer: optimizes query
- Query optimizer → Ollama models: expands query
- Room RAG engine → Hybrid retrieval: retrieves and ranks
- Hybrid retrieval → Chroma store: searches vectors
- Hybrid retrieval → Ollama models: embeds query
- Room RAG engine → Ollama models: generates answer
- Flask API → PDF and page images: builds citation URLs
- Flask API → Room manager: resolves citation room
- PDF and page images → Room files and indexes: serves PDF or images
- Flask API → Chat client: returns answer and citations
- Chat client → Message and citations: renders messages
- Message and citations → PDF and page images: opens cited sources
