# gaikwaddarshan0111/rag_system architecture

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

- Interactive diagram: https://gitdiagram.com/gaikwaddarshan0111/rag_system
- Repository: https://github.com/gaikwaddarshan0111/rag_system

## Overview

This is a document-grounded RAG application: an admin uploads and indexes policy PDFs, while authenticated users ask questions and receive answers with sources. The ask handler chooses company context when it is answerable and otherwise searches the web; the selected context is prompted and sent to an LLM. The graph also captures authentication, document administration, and the indexing/retrieval internals. Several modules are identified by the source index but not excerpted, so edges involving them are included only where that index or an excerpt supports the relationship.

Main entry points: [`src/api/routes.py`](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/api/routes.py) (Ask endpoint), [`main.py`](https://github.com/gaikwaddarshan0111/rag_system/blob/main/main.py) (App and upload routes), [`src/vectordb/index_documents.py`](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/vectordb/index_documents.py) (Document indexing), [`src/auth/dependencies.py`](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/auth/dependencies.py) (Token authorization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Application API"]
  node_app["App and upload routes<br/>[main.py]"]
  node_ask["Ask endpoint<br/>[routes.py]"]
end

subgraph group_identity["Identity and records"]
  node_auth_routes["Login and identity routes<br/>[auth_routes.py]"]
  node_doc_routes["Document listing<br/>[document_routes.py]"]
  node_auth_deps["Token authorization<br/>[dependencies.py]"]
  node_security["Token and password security<br/>[security.py]"]
  node_user_model["User and document records<br/>[models.py]"]
  node_sql_db[("Application SQL database<br/>[database.py]")]
end

subgraph group_knowledge["Knowledge pipeline"]
  node_indexer["Document indexing<br/>[index_documents.py]"]
  node_loader["PDF loader<br/>[loader.py]"]
  node_chunking["Text chunking<br/>[chunker.py]"]
  node_embedder["Text embeddings<br/>[embedder.py]"]
  node_vector_store[("Chroma vector store<br/>[chroma_store.py]")]
  node_retriever["Knowledge retrieval<br/>[retriever.py]"]
end

subgraph group_answering["Answer generation"]
  node_prompt["Prompt construction<br/>[prompts.py]"]
  node_generator["LLM generation and checking<br/>[generator.py]"]
end

subgraph group_web["Web fallback"]
  node_web_search["Web search facade<br/>[search.py]"]
  node_tavily["Tavily provider<br/>[tavily_provider.py]"]
end

node_user(("Authenticated user"))
node_admin(("Admin uploader"))
node_pdf["Uploaded PDF files"]
node_llm_service(("Configured LLM service"))
node_web_service(("Tavily search service"))

node_user -->|"asks question"| node_ask
node_ask -->|"requires user"| node_auth_deps
node_admin -->|"uploads PDF"| node_app
node_app -->|"requires admin"| node_auth_deps
node_app -->|"indexes upload"| node_indexer
node_app -->|"records upload"| node_sql_db
node_app -->|"writes file"| node_pdf
node_auth_routes -->|"queries user"| node_sql_db
node_auth_routes -->|"loads user"| node_user_model
node_auth_routes -->|"verifies and issues"| node_security
node_auth_deps -->|"decodes token"| node_security
node_user_model -->|"maps records"| node_sql_db
node_doc_routes -->|"requires user"| node_auth_deps
node_doc_routes -->|"queries documents"| node_sql_db
node_doc_routes -->|"returns records"| node_user_model
node_indexer -->|"loads PDF"| node_loader
node_indexer -->|"chunks text"| node_chunking
node_indexer -->|"embeds chunks"| node_embedder
node_indexer -->|"stores chunks"| node_vector_store
node_ask -->|"retrieves context"| node_retriever
node_retriever -->|"embeds query"| node_embedder
node_retriever -->|"queries vectors"| node_vector_store
node_ask -->|"builds prompt"| node_prompt
node_ask -->|"checks answerability"| node_generator
node_ask -->|"generates answer"| node_generator
node_generator -.->|"calls configured model"| node_llm_service
node_ask -->|"searches fallback"| node_web_search
node_ask -->|"builds web context"| node_web_search
node_web_search -->|"dispatches search"| node_tavily
node_tavily -.->|"queries provider"| node_web_service

click node_app "https://github.com/gaikwaddarshan0111/rag_system/blob/main/main.py"
click node_ask "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/api/routes.py"
click node_auth_routes "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/api/auth_routes.py"
click node_doc_routes "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/api/document_routes.py"
click node_auth_deps "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/auth/dependencies.py"
click node_security "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/auth/security.py"
click node_user_model "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/auth/models.py"
click node_sql_db "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/auth/database.py"
click node_indexer "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/vectordb/index_documents.py"
click node_loader "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/ingestion/loader.py"
click node_chunking "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/chunking/chunker.py"
click node_embedder "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/embeddings/embedder.py"
click node_vector_store "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/vectordb/chroma_store.py"
click node_retriever "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/retrieval/retriever.py"
click node_prompt "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/prompts/prompts.py"
click node_generator "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/llm/generator.py"
click node_web_search "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/web_search/search.py"
click node_tavily "https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/web_search/providers/tavily_provider.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_app,node_ask,node_user toneBlue
class node_auth_routes,node_doc_routes,node_auth_deps,node_security,node_user_model,node_sql_db toneAmber
class node_indexer,node_loader,node_chunking,node_embedder,node_vector_store,node_retriever toneMint
class node_prompt,node_generator toneRose
class node_web_search,node_tavily,node_admin,node_pdf,node_llm_service,node_web_service toneIndigo
```

## Components

### Application API

- [App and upload routes](https://github.com/gaikwaddarshan0111/rag_system/blob/main/main.py): `main.py`
- [Ask endpoint](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/api/routes.py): `src/api/routes.py`

### Identity and records

- [Login and identity routes](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/api/auth_routes.py): `src/api/auth_routes.py`
- [Document listing](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/api/document_routes.py): `src/api/document_routes.py`
- [Token authorization](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/auth/dependencies.py): `src/auth/dependencies.py`
- [Token and password security](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/auth/security.py): `src/auth/security.py`
- [User and document records](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/auth/models.py): `src/auth/models.py`
- [Application SQL database](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/auth/database.py): `src/auth/database.py`

### Knowledge pipeline

- [Document indexing](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/vectordb/index_documents.py): `src/vectordb/index_documents.py`
- [PDF loader](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/ingestion/loader.py): `src/ingestion/loader.py`
- [Text chunking](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/chunking/chunker.py): `src/chunking/chunker.py`
- [Text embeddings](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/embeddings/embedder.py): `src/embeddings/embedder.py`
- [Chroma vector store](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/vectordb/chroma_store.py): `src/vectordb/chroma_store.py`
- [Knowledge retrieval](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/retrieval/retriever.py): `src/retrieval/retriever.py`

### Answer generation

- [Prompt construction](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/prompts/prompts.py): `src/prompts/prompts.py`
- [LLM generation and checking](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/llm/generator.py): `src/llm/generator.py`

### Web fallback

- [Web search facade](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/web_search/search.py): `src/web_search/search.py`
- [Tavily provider](https://github.com/gaikwaddarshan0111/rag_system/blob/main/src/web_search/providers/tavily_provider.py): `src/web_search/providers/tavily_provider.py`

### Other components

- **Authenticated user**
- **Admin uploader**
- **Uploaded PDF files**
- **Configured LLM service**
- **Tavily search service**

## Connections

- Authenticated user → Ask endpoint: asks question (evidence: `src/api/routes.py`)
- Ask endpoint → Token authorization: requires user (evidence: `src/api/routes.py`)
- Admin uploader → App and upload routes: uploads PDF (evidence: `main.py`)
- App and upload routes → Token authorization: requires admin (evidence: `main.py`)
- App and upload routes → Document indexing: indexes upload (evidence: `main.py`)
- App and upload routes → Application SQL database: records upload (evidence: `main.py`)
- App and upload routes → Uploaded PDF files: writes file (evidence: `main.py`)
- Login and identity routes → Application SQL database: queries user (evidence: `src/api/auth_routes.py`)
- Login and identity routes → User and document records: loads user (evidence: `src/api/auth_routes.py`)
- Login and identity routes → Token and password security: verifies and issues (evidence: `src/api/auth_routes.py`)
- Token authorization → Token and password security: decodes token (evidence: `src/auth/dependencies.py`)
- User and document records → Application SQL database: maps records (evidence: `src/auth/models.py`)
- Document listing → Token authorization: requires user (evidence: `src/api/document_routes.py`)
- Document listing → Application SQL database: queries documents (evidence: `src/api/document_routes.py`)
- Document listing → User and document records: returns records (evidence: `src/api/document_routes.py`)
- Document indexing → PDF loader: loads PDF (evidence: `src/vectordb/index_documents.py`)
- Document indexing → Text chunking: chunks text (evidence: `src/vectordb/index_documents.py`)
- Document indexing → Text embeddings: embeds chunks (evidence: `src/vectordb/index_documents.py`)
- Document indexing → Chroma vector store: stores chunks (evidence: `src/vectordb/index_documents.py`)
- Ask endpoint → Knowledge retrieval: retrieves context (evidence: `src/api/routes.py`)
- Knowledge retrieval → Text embeddings: embeds query (evidence: `src/retrieval/retriever.py`)
- Knowledge retrieval → Chroma vector store: queries vectors (evidence: `src/retrieval/retriever.py`)
- Ask endpoint → Prompt construction: builds prompt (evidence: `src/api/routes.py`)
- Ask endpoint → LLM generation and checking: checks answerability (evidence: `src/api/routes.py`)
- Ask endpoint → LLM generation and checking: generates answer (evidence: `src/api/routes.py`)
- LLM generation and checking → Configured LLM service: calls configured model
- Ask endpoint → Web search facade: searches fallback (evidence: `src/api/routes.py`)
- Ask endpoint → Web search facade: builds web context (evidence: `src/api/routes.py`)
- Web search facade → Tavily provider: dispatches search (evidence: `src/web_search/search.py`)
- Tavily provider → Tavily search service: queries provider
