# dhruvvv-sh/production-rag-document-assistant architecture

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

## Overview

This repository implements Stage 1 of a PDF document assistant: clients upload PDFs, which are validated, extracted page by page, chunked with page metadata, and stored for later lookup. The API also exposes liveness/readiness checks and document status. Configuration, SQLAlchemy session handling, and ORM models form the supporting persistence layer. The README describes retrieval, reranking, and answer-generation stages as future roadmap items; they are not included as runtime components. Relationships below are based on the sampled source and README.

Main entry points: [`src/app/api/routes.py`](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/api/routes.py) (Document Routes), [`src/app/services/ingestion.py`](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/services/ingestion.py) (Ingestion Service), [`src/app/database.py`](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/database.py) (DB Sessions), [`src/app/main.py`](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/main.py) (FastAPI App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_routes["Document Routes<br/>[routes.py]"]
  node_schemas["Response Schemas<br/>[schemas.py]"]
end

subgraph group_ingestion["PDF Ingestion"]
  node_ingestion["Ingestion Service<br/>[ingestion.py]"]
  node_pdf["PDF Extraction<br/>[pdf.py]"]
  node_chunker["Token Chunker<br/>[chunking.py]"]
end

subgraph group_persistence["Persistence"]
  node_session["DB Sessions<br/>[database.py]"]
  node_models["Document Models<br/>[models.py]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_runtime["Runtime Setup"]
  node_app["FastAPI App<br/>[main.py]"]
  node_settings["Service Settings<br/>[config.py]"]
end

node_client(("API Client"))

node_client -->|"sends requests"| node_app
node_app -->|"registers routes"| node_routes
node_app -->|"loads settings"| node_settings
node_routes -->|"reads limits"| node_settings
node_routes -->|"depends on"| node_session
node_routes -->|"calls ingest"| node_ingestion
node_routes -->|"creates chunker"| node_chunker
node_routes -->|"queries documents"| node_models
node_routes -->|"returns responses"| node_schemas
node_ingestion -->|"extracts pages"| node_pdf
node_ingestion -->|"chunks pages"| node_chunker
node_ingestion -->|"creates records"| node_models
node_models -->|"uses declarative base"| node_session
node_session -->|"gets database URL"| node_settings
node_session -->|"connects to"| node_postgres

click node_app "https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/main.py"
click node_routes "https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/api/routes.py"
click node_schemas "https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/schemas.py"
click node_settings "https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/config.py"
click node_session "https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/database.py"
click node_models "https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/models.py"
click node_ingestion "https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/services/ingestion.py"
click node_pdf "https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/services/pdf.py"
click node_chunker "https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/services/chunking.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_schemas,node_client toneBlue
class node_ingestion,node_pdf,node_chunker toneAmber
class node_session,node_models,node_postgres toneMint
class node_app,node_settings toneRose
```

## Components

### HTTP API

- [Document Routes](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/api/routes.py): `src/app/api/routes.py`
- [Response Schemas](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/schemas.py): `src/app/schemas.py`

### PDF Ingestion

- [Ingestion Service](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/services/ingestion.py): `src/app/services/ingestion.py`
- [PDF Extraction](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/services/pdf.py): `src/app/services/pdf.py`
- [Token Chunker](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/services/chunking.py): `src/app/services/chunking.py`

### Persistence

- [DB Sessions](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/database.py): `src/app/database.py`
- [Document Models](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/models.py): `src/app/models.py`
- **PostgreSQL**

### Runtime Setup

- [FastAPI App](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/main.py): `src/app/main.py`
- [Service Settings](https://github.com/dhruvvv-sh/production-rag-document-assistant/blob/main/src/app/config.py): `src/app/config.py`

### Other components

- **API Client**

## Connections

- API Client → FastAPI App: sends requests (evidence: `README.md`)
- FastAPI App → Document Routes: registers routes (evidence: `src/app/main.py`)
- FastAPI App → Service Settings: loads settings (evidence: `src/app/main.py`)
- Document Routes → Service Settings: reads limits (evidence: `src/app/api/routes.py`)
- Document Routes → DB Sessions: depends on (evidence: `src/app/api/routes.py`)
- Document Routes → Ingestion Service: calls ingest (evidence: `src/app/api/routes.py`)
- Document Routes → Token Chunker: creates chunker (evidence: `src/app/api/routes.py`)
- Document Routes → Document Models: queries documents (evidence: `src/app/api/routes.py`)
- Document Routes → Response Schemas: returns responses (evidence: `src/app/api/routes.py`)
- Ingestion Service → PDF Extraction: extracts pages (evidence: `src/app/services/ingestion.py`)
- Ingestion Service → Token Chunker: chunks pages (evidence: `src/app/services/ingestion.py`)
- Ingestion Service → Document Models: creates records (evidence: `src/app/services/ingestion.py`)
- Document Models → DB Sessions: uses declarative base (evidence: `src/app/models.py`)
- DB Sessions → Service Settings: gets database URL (evidence: `src/app/database.py`)
- DB Sessions → PostgreSQL: connects to (evidence: `README.md`)
