# saralgupta09/docuintelligence architecture

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

- Interactive diagram: https://gitdiagram.com/saralgupta09/docuintelligence
- Repository: https://github.com/saralgupta09/docuintelligence

## Overview

1. **Repository shape**
   - This is a two-tier app: a **FastAPI backend** under `backend/` and a **React/Vite frontend** under `frontend/`.
   - The backend is the real system boundary: it owns file ingestion, retrieval, conversation state, and persistence. The frontend is a thin client that calls backend APIs and renders chat/document UI.

2. **Backend entrypoint and API surface**
   - `backend/main.py` is the primary app bootstrap; `main_backup.py` and `ask_backup.py` show earlier iterations or fallback versions.
   - HTTP routes are split by domain in `backend/api/routes/`: `ingest.py`, `documents.py`, `conversations.py`, and `ask.py`.
   - This indicates the API is organized around document lifecycle, conversation lifecycle, and question-answering, rather than a generic CRUD service.

3. **Ingestion pipeline**
   - The ingestion path is centered on `POST /api/v1/ingest/` and is implemented through `backend/ingestion/`.
   - `pdf_processor.py` extracts page-level text from PDFs, `chunker.py` turns text into overlapping chunks with metadata, and `ocr_processor.py` exists for scanned/low-text documents.
   - The README’s Phase 1 flow matches the code structure: upload PDF → extract text → chunk → embed → store.

4. **Embedding and vector storage**
   - `backend/services/embedding_service.py` wraps local embeddings, using BGE-style embeddings per the README.
   - `backend/services/vector_store.py` persists chunks into **ChromaDB**, backed by the on-disk database in `backend/data/chroma_db/`.
   - `backend/data/uploads/` stores original uploaded PDFs, while Chroma holds chunk text, embeddings, and metadata for later retrieval.

5. **Retrieval and RAG orchestration**
   - Retrieval is not a single function; it is decomposed into services and graph nodes.
   - `backend/services/retrieval_service.py`, `bm25_service.py`, and `hybrid_retrieval_service.py` suggest multiple retrieval strategies: pure vector search, lexical BM25, and a hybrid combination.
   - `backend/graph/nodes/retrieve.py`, `rewrite.py`, and `generate.py` show a workflow where the query can be rewritten, relevant chunks fetched, and an answer generated from retrieved context.

6. **LangGraph-style workflow boundary**
   - `backend/graph/retrieval_graph.py` and `backend/graph/state.py` define the orchestration layer for the Q&A pipeline.
   - This is the main control boundary between request handling and model/retrieval logic: API route → graph state machine → retrieval/generation nodes → response.
   - The structure implies the app is designed to support multi-step reasoning and iterative retrieval, not just one-shot search.

7. **Conversation and memory**
   - Conversation persistence is split between `backend/memory/conversation_manager.py` and `backend/services/conversation_store.py`.
   - There is also a `backend/data/conversations.json`, which suggests lightweight local persistence for chat history.
   - This layer keeps chat state separate from document storage, so conversations can reference retrieved document chunks without mixing the two data models.

8. **Document and conversation APIs**
   - `documents.py` and `conversations.py` likely expose backend state to the UI: document listings, metadata, conversation threads, and message history.
   - `ask.py` is the main interactive endpoint for chat-style querying over the indexed documents.
   - This separation helps the frontend treat documents, chats, and answers as distinct screens or panels.

9. **Frontend architecture**
   - The frontend is a React app built with Vite and styled with Tailwind/PostCSS.
   - `src/App.jsx` composes the UI, while components like `ChatArea`, `ChatHistory`, `ChatInput`, `DocumentList`, `Sidebar`, `UploadSection`, and `PdfPreviewPanel` map directly to the backend concepts.
   - Hooks such as `useChat`, `useDocuments`, and `useBackendStatus` encapsulate API interaction and keep the UI components mostly presentational.

10. **Persistence and runtime state**
   - The repo uses a mostly local, file-based runtime model: uploaded PDFs, conversation JSON, and ChromaDB live inside `backend/data/`.
   - `backend/config.py` and `.env.example` centralize runtime settings; this is important because the app depends on local paths and model/database configuration.
   - `backend/utils/logger.py` provides structured logging, which is important for tracing ingestion timing, retrieval behavior, and API health.

11. **What matters most for an architecture diagram**
   - The key data flow is: **Frontend upload/query → FastAPI route → ingestion or retrieval service → ChromaDB / conversation store → response back to UI**.
   - There are two persistent data planes: **document/vector state** in ChromaDB and **chat state** in conversation storage.
   - The main architectural boundary is between the request/API layer and the internal workflow/services layer, with the graph module acting as the orchestration core for question answering.

12. **Repository maturity signal**
   - The README describes Phase 1 ingestion, but the tree shows the codebase has already expanded into retrieval, hybrid search, conversation management, and a richer UI.
   - So the repo is best understood as a **document intelligence platform** with a working ingestion core and a partially/fully implemented RAG chat stack built on top.

Main entry points: [`backend/api/routes`](https://github.com/saralgupta09/docuintelligence/tree/main/backend/api/routes) (API routes), [`frontend/src/App.jsx`](https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/App.jsx) (App shell), [`backend/ingestion`](https://github.com/saralgupta09/docuintelligence/tree/main/backend/ingestion) (Ingestion flow), [`backend/graph/nodes`](https://github.com/saralgupta09/docuintelligence/tree/main/backend/graph/nodes) (Graph nodes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_main["Main app<br/>FastAPI bootstrap<br/>[main.py]"]
  node_backend_routes["API routes<br/>HTTP surface"]
  node_route_ingest["Ingest API<br/>upload endpoint<br/>[ingest.py]"]
  node_route_docs["Documents API<br/>document endpoint<br/>[documents.py]"]
  node_route_convos["Conversations API<br/>chat endpoint<br/>[conversations.py]"]
  node_route_ask["Ask API<br/>qa endpoint<br/>[ask.py]"]
  node_ingestion_pipeline{{"Ingestion flow<br/>pipeline"}}
  node_pdf_processor["PDF parse<br/>extractor<br/>[pdf_processor.py]"]
  node_chunker["Chunk text<br/>chunker<br/>[chunker.py]"]
  node_ocr_processor["OCR fallback<br/>[ocr_processor.py]"]
  node_embedding_service(("Embeddings<br/>embedding service"))
  node_vector_store[("Vector store<br/>ChromaDB service<br/>[vector_store.py]")]
  node_retrieval_graph{{"Retrieval graph<br/>orchestration<br/>[retrieval_graph.py]"}}
  node_graph_nodes["Graph nodes<br/>workflow nodes"]
  node_retrieve_node["Retrieve<br/>graph node<br/>[retrieve.py]"]
  node_rewrite_node["Rewrite<br/>graph node<br/>[rewrite.py]"]
  node_generate_node["Generate<br/>graph node<br/>[generate.py]"]
  node_retrieval_services["Retrieval services<br/>search layer"]
  node_llm_service(("LLM service<br/>model service<br/>[llm_service.py]"))
  node_conversation_store[("Conversation store<br/>chat persistence")]
  node_conversation_manager["Memory manager<br/>session state"]
end

subgraph group_frontend["Frontend"]
  node_frontend_app["App shell<br/>React app<br/>[App.jsx]"]
  node_frontend_api["API client<br/>frontend data access<br/>[client.js]"]
  node_ui_chat["Chat UI<br/>presentation<br/>[ChatArea.jsx]"]
  node_ui_docs["Document UI<br/>presentation<br/>[DocumentList.jsx]"]
  node_ui_shell["Shell UI<br/>presentation<br/>[Sidebar.jsx]"]
  node_hooks["UI hooks<br/>state hooks"]
end

subgraph group_data["Local Data"]
  node_uploads["Uploads<br/>local files"]
  node_chroma_db[("ChromaDB<br/>vector index")]
  node_conversations_json["Chat JSON<br/>conversation file<br/>[conversations.json]"]
end

node_frontend_app -->|"calls"| node_frontend_api
node_frontend_app -->|"renders"| node_ui_chat
node_frontend_app -->|"renders"| node_ui_docs
node_frontend_app -->|"wraps"| node_ui_shell
node_frontend_app -->|"uses"| node_hooks
node_frontend_api -->|"requests"| node_backend_routes
node_backend_main -->|"mounts"| node_backend_routes
node_backend_routes -->|"includes"| node_route_ingest
node_backend_routes -->|"includes"| node_route_docs
node_backend_routes -->|"includes"| node_route_convos
node_backend_routes -->|"includes"| node_route_ask
node_route_ingest -->|"starts"| node_ingestion_pipeline
node_ingestion_pipeline -->|"extracts"| node_pdf_processor
node_ingestion_pipeline -.->|"fallback"| node_ocr_processor
node_ingestion_pipeline -->|"chunks"| node_chunker
node_ingestion_pipeline -->|"embeds"| node_embedding_service
node_embedding_service -->|"stores"| node_vector_store
node_vector_store -->|"persists to"| node_chroma_db
node_route_ask -->|"orchestrates"| node_retrieval_graph
node_retrieval_graph -->|"runs"| node_graph_nodes
node_graph_nodes -->|"contains"| node_rewrite_node
node_graph_nodes -->|"contains"| node_retrieve_node
node_graph_nodes -->|"contains"| node_generate_node
node_retrieve_node -->|"uses"| node_retrieval_services
node_retrieval_services -->|"queries"| node_vector_store
node_retrieval_services -->|"may use"| node_llm_service
node_route_convos -->|"uses"| node_conversation_manager
node_conversation_manager -->|"persists"| node_conversation_store
node_conversation_store -->|"backs"| node_conversations_json
node_route_docs -->|"reads"| node_vector_store
node_route_ingest -->|"writes"| node_uploads

click node_backend_main "https://github.com/saralgupta09/docuintelligence/blob/main/backend/main.py"
click node_backend_routes "https://github.com/saralgupta09/docuintelligence/tree/main/backend/api/routes"
click node_route_ingest "https://github.com/saralgupta09/docuintelligence/blob/main/backend/api/routes/ingest.py"
click node_route_docs "https://github.com/saralgupta09/docuintelligence/blob/main/backend/api/routes/documents.py"
click node_route_convos "https://github.com/saralgupta09/docuintelligence/blob/main/backend/api/routes/conversations.py"
click node_route_ask "https://github.com/saralgupta09/docuintelligence/blob/main/backend/api/routes/ask.py"
click node_ingestion_pipeline "https://github.com/saralgupta09/docuintelligence/tree/main/backend/ingestion"
click node_pdf_processor "https://github.com/saralgupta09/docuintelligence/blob/main/backend/ingestion/pdf_processor.py"
click node_chunker "https://github.com/saralgupta09/docuintelligence/blob/main/backend/ingestion/chunker.py"
click node_ocr_processor "https://github.com/saralgupta09/docuintelligence/blob/main/backend/ingestion/ocr_processor.py"
click node_embedding_service "https://github.com/saralgupta09/docuintelligence/blob/main/backend/services/embedding_service.py"
click node_vector_store "https://github.com/saralgupta09/docuintelligence/blob/main/backend/services/vector_store.py"
click node_retrieval_graph "https://github.com/saralgupta09/docuintelligence/blob/main/backend/graph/retrieval_graph.py"
click node_graph_nodes "https://github.com/saralgupta09/docuintelligence/tree/main/backend/graph/nodes"
click node_retrieve_node "https://github.com/saralgupta09/docuintelligence/blob/main/backend/graph/nodes/retrieve.py"
click node_rewrite_node "https://github.com/saralgupta09/docuintelligence/blob/main/backend/graph/nodes/rewrite.py"
click node_generate_node "https://github.com/saralgupta09/docuintelligence/blob/main/backend/graph/nodes/generate.py"
click node_retrieval_services "https://github.com/saralgupta09/docuintelligence/tree/main/backend/services"
click node_llm_service "https://github.com/saralgupta09/docuintelligence/blob/main/backend/services/llm_service.py"
click node_conversation_store "https://github.com/saralgupta09/docuintelligence/blob/main/backend/services/conversation_store.py"
click node_conversation_manager "https://github.com/saralgupta09/docuintelligence/blob/main/backend/memory/conversation_manager.py"
click node_frontend_app "https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/App.jsx"
click node_frontend_api "https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/api/client.js"
click node_ui_chat "https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/components/ChatArea.jsx"
click node_ui_docs "https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/components/DocumentList.jsx"
click node_ui_shell "https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/components/Sidebar.jsx"
click node_hooks "https://github.com/saralgupta09/docuintelligence/tree/main/frontend/src/hooks"
click node_uploads "https://github.com/saralgupta09/docuintelligence/tree/main/backend/data/uploads"
click node_chroma_db "https://github.com/saralgupta09/docuintelligence/tree/main/backend/data/chroma_db"
click node_conversations_json "https://github.com/saralgupta09/docuintelligence/blob/main/backend/data/conversations.json"

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_backend_main,node_backend_routes,node_route_ingest,node_route_docs,node_route_convos,node_route_ask,node_ingestion_pipeline,node_pdf_processor,node_chunker,node_ocr_processor,node_embedding_service,node_vector_store,node_retrieval_graph,node_graph_nodes,node_retrieve_node,node_rewrite_node,node_generate_node,node_retrieval_services,node_llm_service,node_conversation_store,node_conversation_manager toneBlue
class node_frontend_app,node_frontend_api,node_ui_chat,node_ui_docs,node_ui_shell,node_hooks toneAmber
class node_uploads,node_chroma_db,node_conversations_json toneMint
```

## Components

### Backend

FastAPI app, ingestion, retrieval, and persistence services

- [Main app](https://github.com/saralgupta09/docuintelligence/blob/main/backend/main.py): FastAPI bootstrap · Application startup and server wiring · `backend/main.py`
- [API routes](https://github.com/saralgupta09/docuintelligence/tree/main/backend/api/routes): HTTP surface · Domain-routed endpoints for ingest, documents, conversations, and ask · `backend/api/routes`
- [Ingest API](https://github.com/saralgupta09/docuintelligence/blob/main/backend/api/routes/ingest.py): upload endpoint · Starts document ingestion and indexing · `backend/api/routes/ingest.py`
- [Documents API](https://github.com/saralgupta09/docuintelligence/blob/main/backend/api/routes/documents.py): document endpoint · Lists and exposes indexed documents and metadata · `backend/api/routes/documents.py`
- [Conversations API](https://github.com/saralgupta09/docuintelligence/blob/main/backend/api/routes/conversations.py): chat endpoint · Reads and updates conversation threads and message history · `backend/api/routes/conversations.py`
- [Ask API](https://github.com/saralgupta09/docuintelligence/blob/main/backend/api/routes/ask.py): qa endpoint · Interactive question-answering endpoint over indexed documents · `backend/api/routes/ask.py`
- [Ingestion flow](https://github.com/saralgupta09/docuintelligence/tree/main/backend/ingestion): pipeline · PDF extraction, chunking, embedding, and storage · `backend/ingestion`
- [PDF parse](https://github.com/saralgupta09/docuintelligence/blob/main/backend/ingestion/pdf_processor.py): extractor · Extracts text from PDFs page by page · `backend/ingestion/pdf_processor.py`
- [Chunk text](https://github.com/saralgupta09/docuintelligence/blob/main/backend/ingestion/chunker.py): chunker · Creates overlapping chunks with metadata · `backend/ingestion/chunker.py`
- [OCR fallback](https://github.com/saralgupta09/docuintelligence/blob/main/backend/ingestion/ocr_processor.py): ocr · Handles scanned or low-text documents · `backend/ingestion/ocr_processor.py`
- [Embeddings](https://github.com/saralgupta09/docuintelligence/blob/main/backend/services/embedding_service.py): embedding service · Generates local vector embeddings · `backend/services/embedding_service.py`
- [Vector store](https://github.com/saralgupta09/docuintelligence/blob/main/backend/services/vector_store.py): ChromaDB service · Persists chunks and embeddings for retrieval · `backend/services/vector_store.py`
- [Retrieval graph](https://github.com/saralgupta09/docuintelligence/blob/main/backend/graph/retrieval_graph.py): orchestration · Stateful workflow for rewrite, retrieve, and generate · `backend/graph/retrieval_graph.py`
- [Graph nodes](https://github.com/saralgupta09/docuintelligence/tree/main/backend/graph/nodes): workflow nodes · Query rewrite, retrieval, and answer generation steps · `backend/graph/nodes`
- [Retrieve](https://github.com/saralgupta09/docuintelligence/blob/main/backend/graph/nodes/retrieve.py): graph node · Fetches relevant chunks for the current query · `backend/graph/nodes/retrieve.py`
- [Rewrite](https://github.com/saralgupta09/docuintelligence/blob/main/backend/graph/nodes/rewrite.py): graph node · Transforms queries before retrieval when needed · `backend/graph/nodes/rewrite.py`
- [Generate](https://github.com/saralgupta09/docuintelligence/blob/main/backend/graph/nodes/generate.py): graph node · Builds the final answer from retrieved context · `backend/graph/nodes/generate.py`
- [Retrieval services](https://github.com/saralgupta09/docuintelligence/tree/main/backend/services): search layer · Vector, BM25, and hybrid retrieval implementations · `backend/services`
- [LLM service](https://github.com/saralgupta09/docuintelligence/blob/main/backend/services/llm_service.py): model service · Model access used for generation and reasoning · `backend/services/llm_service.py`
- [Conversation store](https://github.com/saralgupta09/docuintelligence/blob/main/backend/services/conversation_store.py): chat persistence · Persists conversation state separate from documents · `backend/services/conversation_store.py`
- [Memory manager](https://github.com/saralgupta09/docuintelligence/blob/main/backend/memory/conversation_manager.py): session state · Coordinates chat history and memory behavior · `backend/memory/conversation_manager.py`

### Frontend

React/Vite client UI and API hooks

- [App shell](https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/App.jsx): React app · Top-level UI composition · `frontend/src/App.jsx`
- [API client](https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/api/client.js): frontend data access · Wraps backend calls for the UI · `frontend/src/api/client.js`
- [Chat UI](https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/components/ChatArea.jsx): presentation · Chat area, input, history, and message display · `frontend/src/components/ChatArea.jsx`
- [Document UI](https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/components/DocumentList.jsx): presentation · Document list and upload/preview panels · `frontend/src/components/DocumentList.jsx`
- [Shell UI](https://github.com/saralgupta09/docuintelligence/blob/main/frontend/src/components/Sidebar.jsx): presentation · Sidebar, top bar, and layout components · `frontend/src/components/Sidebar.jsx`
- [UI hooks](https://github.com/saralgupta09/docuintelligence/tree/main/frontend/src/hooks): state hooks · Chat, document, and backend-status hooks · `frontend/src/hooks`

### Local Data

On-disk uploads, chat state, and vector index

- [Uploads](https://github.com/saralgupta09/docuintelligence/tree/main/backend/data/uploads): local files · Stored source PDFs · `backend/data/uploads`
- [ChromaDB](https://github.com/saralgupta09/docuintelligence/tree/main/backend/data/chroma_db): vector index · On-disk vector database for retrieved chunks · `backend/data/chroma_db`
- [Chat JSON](https://github.com/saralgupta09/docuintelligence/blob/main/backend/data/conversations.json): conversation file · File-backed conversation history · `backend/data/conversations.json`

## Connections

- App shell → API client: calls · UI actions are translated into backend requests
- App shell → Chat UI: renders · Main screen includes chat interaction surfaces
- App shell → Document UI: renders · Main screen includes document browsing and upload surfaces
- App shell → Shell UI: wraps · Layout and navigation structure the app
- App shell → UI hooks: uses · Shared hooks manage data loading and interaction state
- API client → API routes: requests · Frontend talks to domain routes in the backend
- Main app → API routes: mounts · Application bootstrap registers the HTTP surface
- API routes → Ingest API: includes · Ingestion endpoint
- API routes → Documents API: includes · Document endpoint
- API routes → Conversations API: includes · Conversation endpoint
- API routes → Ask API: includes · Question-answering endpoint
- Ingest API → Ingestion flow: starts · Upload requests enter the ingestion flow
- Ingestion flow → PDF parse: extracts · Reads PDF text before chunking
- Ingestion flow → OCR fallback: fallback · Used when PDFs need OCR
- Ingestion flow → Chunk text: chunks · Turns extracted text into retrievable segments
- Ingestion flow → Embeddings: embeds · Creates vector representations for chunks
- Embeddings → Vector store: stores · Embedding output is persisted in the vector index
- Vector store → ChromaDB: persists to · ChromaDB is the physical vector backing store
- Ask API → Retrieval graph: orchestrates · Ask endpoint delegates answer construction to the workflow
- Retrieval graph → Graph nodes: runs · Graph coordinates the main QA steps
- Graph nodes → Rewrite: contains · Query rewrite step
- Graph nodes → Retrieve: contains · Retrieval step
- Graph nodes → Generate: contains · Answer generation step
- Retrieve → Retrieval services: uses · Retrieval node calls search implementations
- Retrieval services → Vector store: queries · Vector and hybrid search read from the index
- Retrieval services → LLM service: may use · Generation and rewrite can involve the model service
- Conversations API → Memory manager: uses · Conversation endpoints coordinate memory behavior
- Memory manager → Conversation store: persists · Conversation state is saved separately from documents
- Conversation store → Chat JSON: backs · Local file-backed chat history
- Documents API → Vector store: reads · Document listing reflects indexed chunks and metadata
- Ingest API → Uploads: writes · Original uploaded PDFs are stored on disk
