How saralgupta09/docuintelligence works
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: routes API routes · App.jsx App shell · ingestion Ingestion flow · nodes Graph nodes
Components 30
Backend
FastAPI app, ingestion, retrieval, and persistence services
- Main app · Application startup and server wiring
backend/main.py - API routes · Domain-routed endpoints for ingest, documents, conversations, and ask
backend/api/routes - Ingest API · Starts document ingestion and indexing
backend/api/routes/ingest.py - Documents API · Lists and exposes indexed documents and metadata
backend/api/routes/documents.py - Conversations API · Reads and updates conversation threads and message history
backend/api/routes/conversations.py - Ask API · Interactive question-answering endpoint over indexed documents
backend/api/routes/ask.py - Ingestion flow · PDF extraction, chunking, embedding, and storage
backend/ingestion - PDF parse · Extracts text from PDFs page by page
backend/ingestion/pdf_processor.py - Chunk text · Creates overlapping chunks with metadata
backend/ingestion/chunker.py - OCR fallback · Handles scanned or low-text documents
backend/ingestion/ocr_processor.py - Embeddings · Generates local vector embeddings
backend/services/embedding_service.py - Vector store · Persists chunks and embeddings for retrieval
backend/services/vector_store.py - Retrieval graph · Stateful workflow for rewrite, retrieve, and generate
backend/graph/retrieval_graph.py - Graph nodes · Query rewrite, retrieval, and answer generation steps
backend/graph/nodes - Retrieve · Fetches relevant chunks for the current query
backend/graph/nodes/retrieve.py - Rewrite · Transforms queries before retrieval when needed
backend/graph/nodes/rewrite.py - Generate · Builds the final answer from retrieved context
backend/graph/nodes/generate.py - Retrieval services · Vector, BM25, and hybrid retrieval implementations
backend/services - LLM service · Model access used for generation and reasoning
backend/services/llm_service.py - Conversation store · Persists conversation state separate from documents
backend/services/conversation_store.py - Memory manager · Coordinates chat history and memory behavior
backend/memory/conversation_manager.py
Frontend
React/Vite client UI and API hooks
- App shell · Top-level UI composition
frontend/src/App.jsx - API client · Wraps backend calls for the UI
frontend/src/api/client.js - Chat UI · Chat area, input, history, and message display
frontend/src/components/ChatArea.jsx - Document UI · Document list and upload/preview panels
frontend/src/components/DocumentList.jsx - Shell UI · Sidebar, top bar, and layout components
frontend/src/components/Sidebar.jsx - UI hooks · Chat, document, and backend-status hooks
frontend/src/hooks
Connections 31
- 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