# kashishbhutia/ragpdfanalyser architecture

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

- Interactive diagram: https://gitdiagram.com/kashishbhutia/ragpdfanalyser
- Repository: https://github.com/kashishbhutia/ragpdfanalyser

## Overview

Smart Document Analyzer lets users upload PDFs, wait for processing, then ask document-specific questions and see grounded answers with page citations; chat history persists per document. The graph covers the UI/API, upload and indexing stages, retrieval and answer generation, and persistence. The README documents the major capabilities; edges are limited to relationships shown in excerpts or explicitly documented, so unsampled internals are not inferred.

Main entry points: [`server/src/controllers/document.controller.ts`](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/controllers/document.controller.ts) (Document controller), [`client/src/pages/Home.tsx`](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/pages/Home.tsx) (Home workflow), [`server/src/controllers/chat.controller.ts`](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/controllers/chat.controller.ts) (Chat controller), [`server/src/services/rag.service.ts`](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/rag.service.ts) (RAG orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_home["Home workflow<br/>[Home.tsx]"]
  node_chatui["Chat interface<br/>[ChatInterface.tsx]"]
  node_uploadui["Document upload<br/>[DocumentUpload.tsx]"]
  node_doclist["Document list<br/>[DocumentList.tsx]"]
  node_message["Message display<br/>[MessageBubble.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API and orchestration"]
  node_http_api["HTTP API<br/>[app.ts]"]
  node_doc_routes["Document routes<br/>[document.routes.ts]"]
  node_doc_controller["Document controller"]
  node_chat_controller["Chat controller<br/>[chat.controller.ts]"]
  node_chat_routes["Chat routes<br/>[chat.routes.ts]"]
  node_upload_middleware["File upload middleware<br/>[upload.ts]"]
end

subgraph group_indexing["PDF indexing"]
  node_pdf["PDF extraction<br/>[pdf.service.ts]"]
  node_chunking["Text chunking"]
  node_embedding["Embedding service"]
end

subgraph group_qa["Retrieval and answers"]
  node_rag["RAG orchestration<br/>[rag.service.ts]"]
  node_vector[("Vector search store")]
end

subgraph group_persistence["Persistence"]
  node_documents[("Document records<br/>[Document.model.ts]")]
  node_history[("Chat history records")]
end

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

node_user -->|"uses"| node_home
node_home -->|"renders"| node_chatui
node_home -->|"renders"| node_uploadui
node_home -->|"renders"| node_doclist
node_chatui -->|"submits queries"| node_api_client
node_chatui -->|"renders messages"| node_message
node_uploadui -->|"uploads PDF"| node_api_client
node_home -->|"loads documents and history"| node_api_client
node_api_client -->|"HTTP requests"| node_http_api
node_http_api -->|"mounts routes"| node_doc_routes
node_http_api -->|"mounts routes"| node_chat_routes
node_doc_routes -->|"accepts files"| node_upload_middleware
node_doc_routes -->|"dispatches"| node_doc_controller
node_chat_routes -->|"dispatches"| node_chat_controller
node_doc_controller -->|"creates and updates"| node_documents
node_doc_controller -->|"extracts pages"| node_pdf
node_doc_controller -->|"chunks text"| node_chunking
node_doc_controller -->|"embeds chunks"| node_embedding
node_doc_controller -->|"stores vectors"| node_vector
node_doc_controller -->|"deletes history"| node_history
node_chat_controller -->|"checks readiness"| node_documents
node_chat_controller -->|"runs query"| node_rag
node_chat_controller -->|"saves and reads"| node_history
node_rag -->|"embeds query"| node_embedding
node_rag -->|"retrieves chunks"| node_vector
node_rag -->|"generates answer"| node_gemini
node_embedding -->|"requests embeddings"| node_gemini

click node_home "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/pages/Home.tsx"
click node_chatui "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/components/ChatInterface.tsx"
click node_uploadui "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/components/DocumentUpload.tsx"
click node_doclist "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/components/DocumentList.tsx"
click node_message "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/components/MessageBubble.tsx"
click node_api_client "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/services/api.ts"
click node_http_api "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/app.ts"
click node_doc_routes "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/routes/document.routes.ts"
click node_doc_controller "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/controllers/document.controller.ts"
click node_chat_controller "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/controllers/chat.controller.ts"
click node_chat_routes "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/routes/chat.routes.ts"
click node_upload_middleware "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/middleware/upload.ts"
click node_pdf "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/pdf.service.ts"
click node_chunking "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/chunking.service.ts"
click node_embedding "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/embedding.service.ts"
click node_rag "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/rag.service.ts"
click node_vector "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/vectorStore.service.ts"
click node_documents "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/models/Document.model.ts"
click node_history "https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/models/ChatHistory.model.ts"

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_home,node_chatui,node_uploadui,node_doclist,node_message,node_api_client,node_user toneBlue
class node_http_api,node_doc_routes,node_doc_controller,node_chat_controller,node_chat_routes,node_upload_middleware toneAmber
class node_pdf,node_chunking,node_embedding toneMint
class node_rag,node_vector toneRose
class node_documents,node_history,node_gemini toneIndigo
```

## Components

### Web client

- [Home workflow](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/pages/Home.tsx): `client/src/pages/Home.tsx`
- [Chat interface](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/components/ChatInterface.tsx): `client/src/components/ChatInterface.tsx`
- [Document upload](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/components/DocumentUpload.tsx): `client/src/components/DocumentUpload.tsx`
- [Document list](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/components/DocumentList.tsx): `client/src/components/DocumentList.tsx`
- [Message display](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/components/MessageBubble.tsx): `client/src/components/MessageBubble.tsx`
- [API client](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/client/src/services/api.ts): `client/src/services/api.ts`

### API and orchestration

- [HTTP API](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/app.ts): `server/src/app.ts`
- [Document routes](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/routes/document.routes.ts): `server/src/routes/document.routes.ts`
- [Document controller](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/controllers/document.controller.ts): `server/src/controllers/document.controller.ts`
- [Chat controller](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/controllers/chat.controller.ts): `server/src/controllers/chat.controller.ts`
- [Chat routes](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/routes/chat.routes.ts): `server/src/routes/chat.routes.ts`
- [File upload middleware](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/middleware/upload.ts): `server/src/middleware/upload.ts`

### PDF indexing

- [PDF extraction](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/pdf.service.ts): `server/src/services/pdf.service.ts`
- [Text chunking](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/chunking.service.ts): `server/src/services/chunking.service.ts`
- [Embedding service](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/embedding.service.ts): `server/src/services/embedding.service.ts`

### Retrieval and answers

- [RAG orchestration](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/rag.service.ts): `server/src/services/rag.service.ts`
- [Vector search store](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/services/vectorStore.service.ts): `server/src/services/vectorStore.service.ts`

### Persistence

- [Document records](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/models/Document.model.ts): `server/src/models/Document.model.ts`
- [Chat history records](https://github.com/kashishbhutia/ragpdfanalyser/blob/main/server/src/models/ChatHistory.model.ts): `server/src/models/ChatHistory.model.ts`

### Other components

- **User**
- **Google Gemini**

## Connections

- User → Home workflow: uses (evidence: `README.md`)
- Home workflow → Chat interface: renders (evidence: `client/src/pages/Home.tsx`)
- Home workflow → Document upload: renders (evidence: `client/src/pages/Home.tsx`)
- Home workflow → Document list: renders
- Chat interface → API client: submits queries (evidence: `client/src/components/ChatInterface.tsx`)
- Chat interface → Message display: renders messages (evidence: `client/src/components/ChatInterface.tsx`)
- Document upload → API client: uploads PDF (evidence: `client/src/components/DocumentUpload.tsx`)
- Home workflow → API client: loads documents and history (evidence: `client/src/pages/Home.tsx`)
- API client → HTTP API: HTTP requests (evidence: `client/src/services/api.ts`)
- HTTP API → Document routes: mounts routes (evidence: `server/src/app.ts`)
- HTTP API → Chat routes: mounts routes (evidence: `server/src/app.ts`)
- Document routes → File upload middleware: accepts files (evidence: `server/src/routes/document.routes.ts`)
- Document routes → Document controller: dispatches (evidence: `server/src/routes/document.routes.ts`)
- Chat routes → Chat controller: dispatches (evidence: `server/src/routes/chat.routes.ts`)
- Document controller → Document records: creates and updates (evidence: `server/src/controllers/document.controller.ts`)
- Document controller → PDF extraction: extracts pages (evidence: `server/src/controllers/document.controller.ts`)
- Document controller → Text chunking: chunks text (evidence: `server/src/controllers/document.controller.ts`)
- Document controller → Embedding service: embeds chunks (evidence: `server/src/controllers/document.controller.ts`)
- Document controller → Vector search store: stores vectors (evidence: `server/src/controllers/document.controller.ts`)
- Document controller → Chat history records: deletes history (evidence: `server/src/controllers/document.controller.ts`)
- Chat controller → Document records: checks readiness (evidence: `server/src/controllers/chat.controller.ts`)
- Chat controller → RAG orchestration: runs query (evidence: `server/src/controllers/chat.controller.ts`)
- Chat controller → Chat history records: saves and reads (evidence: `server/src/controllers/chat.controller.ts`)
- RAG orchestration → Embedding service: embeds query (evidence: `server/src/services/rag.service.ts`)
- RAG orchestration → Vector search store: retrieves chunks (evidence: `server/src/services/rag.service.ts`)
- RAG orchestration → Google Gemini: generates answer (evidence: `server/src/services/rag.service.ts`)
- Embedding service → Google Gemini: requests embeddings (evidence: `server/src/services/embedding.service.ts`)
