How shahvir-w/document-rag-app works
Project Type and Purpose
• This is a full-stack Retrieval-Augmented Generation (RAG) application.
• Frontend: React + TypeScript (Vite, Tailwind) providing document upload, PDF/text viewing, chat UI.
• Backend: FastAPI serving REST endpoints, orchestrating ChromaDB indexing/queries and summarization via Celery tasks.
• Datastore: ChromaDB (SQLite), Redis as Celery broker/cache, Docker Compose for service orchestration.
File Structure
• Top-level directories:
• frontend/ – React app (src/components, services, public)
• backend/ – FastAPI app (app/api, app/services, app/tasks)
• chromadb/ – SQLite data file
• docker-compose.yml – defines services: backend API, Celery worker, Redis, (optionally ChromaDB service)
• The backend uses:
• “api” for REST endpoints (chat.py, documentUpload.py, textUpload.py)
• “services” for high-level logic (createChroma, createSummary, queryChroma)
• “tasks” for asynchronous jobs (celery_config, chroma_tasks)
• The frontend calls a single backend API and handles rendering and user interaction.
README Insights
• RAG workflow: user uploads → text is chunked & embedded in ChromaDB → user queries via chat UI → system retrieves relevant embeddings → LLM summarization/response.
• Uses Celery + Redis for offloading heavy processing.
• Docker Compose brings up: FastAPI server (port 5000), Celery workers, Redis, and ChromaDB persistence.
Defining Main Components
a. User & UI Layer
• Browser client interacts over HTTPS to the React frontend.
b. Frontend Application
• Vite-served React app components (Chat, DocumentView, Compartments).
• API service module in src/services/api.ts for HTTP calls.
c. API Gateway / Backend
• FastAPI application (app/main.py) exposing endpoints.
• Endpoints in app/api.* handle upload and chat routes.
• Config module (config.py) for environment settings.
d. Service Layer
• app/services:
• createChroma: chunking & embedding document text → store in ChromaDB
• queryChroma: vector search to fetch relevant chunks
• createSummary: summarization/compartment logic
e. Task Queue
• Celery (app/tasks/*) with Redis broker & backend.
• Asynchronous jobs: chroma indexing, summarization tasks.
f. Data Stores & External Services
• ChromaDB (SQLite) as vector store.
• Redis for message brokering and caching.
• (Optionally) LLM provider’s external API if used for summarization/chat.
Relationships and Interactions
• Browser → Frontend (React) → HTTP → FastAPI
• FastAPI → synchronous calls to services.queryChroma for chat requests
• FastAPI → dispatch tasks to Celery (via Redis) for heavy processing (indexing/summarization)
• Celery Worker → access app/services implementations → read/write to ChromaDB → return results via Redis
• FastAPI → return final payload to frontend → UI update
Architectural Patterns & Design Principles
• Layered architecture: UI | API | Services | Data | Background Tasks
• Asynchronous task pattern: Celery + Redis decouples heavy compute from request-response cycle
• Modular separation: services vs. tasks vs. API vs. UI
• Single codebase orchestrated via Docker Compose for reproducible environments