How aparna-adev/docsenseai works
Purpose and entry points
Simple RAG is a tenant-aware document retrieval and chat system. It exposes a FastAPI backend and a React/Vite client. Backend startup is backend/app/main.py; durable ingestion runs separately through backend/app/worker.py; vector backfills use backend/app/reindex.py. The browser entry is frontend/src/main.tsx, rendering the application in frontend/src/App.tsx.
API, identity, and tenancy
FastAPI routes partition the system into authentication, projects/collections, document lifecycle, ingestion, search, chat, and health operations. JWT-based authentication and account handling form the primary tenant boundary; request-scoped authorization must constrain both metadata and retrieval.
• backend/app/auth.py
• backend/app/routes/auth.py
• backend/app/routes/projects.py
• backend/app/routes/documents.py
Durable document-ingestion pipeline
The API accepts and validates uploads, stores metadata/files, and creates durable SQLite-backed ingestion jobs rather than performing extraction synchronously. The worker claims jobs idempotently, supports retries/cancellation/stale-lock recovery, then parses documents, extracts structured content, chunks it, embeds it, and upserts vectors. Versioning means retrieval should target current document versions.
• backend/app/routes/upload.py
• backend/app/routes/ingestion.py
• backend/app/services/ingestion_jobs.py
• backend/app/services/document_loader.py
• backend/app/services/chunking.py
• backend/app/services/embeddings.py
Content-format processing boundary
Ingestion has specialized paths for PDFs/layout, images with OCR/vision, spreadsheets/workbooks, structured CSV, folders, and ZIP archives. These normalize diverse sources into document content/chunks before they enter common embedding and vector-store stages.
• backend/app/services/pdf_layout.py
• backend/app/services/image_processor/
• backend/app/services/workbook_analysis.py
• backend/app/services/structured_ingestion.py
• backend/app/services/zip_archives.py
Retrieval and RAG answer pipeline
Search combines vector retrieval with keyword search, source filtering/selection, and access controls. Chat builds bounded conversation context, retrieves eligible sources, applies the RAG prompt, and calls the Groq LLM client; diagnostics expose decision and retrieval visibility. Citation/source extraction is a first-class response concern.
• backend/app/routes/chat.py
• backend/app/services/rag_service.py
• backend/app/services/vector_search.py
• backend/app/services/keyword_search.py
• backend/app/services/source_selection.py
• backend/app/services/groq_client.py
Persistence, infrastructure, and operations
SQLite is the durable system of record for users, documents, versions, and jobs; Qdrant holds retrieval vectors and is required for production readiness. Uploaded originals are stored under local backend data/storage abstractions. The service provides readiness and metrics endpoints; Qdrant can be run via Compose.
• backend/app/database.py
• backend/app/services/vector_store.py
• backend/app/services/storage.py
• backend/app/routes/health.py
• docker-compose.yml
Frontend integration
The React SPA communicates with the FastAPI base URL via a centralized API service. Its primary product surfaces are chat, document library/upload, account/settings, and dashboard views; shared application state is held in context.
• frontend/src/services/api.ts
• frontend/src/context/AppContext.tsx
• frontend/src/components/ChatArea.tsx
• frontend/src/components/LibraryPage.tsx
• frontend/src/components/UploadDocumentsModal.tsx
Main entry points: main.py FastAPI server · database.py SQLite · App.tsx Application shell · upload.py Upload and ingestion API
Components 21
React client
- React SPA
frontend/src/main.tsx - Application shell · Provides chat, library, upload, dashboard, and account surfaces.
frontend/src/App.tsx - API client
frontend/src/services/api.ts - App state
frontend/src/context/AppContext.tsx
Backend API
- FastAPI server
backend/app/main.py - JWT identity · Establishes account and tenant authorization for requests.
backend/app/auth.py - Project and document API
backend/app/routes/documents.py - Upload and ingestion API · Validates uploads and creates durable ingestion jobs.
backend/app/routes/upload.py - Chat API
backend/app/routes/chat.py
Durable ingestion
- Job coordinator · Claims jobs idempotently and handles retry, cancellation, and stale locks.
backend/app/services/ingestion_jobs.py - Ingestion worker
backend/app/worker.py - Content processors · Normalizes PDF, image/OCR, workbook, CSV, folder, and ZIP content.
backend/app/services/document_loader.py - Chunking
backend/app/services/chunking.py - Embeddings
backend/app/services/embeddings.py
Retrieval and RAG
- RAG orchestration · Builds bounded context, prompts the LLM, and returns citations.
backend/app/services/rag_service.py - Eligible-source retrieval · Combines vector search, keyword search, selection, and access constraints.
backend/app/services/vector_search.py - Groq LLM
backend/app/services/groq_client.py
Persistence and infrastructure
- SQLite · Stores users, documents, versions, and ingestion jobs.
backend/app/database.py - Original file storage
backend/app/services/storage.py - Qdrant · Holds retrieval vectors for current document versions.
backend/app/services/vector_store.py - Vector reindexer · Backfills vectors independently of ingestion.
backend/app/reindex.py
Connections 24
- React SPA → Application shell: renders
- Application shell → API client: uses
- Application shell → App state: shares state
- API client → FastAPI server: HTTP API
- FastAPI server → JWT identity: authenticates
- FastAPI server → Project and document API: serves
- FastAPI server → Upload and ingestion API: serves
- FastAPI server → Chat API: serves
- JWT identity → SQLite: accounts and tenancy
- Project and document API → SQLite: document metadata
- Upload and ingestion API → Original file storage: stores originals
- Upload and ingestion API → Job coordinator: enqueues
- Job coordinator → SQLite: persists jobs
- Ingestion worker → Job coordinator: claims jobs
- Ingestion worker → Content processors: processes
- Content processors → Chunking: normalized content
- Chunking → Embeddings: chunks
- Embeddings → Qdrant: upserts vectors
- Chat API → RAG orchestration: answers
- RAG orchestration → Eligible-source retrieval: retrieves sources
- Eligible-source retrieval → Qdrant: vector search
- Eligible-source retrieval → SQLite: keywords and access metadata
- RAG orchestration → Groq LLM: RAG prompt
- Vector reindexer → Qdrant: backfills vectors