# abhiram-t5/talktopdf architecture

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

- Interactive diagram: https://gitdiagram.com/abhiram-t5/talktopdf
- Repository: https://github.com/abhiram-t5/talktopdf

## Overview

TalkToPDF lets users upload PDFs, wait for asynchronous ingestion, then ask document-grounded questions and receive streamed answers with source references. The frontend selects or uploads documents and chats; Express routes requests to document, chat, and job controllers. Ingestion extracts, chunks, embeds, and stores content; chat embeds questions, retrieves relevant chunks, streams Gemini responses, and persists session history in Redis. README documents the broader capabilities; arrows for unsampled implementations are included only where the README or source index supports them.

Main entry points: [`backend/src/worker/ingestion.worker.js`](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/worker/ingestion.worker.js) (Ingestion worker), [`backend/src/controllers/chat.controller.js`](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/controllers/chat.controller.js) (Chat controller), [`backend/src/controllers/document.controller.js`](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/controllers/document.controller.js) (Document controller), [`backend/src/config/redis.js`](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/config/redis.js) (Redis queue and cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_app_ui["App shell<br/>[App.jsx]"]
  node_upload_ui["PDF upload<br/>[UploadArea.jsx]"]
  node_sidebar["Document sidebar<br/>[Sidebar.jsx]"]
  node_chat_ui["Chat interface<br/>[ChatBox.jsx]"]
  node_sse["SSE parser<br/>[sseParser.js]"]
  node_frontend_api["API client<br/>[api.js]"]
end

subgraph group_api["API and control"]
  node_express["Express app<br/>[app.js]"]
  node_doc_routes["Document routes<br/>[document.route.js]"]
  node_chat_routes["Chat routes<br/>[chat.route.js]"]
  node_job_routes["Job routes<br/>[job.route.js]"]
  node_doc_controller["Document controller"]
  node_chat_controller["Chat controller<br/>[chat.controller.js]"]
  node_job_controller["Job controller<br/>[job.controller.js]"]
  node_rate_limiter["Rate limiter"]
end

subgraph group_ingest["Document ingestion"]
  node_worker["Ingestion worker"]
  node_pdf["PDF extraction<br/>[pdf.service.js]"]
  node_chunker["Text chunker<br/>[chunker.service.js]"]
  node_embedding["Embedding service"]
end

subgraph group_qa["Grounded chat"]
  node_retrieval["Vector retrieval"]
  node_llm["Answer streaming<br/>[llm.service.js]"]
  node_history["Chat history<br/>[history.service.js]"]
end

subgraph group_state["Persistence and services"]
  node_documents[("Document metadata<br/>[document.model.js]")]
  node_chunks[("Embedded chunks<br/>[chunks.model.js]")]
  node_redis[("Redis queue and cache<br/>[redis.js]")]
end

node_user(("User"))
node_mongodb[("MongoDB Atlas")]
node_gemini{{"Gemini API"}}

node_user -->|"uses"| node_app_ui
node_app_ui -->|"renders"| node_upload_ui
node_app_ui -->|"renders"| node_sidebar
node_app_ui -->|"renders"| node_chat_ui
node_upload_ui -->|"uploads through"| node_frontend_api
node_sidebar -->|"loads documents"| node_frontend_api
node_chat_ui -->|"sends questions"| node_frontend_api
node_chat_ui -->|"parses stream"| node_sse
node_frontend_api -->|"HTTP requests"| node_express
node_express -->|"mounts"| node_doc_routes
node_express -->|"mounts"| node_chat_routes
node_express -->|"mounts"| node_job_routes
node_doc_routes -->|"routes to"| node_doc_controller
node_chat_routes -->|"routes to"| node_chat_controller
node_chat_routes -->|"applies"| node_rate_limiter
node_job_routes -->|"routes to"| node_job_controller
node_doc_controller -->|"creates and reads"| node_documents
node_doc_controller -->|"deletes chunks"| node_chunks
node_doc_controller -->|"queues ingestion"| node_redis
node_doc_controller -->|"enqueues job"| node_worker
node_worker -->|"reads queue and updates status"| node_redis
node_worker -->|"extracts text"| node_pdf
node_worker -->|"splits text"| node_chunker
node_worker -->|"embeds chunks"| node_embedding
node_worker -->|"stores vectors"| node_chunks
node_worker -->|"updates status"| node_documents
node_chat_controller -->|"checks document"| node_documents
node_chat_controller -->|"embeds question"| node_embedding
node_chat_controller -->|"requests matches"| node_retrieval
node_retrieval -->|"searches vectors"| node_chunks
node_chat_controller -->|"loads and saves"| node_history
node_chat_controller -->|"builds and streams answer"| node_llm
node_llm -->|"generates stream"| node_gemini
node_embedding -->|"creates embeddings"| node_gemini
node_history -->|"stores history"| node_redis
node_job_controller -->|"reads job status"| node_redis
node_documents -->|"persists metadata"| node_mongodb
node_chunks -->|"persists vectors"| node_mongodb
node_rate_limiter -->|"tracks request limits"| node_redis

click node_app_ui "https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/App.jsx"
click node_upload_ui "https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/components/UploadArea.jsx"
click node_sidebar "https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/components/Sidebar.jsx"
click node_chat_ui "https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/components/ChatBox.jsx"
click node_sse "https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/utils/sseParser.js"
click node_frontend_api "https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/utils/api.js"
click node_express "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/app.js"
click node_doc_routes "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/routes/document.route.js"
click node_chat_routes "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/routes/chat.route.js"
click node_job_routes "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/routes/job.route.js"
click node_doc_controller "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/controllers/document.controller.js"
click node_chat_controller "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/controllers/chat.controller.js"
click node_job_controller "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/controllers/job.controller.js"
click node_rate_limiter "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/middlewares/rateLimiter.middleware.js"
click node_worker "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/worker/ingestion.worker.js"
click node_pdf "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/pdf.service.js"
click node_chunker "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/chunker.service.js"
click node_embedding "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/embedding.service.js"
click node_retrieval "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/retrieval.service.js"
click node_llm "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/llm.service.js"
click node_history "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/history.service.js"
click node_documents "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/models/document.model.js"
click node_chunks "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/models/chunks.model.js"
click node_redis "https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/config/redis.js"

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_app_ui,node_upload_ui,node_sidebar,node_chat_ui,node_sse,node_frontend_api,node_user toneBlue
class node_express,node_doc_routes,node_chat_routes,node_job_routes,node_doc_controller,node_chat_controller,node_job_controller,node_rate_limiter,node_mongodb toneAmber
class node_worker,node_pdf,node_chunker,node_embedding,node_gemini toneMint
class node_retrieval,node_llm,node_history toneRose
class node_documents,node_chunks,node_redis toneIndigo
```

## Components

### User interface

- [App shell](https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/App.jsx): `frontend/src/App.jsx`
- [PDF upload](https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/components/UploadArea.jsx): `frontend/src/components/UploadArea.jsx`
- [Document sidebar](https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/components/Sidebar.jsx): `frontend/src/components/Sidebar.jsx`
- [Chat interface](https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/components/ChatBox.jsx): `frontend/src/components/ChatBox.jsx`
- [SSE parser](https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/utils/sseParser.js): `frontend/src/utils/sseParser.js`
- [API client](https://github.com/abhiram-t5/talktopdf/blob/master/frontend/src/utils/api.js): `frontend/src/utils/api.js`

### API and control

- [Express app](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/app.js): `backend/src/app.js`
- [Document routes](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/routes/document.route.js): `backend/src/routes/document.route.js`
- [Chat routes](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/routes/chat.route.js): `backend/src/routes/chat.route.js`
- [Job routes](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/routes/job.route.js): `backend/src/routes/job.route.js`
- [Document controller](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/controllers/document.controller.js): `backend/src/controllers/document.controller.js`
- [Chat controller](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/controllers/chat.controller.js): `backend/src/controllers/chat.controller.js`
- [Job controller](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/controllers/job.controller.js): `backend/src/controllers/job.controller.js`
- [Rate limiter](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/middlewares/rateLimiter.middleware.js): `backend/src/middlewares/rateLimiter.middleware.js`

### Document ingestion

- [Ingestion worker](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/worker/ingestion.worker.js): `backend/src/worker/ingestion.worker.js`
- [PDF extraction](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/pdf.service.js): `backend/src/services/pdf.service.js`
- [Text chunker](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/chunker.service.js): `backend/src/services/chunker.service.js`
- [Embedding service](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/embedding.service.js): `backend/src/services/embedding.service.js`

### Grounded chat

- [Vector retrieval](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/retrieval.service.js): `backend/src/services/retrieval.service.js`
- [Answer streaming](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/llm.service.js): `backend/src/services/llm.service.js`
- [Chat history](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/services/history.service.js): `backend/src/services/history.service.js`

### Persistence and services

- [Document metadata](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/models/document.model.js): `backend/src/models/document.model.js`
- [Embedded chunks](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/models/chunks.model.js): `backend/src/models/chunks.model.js`
- [Redis queue and cache](https://github.com/abhiram-t5/talktopdf/blob/master/backend/src/config/redis.js): `backend/src/config/redis.js`

### Other components

- **User**
- **MongoDB Atlas**
- **Gemini API**

## Connections

- User → App shell: uses (evidence: `README.md`)
- App shell → PDF upload: renders (evidence: `frontend/src/App.jsx`)
- App shell → Document sidebar: renders (evidence: `frontend/src/App.jsx`)
- App shell → Chat interface: renders (evidence: `frontend/src/App.jsx`)
- PDF upload → API client: uploads through (evidence: `frontend/src/components/UploadArea.jsx`)
- Document sidebar → API client: loads documents (evidence: `frontend/src/components/Sidebar.jsx`)
- Chat interface → API client: sends questions (evidence: `frontend/src/components/ChatBox.jsx`)
- Chat interface → SSE parser: parses stream (evidence: `frontend/src/components/ChatBox.jsx`)
- API client → Express app: HTTP requests (evidence: `README.md`)
- Express app → Document routes: mounts (evidence: `backend/src/app.js`)
- Express app → Chat routes: mounts (evidence: `backend/src/app.js`)
- Express app → Job routes: mounts (evidence: `backend/src/app.js`)
- Document routes → Document controller: routes to (evidence: `backend/src/routes/document.route.js`)
- Chat routes → Chat controller: routes to (evidence: `backend/src/routes/chat.route.js`)
- Chat routes → Rate limiter: applies (evidence: `backend/src/routes/chat.route.js`)
- Job routes → Job controller: routes to (evidence: `backend/src/routes/job.route.js`)
- Document controller → Document metadata: creates and reads (evidence: `backend/src/controllers/document.controller.js`)
- Document controller → Embedded chunks: deletes chunks (evidence: `backend/src/controllers/document.controller.js`)
- Document controller → Redis queue and cache: queues ingestion (evidence: `backend/src/controllers/document.controller.js`)
- Document controller → Ingestion worker: enqueues job (evidence: `README.md`)
- Ingestion worker → Redis queue and cache: reads queue and updates status (evidence: `backend/src/worker/ingestion.worker.js`)
- Ingestion worker → PDF extraction: extracts text (evidence: `backend/src/worker/ingestion.worker.js`)
- Ingestion worker → Text chunker: splits text (evidence: `backend/src/worker/ingestion.worker.js`)
- Ingestion worker → Embedding service: embeds chunks (evidence: `backend/src/worker/ingestion.worker.js`)
- Ingestion worker → Embedded chunks: stores vectors (evidence: `backend/src/worker/ingestion.worker.js`)
- Ingestion worker → Document metadata: updates status (evidence: `backend/src/worker/ingestion.worker.js`)
- Chat controller → Document metadata: checks document (evidence: `backend/src/controllers/chat.controller.js`)
- Chat controller → Embedding service: embeds question (evidence: `backend/src/controllers/chat.controller.js`)
- Chat controller → Vector retrieval: requests matches (evidence: `backend/src/controllers/chat.controller.js`)
- Vector retrieval → Embedded chunks: searches vectors (evidence: `backend/src/services/retrieval.service.js`)
- Chat controller → Chat history: loads and saves (evidence: `backend/src/controllers/chat.controller.js`)
- Chat controller → Answer streaming: builds and streams answer (evidence: `backend/src/controllers/chat.controller.js`)
- Answer streaming → Gemini API: generates stream (evidence: `backend/src/services/llm.service.js`)
- Embedding service → Gemini API: creates embeddings (evidence: `backend/src/services/embedding.service.js`)
- Chat history → Redis queue and cache: stores history (evidence: `backend/src/services/history.service.js`)
- Job controller → Redis queue and cache: reads job status (evidence: `backend/src/controllers/job.controller.js`)
- Document metadata → MongoDB Atlas: persists metadata (evidence: `README.md`)
- Embedded chunks → MongoDB Atlas: persists vectors (evidence: `README.md`)
- Rate limiter → Redis queue and cache: tracks request limits (evidence: `backend/src/middlewares/rateLimiter.middleware.js`)
