How saahilpal/rag-docanalyzer works
Document Analyzer is a chat-first PDF question-answering workspace. A user signs in, creates a conversation, uploads a PDF, waits for indexing, then asks questions and receives SSE-delivered answers grounded in retrieved document text. The API coordinates authentication, chat state, document attachment, quota checks, and generation; a database-polling worker parses and indexes files. The README documents frontend features and integrations beyond the sampled UI code; those relationships are shown as documented rather than implying unsampled implementation details.
Main entry points: chatController.js Chat orchestration · client.js PostgreSQL and pgvector · geminiService.js Gemini integration · api.ts API client
Components 24
Web workspace
- Next.js workspace
frontend/src/app/app/page.tsx - Sign-in UI
frontend/src/app/login/page.tsx - Auth state
frontend/src/hooks/use-auth.tsx - Chat workspace state
frontend/src/hooks/use-chat-workspace.tsx - API client
frontend/src/lib/api.ts - Firebase client
frontend/src/lib/firebase.ts
API and identity
- Express API
src/app.js - Auth routes
src/routes/authRoutes.js - Auth exchange
src/controllers/authController.js - User and session service
src/services/authService.js - Chat routes
src/routes/chatRoutes.js - Chat orchestration
src/controllers/chatController.js
Document indexing
- Document attachment
src/services/documentService.js - Indexing worker
src/services/documentWorkerService.js - File storage access
src/services/storageService.js
Grounded answers
- Retrieval and prompts
src/services/ragService.js - Gemini integration
src/services/geminiService.js
Persistence and limits
- Conversation persistence
src/services/chatService.js - PostgreSQL and pgvector
src/database/client.js - Chat quotas
src/services/quotaService.js
Other components
- User
- Firebase Auth
- Supabase Storage
- Google Gemini
Connections 32
- User → Sign-in UI: signs in
- Sign-in UI → Auth state: uses auth
- Auth state → Firebase client: uses client
- Firebase client → Firebase Auth: authenticates with
- Sign-in UI → API client: exchanges token
- Next.js workspace → Chat workspace state: uses workspace
- Chat workspace state → API client: requests data
- API client → Express API: calls API
- Express API → Auth routes: mounts routes
src/app.js - Express API → Chat routes: mounts routes
src/app.js - Auth routes → Auth exchange: dispatches
src/routes/authRoutes.js - Auth exchange → Firebase Auth: verifies token
src/controllers/authController.js - Auth exchange → User and session service: upserts user
src/controllers/authController.js - User and session service → PostgreSQL and pgvector: persists user
src/services/authService.js - Chat routes → Chat orchestration: dispatches
src/routes/chatRoutes.js - Chat orchestration → Conversation persistence: manages chats
src/controllers/chatController.js - Chat orchestration → Document attachment: manages attachments
src/controllers/chatController.js - Document attachment → File storage access: uploads file
src/services/documentService.js - File storage access → Supabase Storage: stores PDF
src/services/storageService.js - Document attachment → PostgreSQL and pgvector: records attachment
src/services/documentService.js - Indexing worker → PostgreSQL and pgvector: claims and indexes
src/services/documentWorkerService.js - Indexing worker → File storage access: downloads PDF
src/services/documentWorkerService.js - Indexing worker → Gemini integration: creates embeddings
src/services/documentWorkerService.js - Gemini integration → Google Gemini: requests embeddings
- Chat orchestration → Chat quotas: checks and consumes
src/controllers/chatController.js - Chat orchestration → Retrieval and prompts: generates reply
src/controllers/chatController.js - Retrieval and prompts → PostgreSQL and pgvector: retrieves chunks
src/services/ragService.js - Retrieval and prompts → Gemini integration: embeds and generates
src/services/ragService.js - Gemini integration → Google Gemini: generates answer
- Chat orchestration → API client: delivers SSE
- Chat orchestration → Conversation persistence: saves messages
src/controllers/chatController.js - Conversation persistence → PostgreSQL and pgvector: persists conversations
src/services/chatService.js