# subbuparavatareddy/geminiragresearchassistant architecture

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

- Interactive diagram: https://gitdiagram.com/subbuparavatareddy/geminiragresearchassistant
- Repository: https://github.com/subbuparavatareddy/geminiragresearchassistant

## Overview

#### Purpose and Entry Points
This is a local research-paper RAG assistant: users upload PDF/TXT papers, index them into a persistent vector store, then ask grounded questions. The backend API starts from `Backend/main.py`; the browser client starts from `Frontend/my-react-app/src/main.jsx` and renders the application in `Frontend/my-react-app/src/App.jsx`.

#### Client Interaction Layer
The React/Vite client provides the two user workflows: select/upload a paper and submit a question. It sends multipart uploads to `POST /upload`, sends question JSON to `POST /query`, and displays the generated answer plus retrieved evidence. Primary UI boundary: `Frontend/my-react-app/src/App.jsx`; build/runtime setup: `Frontend/my-react-app/package.json`, `Frontend/my-react-app/vite.config.js`.

#### FastAPI API Boundary
`Backend/main.py` owns the HTTP service and coordinates the RAG lifecycle. `/upload` accepts the document and triggers loading, chunking, embedding, and persistence. `/query` retrieves relevant chunks, calls the LLM, and returns an `answer` and source metadata. The backend is intended to run under Uvicorn on port 8000; API documentation is exposed by FastAPI.

#### Document Ingestion and Indexing
Upload handling distinguishes PDF from text: LangChain loaders extract document text, then a recursive text splitter produces overlapping chunks (README specifies 1,000 characters with 200 overlap). Chunks are embedded through Google’s `gemini-embedding-001` and written to the shared Chroma collection. Uploaded/example source material exists under `Backend/data/` and root `data/`, including `Backend/data/bert_paper.txt` and `Backend/data/ofosu-ampong.pdf`.

#### Persistent Retrieval Store
ChromaDB is local and durable rather than an external managed database. Its persisted state is under `Backend/chroma_db/`, including `Backend/chroma_db/chroma.sqlite3`. This is a single shared store: documents are not separated by user, session, or paper collection. Query retrieval is similarity-based and selects the top three chunks, with no re-ranking or metadata isolation.

#### Answer Generation Flow
For `/query`, the backend embeds the user question, retrieves the closest Chroma chunks, and supplies those passages as grounding context to Gemini 2.5 Flash. Gemini synthesizes a one-shot answer; the API also returns the raw chunks/metadata so the client can show evidence. The core orchestration and provider calls are centralized in `Backend/main.py`.

#### Runtime, Secrets, and External Services
Python 3.10+ hosts FastAPI, LangChain, document parsing, ChromaDB, and Google Gemini integration; dependencies are declared in `requirements.txt` and `pyproject.toml`. Node.js 18+ runs the Vite React client via `Frontend/my-react-app/package.json`. Google AI Studio is the only required external service: its API key is read from `Backend/.env`. Chroma persistence, document files, and the API server are local infrastructure.

Main entry points: [`Backend/main.py`](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/main.py) (POST /query), [`Frontend/my-react-app/src/App.jsx`](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Frontend/my-react-app/src/App.jsx) (Paper Q&A UI), [`Backend/.env`](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/.env) (Google API key), [`Frontend/my-react-app/src/main.jsx`](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Frontend/my-react-app/src/main.jsx) (React entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser Client"]
  node_client_entry["React entry<br/>Vite entry<br/>[main.jsx]"]
  node_app["Paper Q&amp;A UI<br/>React UI<br/>[App.jsx]"]
  node_client_runtime["Vite runtime<br/>Node build/runtime<br/>[package.json]"]
end

subgraph group_backend["RAG API"]
  node_api["FastAPI RAG service<br/>API orchestration<br/>[main.py]"]
  node_upload["POST /upload<br/>ingestion endpoint<br/>[main.py]"]
  node_query["POST /query<br/>query endpoint<br/>[main.py]"]
  node_loaders["PDF/TXT loaders<br/>LangChain loading"]
  node_splitter["Recursive splitter<br/>chunking"]
  node_retrieval["Top-3 similarity retrieval<br/>Chroma retrieval<br/>[main.py]"]
  node_python_deps["Python dependencies<br/>Python runtime<br/>[requirements.txt]"]
end

subgraph group_local["Local Persistence"]
  node_sources["Paper files<br/>local documents<br/>[bert_paper.txt]"]
  node_shared_store[("Shared Chroma collection<br/>persistent vector store<br/>[chroma.sqlite3]")]
  node_api_key["Google API key<br/>environment secret<br/>[.env]"]
end

subgraph group_google["Google AI"]
  node_embedding{{"Gemini embeddings<br/>gemini-embedding-001"}}
  node_generation{{"Gemini answer generation<br/>Gemini 2.5 Flash"}}
end

node_client_entry -->|"renders"| node_app
node_client_runtime -->|"runs"| node_client_entry
node_app -->|"multipart upload"| node_upload
node_app -->|"question JSON"| node_query
node_upload -->|"handled by"| node_api
node_query -->|"handled by"| node_api
node_upload -->|"stores source"| node_sources
node_upload -->|"extracts text"| node_loaders
node_loaders -->|"documents"| node_splitter
node_splitter -->|"chunk vectors"| node_embedding
node_embedding -->|"writes embeddings"| node_shared_store
node_query -->|"embeds question"| node_embedding
node_embedding -->|"query vector"| node_retrieval
node_retrieval -->|"similarity search"| node_shared_store
node_retrieval -->|"grounding chunks"| node_generation
node_generation -->|"answer"| node_query
node_query -->|"answer and evidence"| node_app
node_api_key -.->|"authenticates"| node_embedding
node_api_key -.->|"authenticates"| node_generation
node_python_deps -.->|"provides runtime"| node_api

click node_client_entry "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Frontend/my-react-app/src/main.jsx"
click node_app "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Frontend/my-react-app/src/App.jsx"
click node_client_runtime "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Frontend/my-react-app/package.json"
click node_api "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/main.py"
click node_upload "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/main.py"
click node_query "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/main.py"
click node_retrieval "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/main.py"
click node_sources "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/data/bert_paper.txt"
click node_shared_store "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/chroma_db/chroma.sqlite3"
click node_api_key "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/.env"
click node_python_deps "https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/requirements.txt"

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_client_entry,node_app,node_client_runtime toneBlue
class node_api,node_upload,node_query,node_loaders,node_splitter,node_retrieval,node_python_deps toneAmber
class node_sources,node_shared_store,node_api_key toneMint
class node_embedding,node_generation toneRose
```

## Components

### Browser Client

- [React entry](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Frontend/my-react-app/src/main.jsx): Vite entry · `Frontend/my-react-app/src/main.jsx`
- [Paper Q&A UI](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Frontend/my-react-app/src/App.jsx): React UI · Uploads papers and displays answers with evidence. · `Frontend/my-react-app/src/App.jsx`
- [Vite runtime](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Frontend/my-react-app/package.json): Node build/runtime · `Frontend/my-react-app/package.json`

### RAG API

- [FastAPI RAG service](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/main.py): API orchestration · Owns upload, retrieval, generation, and response assembly. · `Backend/main.py`
- [POST /upload](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/main.py): ingestion endpoint · `Backend/main.py`
- [POST /query](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/main.py): query endpoint · `Backend/main.py`
- **PDF/TXT loaders**: LangChain loading · Extracts text according to uploaded document type.
- **Recursive splitter**: chunking · Creates overlapping 1,000-character chunks.
- [Top-3 similarity retrieval](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/main.py): Chroma retrieval · Returns nearest chunks without reranking or isolation. · `Backend/main.py`
- [Python dependencies](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/requirements.txt): Python runtime · FastAPI, LangChain, ChromaDB, and parsing dependencies. · `requirements.txt`

### Local Persistence

- [Paper files](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/data/bert_paper.txt): local documents · Uploaded and example PDF/TXT source material. · `Backend/data/bert_paper.txt`
- [Shared Chroma collection](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/chroma_db/chroma.sqlite3): persistent vector store · Single collection shared across papers, users, and sessions. · `Backend/chroma_db/chroma.sqlite3`
- [Google API key](https://github.com/subbuparavatareddy/geminiragresearchassistant/blob/master/Backend/.env): environment secret · `Backend/.env`

### Google AI

- **Gemini embeddings**: gemini-embedding-001
- **Gemini answer generation**: Gemini 2.5 Flash · Synthesizes a grounded one-shot answer.

## Connections

- React entry → Paper Q&A UI: renders
- Vite runtime → React entry: runs
- Paper Q&A UI → POST /upload: multipart upload
- Paper Q&A UI → POST /query: question JSON
- POST /upload → FastAPI RAG service: handled by
- POST /query → FastAPI RAG service: handled by
- POST /upload → Paper files: stores source
- POST /upload → PDF/TXT loaders: extracts text
- PDF/TXT loaders → Recursive splitter: documents
- Recursive splitter → Gemini embeddings: chunk vectors
- Gemini embeddings → Shared Chroma collection: writes embeddings
- POST /query → Gemini embeddings: embeds question
- Gemini embeddings → Top-3 similarity retrieval: query vector
- Top-3 similarity retrieval → Shared Chroma collection: similarity search
- Top-3 similarity retrieval → Gemini answer generation: grounding chunks
- Gemini answer generation → POST /query: answer
- POST /query → Paper Q&A UI: answer and evidence
- Google API key → Gemini embeddings: authenticates
- Google API key → Gemini answer generation: authenticates
- Python dependencies → FastAPI RAG service: provides runtime
