# madhusudandesai1/synthese-api-ai-rag-pdf-extractor architecture

> Architecture diagram of the GitHub repository madhusudandesai1/synthese-api-ai-rag-pdf-extractor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor
- Repository: https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor

## Overview

Synthese is a PDF question-answering application. A user uploads a PDF through the browser; the API saves it and schedules background extraction, chunking, and indexing. For questions, the API retrieves a document-specific chunk from ChromaDB, sends grounded context to Gemini, and streams the answer and source snippets back to the browser. The implementation excerpt shows these backend stages in main.py and browser request handling in static/script.js; the README documents the UI and RAG behavior.

Main entry points: [`main.py`](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py) (FastAPI endpoints), [`static/script.js`](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/static/script.js) (Upload and query client), [`static/index.html`](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/static/index.html) (Web interface), [`data/chroma`](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/tree/main/data/chroma) (ChromaDB collection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser interface"]
  node_ui["Web interface<br/>[index.html]"]
  node_browser_logic["Upload and query client<br/>[script.js]"]
end

subgraph group_api["API and processing"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_upload_storage["Temporary PDF files<br/>[main.py]"]
  node_pdf_processing["PDF extraction and chunking<br/>[main.py]"]
end

subgraph group_retrieval["Document retrieval"]
  node_chroma[("ChromaDB collection")]
  node_retrieval_step["Document-scoped search<br/>[main.py]"]
end

subgraph group_generation["Answer generation"]
  node_prompt["Grounded prompt<br/>[main.py]"]
  node_stream["Answer and sources stream<br/>[main.py]"]
end

node_user(("User"))
node_gemini{{"Gemini API"}}

node_user -->|"uses"| node_ui
node_ui -->|"loads"| node_browser_logic
node_browser_logic -->|"posts upload"| node_api
node_browser_logic -->|"posts question"| node_api
node_api -->|"saves PDF"| node_upload_storage
node_api -->|"schedules"| node_pdf_processing
node_pdf_processing -->|"stores chunks"| node_chroma
node_api -->|"handles query"| node_retrieval_step
node_retrieval_step -->|"searches chunks"| node_chroma
node_retrieval_step -->|"provides context"| node_prompt
node_prompt -->|"generates answer"| node_gemini
node_api -->|"returns stream"| node_stream
node_stream -->|"sends answer and sources"| node_browser_logic

click node_ui "https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/static/index.html"
click node_browser_logic "https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/static/script.js"
click node_api "https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py"
click node_upload_storage "https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py"
click node_pdf_processing "https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py"
click node_chroma "https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/tree/main/data/chroma"
click node_retrieval_step "https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py"
click node_prompt "https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py"
click node_stream "https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.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_ui,node_browser_logic,node_user toneBlue
class node_api,node_upload_storage,node_pdf_processing toneAmber
class node_chroma,node_retrieval_step,node_gemini toneMint
class node_prompt,node_stream toneRose
```

## Components

### Browser interface

- [Web interface](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/static/index.html): `static/index.html`
- [Upload and query client](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/static/script.js): `static/script.js`

### API and processing

- [FastAPI endpoints](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py): `main.py`
- [Temporary PDF files](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py): `main.py`
- [PDF extraction and chunking](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py): `main.py`

### Document retrieval

- [ChromaDB collection](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/tree/main/data/chroma): `data/chroma`
- [Document-scoped search](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py): `main.py`

### Answer generation

- [Grounded prompt](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py): `main.py`
- [Answer and sources stream](https://github.com/madhusudandesai1/synthese-api-ai-rag-pdf-extractor/blob/main/main.py): `main.py`

### Other components

- **User**
- **Gemini API**

## Connections

- User → Web interface: uses (evidence: `README.md`)
- Web interface → Upload and query client: loads (evidence: `README.md`)
- Upload and query client → FastAPI endpoints: posts upload (evidence: `static/script.js`)
- Upload and query client → FastAPI endpoints: posts question (evidence: `static/script.js`)
- FastAPI endpoints → Temporary PDF files: saves PDF (evidence: `main.py`)
- FastAPI endpoints → PDF extraction and chunking: schedules (evidence: `main.py`)
- PDF extraction and chunking → ChromaDB collection: stores chunks (evidence: `main.py`)
- FastAPI endpoints → Document-scoped search: handles query (evidence: `main.py`)
- Document-scoped search → ChromaDB collection: searches chunks (evidence: `main.py`)
- Document-scoped search → Grounded prompt: provides context (evidence: `main.py`)
- Grounded prompt → Gemini API: generates answer (evidence: `main.py`)
- FastAPI endpoints → Answer and sources stream: returns stream (evidence: `main.py`)
- Answer and sources stream → Upload and query client: sends answer and sources (evidence: `static/script.js`)
