How utkarsh-aman/documind works
Purpose and Entry Points
DocuMind is a multi-user document RAG system: users authenticate with Google, upload documents, and query a chat interface grounded in only their own indexed content. The backend FastAPI application starts at backend/main.py; the Next.js client routes from frontend/src/app/page.tsx into login and protected dashboard experiences.
Client and Access Boundary
The Next.js App Router frontend provides the landing, Google sign-in, and dashboard workspace. Route middleware enforces client-side/server-edge access gating before dashboard rendering, while the backend remains the authority for authenticated API operations.
• frontend/src/middleware.ts
• frontend/src/app/login/page.tsx
• frontend/src/app/dashboard/page.tsx
Authentication and Tenant Isolation
Google OAuth verification provisions or identifies users, then backend JWT logic issues signed session tokens intended for HttpOnly/SameSite cookies. Backend auth dependencies resolve the current user for protected endpoints. That authenticated database user ID is the critical tenancy boundary and must be propagated into document access and retrieval filters.
• backend/src/auth/google_auth.py
• backend/src/auth/jwt_auth.py
• backend/src/auth/dependencies.py
API Orchestration and Persistence
backend/main.py owns FastAPI routing for authentication, document lifecycle, and chat operations. SQLAlchemy connection/model layers persist users, documents, chat/message records, and vector-related data in PostgreSQL. Alembic establishes the evolving relational schema, including chats/messages and pgvector/summaries.
• backend/main.py
• backend/src/database/connection.py
• backend/src/database/models.py
• backend/alembic/versions/b2c3d4e5f6g7_add_pgvector_and_summaries.py
Document Ingestion Pipeline
Upload handling parses supported source formats into text, splits content into chunks, generates embeddings, and records processing state for dashboard polling. Parsed content and generated metadata/summaries are persisted; embeddings feed the PostgreSQL pgvector store. This pipeline separates potentially expensive extraction/embedding work from later interactive retrieval.
• backend/src/data_loader.py
• backend/src/embedding.py
• backend/src/pgvector_store.py
RAG Query Pipeline
Chat requests first classify intent. Greetings/small talk can route directly to generation; document-overview requests use stored summaries; document questions retrieve user-filtered semantic candidates, with search/reranking support, then generate an answer using retrieved context. The generator is the boundary to the Groq LLM API.
• backend/src/rag/intent_router.py
• backend/src/rag/retriever.py
• backend/src/rag/generator.py
• backend/src/search.py
Runtime and Infrastructure
The system runs a Python 3.10+ FastAPI backend and Node/Next.js frontend. PostgreSQL is used either as hosted Neon (with SSL) or a local Compose-managed instance; pgvector supports similarity search. External dependencies include Google OAuth client credentials and a Groq API key. Docker builds the backend and Compose provisions backend plus local PostgreSQL.
• backend/Dockerfile
• docker-compose.yml
• backend/requirements.txt
• backend/.env.example
Main entry points: main.py FastAPI application · models.py SQLAlchemy data model · intent_router.py Intent routing · retriever.py Tenant-filtered retrieval
Components 18
Next.js client
- Landing entry
frontend/src/app/page.tsx - Google sign-in
frontend/src/app/login/page.tsx - Access middleware · Gates dashboard access before rendering.
frontend/src/middleware.ts - Dashboard workspace · Uploads documents and runs chat.
frontend/src/app/dashboard/page.tsx
FastAPI backend
- FastAPI application · Owns auth, document, and chat endpoints.
backend/main.py - Google OAuth verification
backend/src/auth/google_auth.py - JWT sessions · Issues signed cookie-oriented session tokens.
backend/src/auth/jwt_auth.py - Current-user dependency · Provides the user ID used as the tenancy boundary.
backend/src/auth/dependencies.py - Document ingestion · Extracts text, chunks content, and tracks processing state.
backend/src/data_loader.py - Embedding generation
backend/src/embedding.py
RAG pipeline
- Intent routing · Routes small talk, overview, and document questions.
backend/src/rag/intent_router.py - Tenant-filtered retrieval · Finds semantic candidates only for the authenticated user.
backend/src/rag/retriever.py - Search and reranking
backend/src/search.py - Answer generation · Sends prompts and retrieved context to Groq.
backend/src/rag/generator.py
Data services
- SQLAlchemy data model · Persists users, documents, chats, messages, and vector-related records.
backend/src/database/models.py - PostgreSQL + pgvector · Hosted Neon or Compose-managed PostgreSQL similarity store.
backend/src/pgvector_store.py - Vector and summary schema
backend/alembic/versions/b2c3d4e5f6g7_add_pgvector_and_summaries.py
Other components
- Groq LLM API
Connections 24
- Landing entry → Google sign-in: sign in
- Google sign-in → FastAPI application: OAuth request
- Access middleware → Dashboard workspace: permits protected route
- Dashboard workspace → FastAPI application: upload and chat API
- FastAPI application → Google OAuth verification: verifies Google identity
- Google OAuth verification → JWT sessions: provisions user and session
- FastAPI application → Current-user dependency: protects operations
- Current-user dependency → SQLAlchemy data model: user-scoped access
- FastAPI application → Document ingestion: document upload
- Document ingestion → Embedding generation: text chunks
- Document ingestion → SQLAlchemy data model: documents and status
- Embedding generation → PostgreSQL + pgvector: chunk vectors
- FastAPI application → Intent routing: chat request
- Intent routing → Answer generation: small talk
- Intent routing → Tenant-filtered retrieval: document question
- Intent routing → SQLAlchemy data model: overview summaries
- Tenant-filtered retrieval → Search and reranking: candidate ranking
- Search and reranking → PostgreSQL + pgvector: similarity search
- Current-user dependency → Tenant-filtered retrieval: tenant filter
- Tenant-filtered retrieval → Answer generation: retrieved context
- Answer generation → Groq LLM API: LLM completion
- FastAPI application → SQLAlchemy data model: chat persistence
- SQLAlchemy data model → PostgreSQL + pgvector: relational records
- Vector and summary schema → PostgreSQL + pgvector: creates pgvector and summaries