# hasnainraza2004/venturedive-rag-assessment architecture

> Architecture diagram of the GitHub repository hasnainraza2004/venturedive-rag-assessment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hasnainraza2004/venturedive-rag-assessment
- Repository: https://github.com/hasnainraza2004/venturedive-rag-assessment

## Overview

1. This repository is a two-tier RAG application centered on a single Wikipedia article at a time. The backend owns ingestion, retrieval, and generation; the frontend is a thin React UI for submitting a URL, viewing the article summary, and chatting against the ingested content.

2. The runtime boundary is split into:
   - Frontend: React + Vite, served in production through nginx on port 3000.
   - Backend: Node.js + Express on port 4000.
   - External local AI services: Ollama on 11434 and ChromaDB on 8000.
   Docker Compose wires these together and sets the service URLs used by the backend.

3. The backend API is organized around three routes:
   - `POST /api/ingest` starts the article pipeline.
   - `POST /api/chat` answers questions using retrieval-augmented generation.
   - `GET /api/health` provides basic service health.
   These are the main architecture entry points for the diagram.

4. Ingestion is a staged pipeline implemented in `ingestService`:
   1) validate the provided Wikipedia URL,
   2) scrape and parse the article content in-process with Cheerio,
   3) summarize the article through Ollama,
   4) normalize and chunk the text,
   5) embed chunks through Ollama,
   6) upsert vectors into ChromaDB.
   This creates the searchable corpus for later chat requests.

5. Chat is a separate query-time pipeline implemented in `ragService`:
   1) embed the user query,
   2) retrieve top-k similar chunks from Chroma with a minimum score filter,
   3) build a RAG prompt using the retrieved context,
   4) call Ollama to generate the final answer.
   The architecture depends on retrieval quality from Chroma and generation quality from the local model.

6. ChromaDB is used as the vector store and is treated as the persistence layer for retrieved article chunks. The README notes a per-article collection model and cosine similarity retrieval, which means the backend effectively isolates content by article rather than maintaining a shared global corpus.

7. Ollama is the unified model runtime for both summarization/chat completion and embeddings. The repository uses local models only: `llama3.2:3b` for summarize/chat and `nomic-embed-text` for embeddings. This is an important architectural constraint because the system does not depend on hosted LLM APIs.

8. The backend keeps a small in-memory `articleState` object. The README indicates one URL per process, so the app is intentionally stateful only within the running backend instance. That makes the diagram simpler: the source of truth for the currently ingested article is ephemeral process memory, while the searchable chunks live in Chroma.

9. The backend is layered into clearly separated concerns:
   - `routes` for HTTP surface area,
   - `services` for business workflows,
   - `clients` for external service adapters,
   - `scraper` for article extraction,
   - `text` for normalization and chunking,
   - `prompts` for LLM prompt templates,
   - `middleware` for logging and error handling.
   This separation is useful for diagramming because the HTTP layer is not directly coupled to Chroma or Ollama; it goes through service and client boundaries.

10. The frontend’s role is presentation and API orchestration. Components like `UrlForm`, `SummaryPanel`, and `ChatBox` map naturally to the ingest-and-chat workflow: submit a Wikipedia URL, show the generated summary, then issue chat queries against the backend. `src/api/client.js` is the only obvious frontend boundary to the backend.

11. Testing is split along the same boundaries. Unit tests mock the Ollama and Chroma clients, while an integration suite exercises the real RAG path end-to-end with Wikipedia HTTP traffic nocked. That confirms the architecture is designed around replacing external dependencies with mocks at the client boundary.

12. Operationally, the whole system is containerized. The Ollama entrypoint script pulls required models on startup, and the compose setup expects enough disk for model storage. The main deployment picture is therefore a local, self-hosted AI stack: browser/UI → Express API → scraper / Ollama / Chroma, all running under Docker Compose.

Main entry points: [`backend/src/services/ingestService.js`](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/services/ingestService.js) (Ingest Service), [`frontend/src/api/client.js`](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/api/client.js) (API Client), [`docker-compose.yml`](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/docker-compose.yml) (Compose), [`frontend/src/App.jsx`](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/App.jsx) (React App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_browser(("User<br/>client"))
  node_frontend_app["React App<br/>ui<br/>[App.jsx]"]
  node_api_client["API Client<br/>http client<br/>[client.js]"]
  node_url_form["URL Form<br/>ui component<br/>[UrlForm.jsx]"]
  node_summary_panel["Summary Panel<br/>ui component<br/>[SummaryPanel.jsx]"]
  node_chat_box["Chat Box<br/>ui component<br/>[ChatBox.jsx]"]
end

subgraph group_backend["Backend"]
  node_backend_app["Express App<br/>api server<br/>[app.js]"]
  node_ingest_route["Ingest API<br/>route<br/>[ingest.js]"]
  node_chat_route["Chat API<br/>route<br/>[chat.js]"]
  node_health_route["Health API<br/>route<br/>[health.js]"]
  node_ingest_service["Ingest Service<br/>pipeline<br/>[ingestService.js]"]
  node_rag_service["RAG Service<br/>pipeline<br/>[ragService.js]"]
  node_scraper["Wikipedia Scraper<br/>extraction"]
  node_chunker["Text Chunker<br/>text prep<br/>[chunker.js]"]
  node_article_state(("Article State<br/>in-memory state<br/>[articleState.js]"))
  node_ollama_client["Ollama Client<br/>model adapter<br/>[ollamaClient.js]"]
  node_chroma_client["Chroma Client<br/>vector adapter<br/>[chromaClient.js]"]
  node_summarize_prompt["Summarize Prompt<br/>prompt template<br/>[summarize.js]"]
  node_rag_prompt["RAG Prompt<br/>prompt template<br/>[ragAnswer.js]"]
end

subgraph group_external["External services"]
  node_wikipedia(("Wikipedia<br/>source site"))
  node_ollama[("Ollama<br/>local model runtime")]
  node_chroma[("ChromaDB<br/>vector store")]
end

subgraph group_ops["Runtime"]
  node_nginx["nginx<br/>static server<br/>[nginx.conf]"]
  node_compose["Compose<br/>orchestrator<br/>[docker-compose.yml]"]
end

node_browser -->|"loads UI"| node_nginx
node_nginx -->|"serves"| node_frontend_app
node_frontend_app -->|"renders"| node_url_form
node_frontend_app -->|"renders"| node_summary_panel
node_frontend_app -->|"renders"| node_chat_box
node_url_form -->|"submits URL"| node_api_client
node_chat_box -->|"asks question"| node_api_client
node_api_client -->|"POST /api/ingest"| node_ingest_route
node_api_client -->|"POST /api/chat"| node_chat_route
node_api_client -->|"GET /api/health"| node_health_route
node_ingest_route -->|"starts pipeline"| node_ingest_service
node_chat_route -->|"starts pipeline"| node_rag_service
node_health_route -->|"reports status"| node_backend_app
node_ingest_service -->|"scrapes"| node_scraper
node_scraper -->|"fetches article"| node_wikipedia
node_ingest_service -->|"builds prompt"| node_summarize_prompt
node_ingest_service -->|"summarizes"| node_ollama_client
node_ingest_service -->|"normalizes chunks"| node_chunker
node_ingest_service -->|"updates"| node_article_state
node_ingest_service -->|"upserts chunks"| node_chroma_client
node_rag_service -->|"embeds and answers"| node_ollama_client
node_rag_service -->|"retrieves context"| node_chroma_client
node_rag_service -->|"builds prompt"| node_rag_prompt
node_ollama_client -->|"HTTP API"| node_ollama
node_chroma_client -->|"HTTP API"| node_chroma
node_compose -->|"starts"| node_nginx
node_compose -->|"starts"| node_backend_app
node_compose -->|"starts"| node_ollama
node_compose -->|"starts"| node_chroma

click node_frontend_app "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/App.jsx"
click node_api_client "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/api/client.js"
click node_url_form "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/components/UrlForm.jsx"
click node_summary_panel "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/components/SummaryPanel.jsx"
click node_chat_box "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/components/ChatBox.jsx"
click node_nginx "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/nginx.conf"
click node_compose "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/docker-compose.yml"
click node_backend_app "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/app.js"
click node_ingest_route "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/routes/ingest.js"
click node_chat_route "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/routes/chat.js"
click node_health_route "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/routes/health.js"
click node_ingest_service "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/services/ingestService.js"
click node_rag_service "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/services/ragService.js"
click node_scraper "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/scraper/wikipediaScraper.js"
click node_chunker "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/text/chunker.js"
click node_article_state "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/state/articleState.js"
click node_ollama_client "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/clients/ollamaClient.js"
click node_chroma_client "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/clients/chromaClient.js"
click node_summarize_prompt "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/prompts/summarize.js"
click node_rag_prompt "https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/prompts/ragAnswer.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_frontend_app,node_api_client,node_url_form,node_summary_panel,node_chat_box toneBlue
class node_backend_app,node_ingest_route,node_chat_route,node_health_route,node_ingest_service,node_rag_service,node_scraper,node_chunker,node_article_state,node_ollama_client,node_chroma_client,node_summarize_prompt,node_rag_prompt toneAmber
class node_wikipedia,node_ollama,node_chroma toneMint
class node_nginx,node_compose toneRose
```

## Components

### Frontend

React UI served through nginx

- **User**: client · Human interacting with the app
- [React App](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/App.jsx): ui · Vite-powered presentation layer · `frontend/src/App.jsx`
- [API Client](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/api/client.js): http client · Frontend boundary for backend requests · `frontend/src/api/client.js`
- [URL Form](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/components/UrlForm.jsx): ui component · Submits a Wikipedia URL · `frontend/src/components/UrlForm.jsx`
- [Summary Panel](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/components/SummaryPanel.jsx): ui component · Displays article summary · `frontend/src/components/SummaryPanel.jsx`
- [Chat Box](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/src/components/ChatBox.jsx): ui component · Collects and shows chat messages · `frontend/src/components/ChatBox.jsx`

### Backend

Express API and RAG workflow

- [Express App](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/app.js): api server · Backend HTTP runtime · `backend/src/app.js`
- [Ingest API](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/routes/ingest.js): route · POST /api/ingest entrypoint · `backend/src/routes/ingest.js`
- [Chat API](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/routes/chat.js): route · POST /api/chat entrypoint · `backend/src/routes/chat.js`
- [Health API](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/routes/health.js): route · GET /api/health entrypoint · `backend/src/routes/health.js`
- [Ingest Service](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/services/ingestService.js): pipeline · Validates, scrapes, summarizes, chunks, and stores article content · `backend/src/services/ingestService.js`
- [RAG Service](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/services/ragService.js): pipeline · Retrieval and answer generation workflow · `backend/src/services/ragService.js`
- [Wikipedia Scraper](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/scraper/wikipediaScraper.js): extraction · Fetches and parses article HTML · `backend/src/scraper/wikipediaScraper.js`
- [Text Chunker](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/text/chunker.js): text prep · Normalizes and chunks article text · `backend/src/text/chunker.js`
- [Article State](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/state/articleState.js): in-memory state · Current article URL and summary within the process · `backend/src/state/articleState.js`
- [Ollama Client](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/clients/ollamaClient.js): model adapter · Calls local LLM and embedding endpoints · `backend/src/clients/ollamaClient.js`
- [Chroma Client](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/clients/chromaClient.js): vector adapter · Stores and retrieves article chunks · `backend/src/clients/chromaClient.js`
- [Summarize Prompt](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/prompts/summarize.js): prompt template · Template for article summarization · `backend/src/prompts/summarize.js`
- [RAG Prompt](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/backend/src/prompts/ragAnswer.js): prompt template · Template for context-grounded answering · `backend/src/prompts/ragAnswer.js`

### External services

Local model and vector services plus Wikipedia

- **Wikipedia**: source site · External article source
- **Ollama**: local model runtime · Runs llama3.2 and embedding models
- **ChromaDB**: vector store · Per-article collection storage and retrieval

### Runtime

Container and serving boundary

- [nginx](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/frontend/nginx.conf): static server · Serves the frontend in production · `frontend/nginx.conf`
- [Compose](https://github.com/hasnainraza2004/venturedive-rag-assessment/blob/master/docker-compose.yml): orchestrator · Wires frontend, backend, and local AI services · `docker-compose.yml`

## Connections

- User → nginx: loads UI · User opens the production frontend
- nginx → React App: serves · nginx delivers the built React app
- React App → URL Form: renders · App composes the main UI areas
- React App → Summary Panel: renders · Shows generated article summary
- React App → Chat Box: renders · Shows the chat experience
- URL Form → API Client: submits URL · Starts ingestion through the backend
- Chat Box → API Client: asks question · Sends chat requests to the backend
- API Client → Ingest API: POST /api/ingest · Backend ingestion entrypoint
- API Client → Chat API: POST /api/chat · Backend chat entrypoint
- API Client → Health API: GET /api/health · Backend health check entrypoint
- Ingest API → Ingest Service: starts pipeline · Route delegates to ingestion workflow
- Chat API → RAG Service: starts pipeline · Route delegates to RAG workflow
- Health API → Express App: reports status · Simple service health surface
- Ingest Service → Wikipedia Scraper: scrapes · Extracts article content in-process
- Wikipedia Scraper → Wikipedia: fetches article · Reads the source page
- Ingest Service → Summarize Prompt: builds prompt · Prepares summarization input
- Ingest Service → Ollama Client: summarizes · Uses local model for summary generation
- Ingest Service → Text Chunker: normalizes chunks · Creates searchable text chunks
- Ingest Service → Article State: updates · Keeps current article in process memory
- Ingest Service → Chroma Client: upserts chunks · Persists vectors for the article
- RAG Service → Ollama Client: embeds and answers · Uses local model runtime for query embedding and completion
- RAG Service → Chroma Client: retrieves context · Fetches top-k similar chunks
- RAG Service → RAG Prompt: builds prompt · Combines question with retrieved context
- Ollama Client → Ollama: HTTP API · Calls local Ollama service
- Chroma Client → ChromaDB: HTTP API · Calls local ChromaDB service
- Compose → nginx: starts · Compose wires the frontend runtime
- Compose → Express App: starts · Compose wires the backend runtime
- Compose → Ollama: starts · Compose wires the model runtime
- Compose → ChromaDB: starts · Compose wires the vector store
