How notvishwas/rag-agent works
Project type & purpose (what you’re diagramming)
This is a small full-stack web app with:
• A single-page frontend (public/index.html) that includes:
• Document upload UI
• A bottom-left chat widget
• A Node.js/Express backend (server.js) that:
• Accepts uploads and stores file content
• Exposes REST endpoints for listing/deleting docs
• Implements a simple RAG flow by injecting all stored document text into a Gemini prompt
• An external dependency: Google Gemini API (model: gemini-2.0-flash per README)
Important architectural characteristic: No vector DB / embeddings. “Retrieval” here is effectively “use *all* uploaded docs as context” (in-memory) and ask Gemini to answer only from that context.
File structure signals (what maps to components)
From the tree:
• server.js → Backend service (Express routes, upload handling, Gemini integration, in-memory store)
• public/index.html → Frontend UI (Bootstrap + widget + API calls)
• public/ → Static assets served by backend (likely express.static)
• package.json → Runtime + scripts (npm start, npm run dev)
• uploads/ (mentioned in README; not shown in tree but implied) → File storage on local disk
• .env / .env.example (mentioned) → Configuration for secrets (GEMINI_API_KEY, PORT)
• Browser (User)
• Frontend page + chat widget
• Express server
• Upload handling / text extraction
• In-memory document store
• Uploads folder (disk)
• Gemini API
• Environment config (.env)
• REST endpoints as the contract boundary
Browser UI Container
• public/index.html (Bootstrap UI + chat widget)
• Calls REST API endpoints
Node.js/Express Container
• server.js
• Serves static UI + JSON API
Local File Storage
• uploads/ directory (raw uploaded files)
In-Memory Knowledge Store
• Documents array / map in server.js (stores extracted text + metadata)
External LLM
• Gemini 2.0 Flash API
• Upload flow:
• Browser → POST /api/upload → Express
• Express → write file to uploads/
• Express → extractText() → store extracted text in memory
• Express → response (document id, name, etc.)
• /delete flow:
• Browser → GET /api/documents → Express → read from in-memory store → response
• Browser → DELETE /api/documents/:id → Express → remove from memory + delete from disk → response
• Chat/RAG flow:
• Browser → POST /api/chat (user message)
• Express → build prompt (system instruction + concatenated docs + user question)
• Express → call Gemini API
• Express → return answer → Browser renders in widget
This is where you “separate into as many components as possible” while staying accurate:
Inside Backend (server.js)
• Static file serving (serves public/index.html)
• API Router:
• /api/health
• /api/upload
• /api/documents (GET)
• /api/documents/:id (DELETE)
• /api/chat
• Upload middleware / multipart handler (e.g., multer-like)
• extractText() module/function (noted in README; PDF parsing is currently naïve)
• Document Repository (in-memory array/map):
• stores {id, filename, extractedText, ...}
• Disk storage adapter:
• writes/removes actual files in uploads/
• Gemini client:
• reads GEMINI_API_KEY from env
• sends model=gemini-2.0-flash request
• returns generated text
Inside Frontend (public/index.html)
• Upload UI component (drag/drop + file picker)
• Document list component (renders uploaded docs + delete buttons)
• Chat trigger button (bottom-left bubble)
• API client functions:
• uploadDocument() -> POST /api/upload
• fetchDocuments() -> GET /api/documents
• deleteDocument(id) -> DELETE /api/documents/:id
• sendChat(message) -> POST /api/chat
Diagramming conventions (so it’s readable and unambiguous)
• “POST upload (multipart)”
• “Store file”
• “Extract text”
• “Build prompt (docs + question)”
• “LLM generate”
• “Return answer (JSON)”
• In-memory store is not durable
• PDF parsing is plain text unless pdf-parse is added
• RAG is full-context injection (no retrieval ranking)
• Don’t imply multi-service microservices; this is a single Node process serving both static UI and API.