# adilshamim8/production-grade-rag architecture

> Architecture diagram of the GitHub repository adilshamim8/production-grade-rag, 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/adilshamim8/production-grade-rag
- Repository: https://github.com/adilshamim8/production-grade-rag

## Overview

This repository contains two RAG implementations: a root-level Streamlit/FastAPI application with optional Inngest orchestration, and a packaged FastAPI service under rag-engine. The main user journey uploads PDFs, chunks and embeds them, stores vectors, retrieves relevant passages, then returns grounded answers with sources. The README also documents multi-provider models, local fallback, diagnostics, and the packaged API/UI. Edges reflect excerpts and README/index references; where packaged internals are unsampled, the graph avoids inferring their call sequence.

Main entry points: [`main.py`](https://github.com/adilshamim8/production-grade-rag/blob/main/main.py) (FastAPI workflow), [`rag-engine/src/rag_engine/api/app.py`](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/app.py) (API application), [`rag-engine/src/rag_engine/core/rag_chain.py`](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/core/rag_chain.py) (RAG chain), [`streamlit_app.py`](https://github.com/adilshamim8/production-grade-rag/blob/main/streamlit_app.py) (Streamlit UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root["Root application"]
  node_root_ui["Streamlit UI<br/>[streamlit_app.py]"]
  node_root_api["FastAPI workflow<br/>[main.py]"]
  node_workflow["Inngest steps<br/>[main.py]"]
  node_pdf_chunks["PDF chunking<br/>[data_loader.py]"]
  node_embeddings["Embedding providers<br/>[data_loader.py]"]
  node_local_answer["Grounded answers<br/>[main.py]"]
  node_root_vectors[("Qdrant storage<br/>[vector_db.py]")]
end

subgraph group_package_api["Packaged API"]
  node_package_ui["Packaged Streamlit UI<br/>[streamlit_app.py]"]
  node_package_app["API application<br/>[app.py]"]
  node_document_routes["Document routes<br/>[documents.py]"]
  node_query_routes["Query routes<br/>[query.py]"]
  node_health_routes["Health routes<br/>[health.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
  node_error_middleware["Error middleware<br/>[error_handler.py]"]
  node_logging_middleware["Request logging<br/>[logging.py]"]
end

subgraph group_package_core["Packaged RAG core"]
  node_doc_loader["Document loading<br/>[document_loader.py]"]
  node_package_embeddings["Embedding service<br/>[embeddings.py]"]
  node_rag_chain["RAG chain<br/>[rag_chain.py]"]
  node_package_vectors[("Vector store manager<br/>[vector_store.py]")]
end

subgraph group_platform["Shared platform"]
  node_qdrant[("Qdrant service")]
  node_logging["Logging utilities<br/>[logger.py]"]
end

node_user(("Document user"))
node_model_services{{"Model providers"}}
node_inngest_service["Inngest service"]

node_user -->|"uploads and queries"| node_root_ui
node_root_ui -.->|"starts workflow"| node_root_api
node_root_ui -->|"local ingestion"| node_pdf_chunks
node_root_ui -->|"local retrieval"| node_root_vectors
node_root_api -->|"registers steps"| node_workflow
node_workflow -->|"dispatches events"| node_inngest_service
node_workflow -->|"loads and chunks"| node_pdf_chunks
node_workflow -->|"embeds chunks"| node_embeddings
node_workflow -->|"upserts vectors"| node_root_vectors
node_workflow -->|"searches vectors"| node_root_vectors
node_root_api -->|"loads and chunks"| node_pdf_chunks
node_root_api -->|"embeds text"| node_embeddings
node_root_api -->|"upserts and searches"| node_root_vectors
node_root_api -->|"generates answer"| node_local_answer
node_root_api -.->|"requests generation"| node_model_services
node_embeddings -.->|"requests embeddings"| node_model_services
node_package_ui -.->|"uses service"| node_package_app
node_package_app -->|"registers route"| node_document_routes
node_package_app -->|"registers route"| node_query_routes
node_package_app -->|"registers route"| node_health_routes
node_document_routes -->|"ingests document"| node_rag_chain
node_query_routes -->|"runs query"| node_rag_chain
node_health_routes -->|"checks store"| node_package_vectors
node_document_routes -->|"uses request models"| node_schemas
node_query_routes -->|"uses query models"| node_schemas
node_rag_chain -.->|"processes documents"| node_doc_loader
node_rag_chain -.->|"creates embeddings"| node_package_embeddings
node_rag_chain -.->|"retrieves and indexes"| node_package_vectors
node_package_vectors -->|"reads and writes"| node_qdrant
node_package_app -->|"gets logger"| node_logging
node_logging_middleware -->|"gets logger"| node_logging
node_package_app -.->|"configures middleware"| node_error_middleware

click node_root_ui "https://github.com/adilshamim8/production-grade-rag/blob/main/streamlit_app.py"
click node_root_api "https://github.com/adilshamim8/production-grade-rag/blob/main/main.py"
click node_workflow "https://github.com/adilshamim8/production-grade-rag/blob/main/main.py"
click node_pdf_chunks "https://github.com/adilshamim8/production-grade-rag/blob/main/data_loader.py"
click node_embeddings "https://github.com/adilshamim8/production-grade-rag/blob/main/data_loader.py"
click node_local_answer "https://github.com/adilshamim8/production-grade-rag/blob/main/main.py"
click node_root_vectors "https://github.com/adilshamim8/production-grade-rag/blob/main/vector_db.py"
click node_package_ui "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/ui/streamlit_app.py"
click node_package_app "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/app.py"
click node_document_routes "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/routes/documents.py"
click node_query_routes "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/routes/query.py"
click node_health_routes "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/routes/health.py"
click node_schemas "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/models/schemas.py"
click node_doc_loader "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/core/document_loader.py"
click node_package_embeddings "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/core/embeddings.py"
click node_rag_chain "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/core/rag_chain.py"
click node_package_vectors "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/core/vector_store.py"
click node_logging "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/utils/logger.py"
click node_error_middleware "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/middleware/error_handler.py"
click node_logging_middleware "https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/middleware/logging.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_root_ui,node_root_api,node_workflow,node_pdf_chunks,node_embeddings,node_local_answer,node_root_vectors,node_user toneBlue
class node_package_ui,node_package_app,node_document_routes,node_query_routes,node_health_routes,node_schemas,node_error_middleware,node_logging_middleware toneAmber
class node_doc_loader,node_package_embeddings,node_rag_chain,node_package_vectors toneMint
class node_qdrant,node_logging toneRose
class node_model_services,node_inngest_service toneIndigo
```

## Components

### Root application

- [Streamlit UI](https://github.com/adilshamim8/production-grade-rag/blob/main/streamlit_app.py): `streamlit_app.py`
- [FastAPI workflow](https://github.com/adilshamim8/production-grade-rag/blob/main/main.py): `main.py`
- [Inngest steps](https://github.com/adilshamim8/production-grade-rag/blob/main/main.py): `main.py`
- [PDF chunking](https://github.com/adilshamim8/production-grade-rag/blob/main/data_loader.py): `data_loader.py`
- [Embedding providers](https://github.com/adilshamim8/production-grade-rag/blob/main/data_loader.py): `data_loader.py`
- [Grounded answers](https://github.com/adilshamim8/production-grade-rag/blob/main/main.py): `main.py`
- [Qdrant storage](https://github.com/adilshamim8/production-grade-rag/blob/main/vector_db.py): `vector_db.py`

### Packaged API

- [Packaged Streamlit UI](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/ui/streamlit_app.py): `rag-engine/src/rag_engine/ui/streamlit_app.py`
- [API application](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/app.py): `rag-engine/src/rag_engine/api/app.py`
- [Document routes](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/routes/documents.py): `rag-engine/src/rag_engine/api/routes/documents.py`
- [Query routes](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/routes/query.py): `rag-engine/src/rag_engine/api/routes/query.py`
- [Health routes](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/routes/health.py): `rag-engine/src/rag_engine/api/routes/health.py`
- [API schemas](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/models/schemas.py): `rag-engine/src/rag_engine/models/schemas.py`
- [Error middleware](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/middleware/error_handler.py): `rag-engine/src/rag_engine/api/middleware/error_handler.py`
- [Request logging](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/api/middleware/logging.py): `rag-engine/src/rag_engine/api/middleware/logging.py`

### Packaged RAG core

- [Document loading](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/core/document_loader.py): `rag-engine/src/rag_engine/core/document_loader.py`
- [Embedding service](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/core/embeddings.py): `rag-engine/src/rag_engine/core/embeddings.py`
- [RAG chain](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/core/rag_chain.py): `rag-engine/src/rag_engine/core/rag_chain.py`
- [Vector store manager](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/core/vector_store.py): `rag-engine/src/rag_engine/core/vector_store.py`

### Shared platform

- **Qdrant service**
- [Logging utilities](https://github.com/adilshamim8/production-grade-rag/blob/main/rag-engine/src/rag_engine/utils/logger.py): `rag-engine/src/rag_engine/utils/logger.py`

### Other components

- **Document user**
- **Model providers**
- **Inngest service**

## Connections

- Document user → Streamlit UI: uploads and queries (evidence: `README.md`)
- Streamlit UI → FastAPI workflow: starts workflow (evidence: `README.md`)
- Streamlit UI → PDF chunking: local ingestion (evidence: `streamlit_app.py`)
- Streamlit UI → Qdrant storage: local retrieval (evidence: `streamlit_app.py`)
- FastAPI workflow → Inngest steps: registers steps (evidence: `README.md`)
- Inngest steps → Inngest service: dispatches events (evidence: `README.md`)
- Inngest steps → PDF chunking: loads and chunks (evidence: `main.py`)
- Inngest steps → Embedding providers: embeds chunks (evidence: `main.py`)
- Inngest steps → Qdrant storage: upserts vectors (evidence: `main.py`)
- Inngest steps → Qdrant storage: searches vectors (evidence: `main.py`)
- FastAPI workflow → PDF chunking: loads and chunks (evidence: `main.py`)
- FastAPI workflow → Embedding providers: embeds text (evidence: `main.py`)
- FastAPI workflow → Qdrant storage: upserts and searches (evidence: `main.py`)
- FastAPI workflow → Grounded answers: generates answer (evidence: `main.py`)
- FastAPI workflow → Model providers: requests generation
- Embedding providers → Model providers: requests embeddings
- Packaged Streamlit UI → API application: uses service
- API application → Document routes: registers route (evidence: `rag-engine/src/rag_engine/api/app.py`)
- API application → Query routes: registers route (evidence: `rag-engine/src/rag_engine/api/app.py`)
- API application → Health routes: registers route (evidence: `rag-engine/src/rag_engine/api/app.py`)
- Document routes → RAG chain: ingests document (evidence: `rag-engine/src/rag_engine/api/routes/documents.py`)
- Query routes → RAG chain: runs query (evidence: `rag-engine/src/rag_engine/api/routes/query.py`)
- Health routes → Vector store manager: checks store (evidence: `rag-engine/src/rag_engine/api/routes/health.py`)
- Document routes → API schemas: uses request models (evidence: `rag-engine/src/rag_engine/api/routes/documents.py`)
- Query routes → API schemas: uses query models (evidence: `rag-engine/src/rag_engine/api/routes/query.py`)
- RAG chain → Document loading: processes documents
- RAG chain → Embedding service: creates embeddings
- RAG chain → Vector store manager: retrieves and indexes
- Vector store manager → Qdrant service: reads and writes (evidence: `rag-engine/src/rag_engine/core/vector_store.py`)
- API application → Logging utilities: gets logger (evidence: `rag-engine/src/rag_engine/api/app.py`)
- Request logging → Logging utilities: gets logger (evidence: `rag-engine/src/rag_engine/api/middleware/logging.py`)
- API application → Error middleware: configures middleware
