# senthil-netxyper/techjays_rag_senthil architecture

> Architecture diagram of the GitHub repository senthil-netxyper/techjays_rag_senthil, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/senthil-netxyper/techjays_rag_senthil
- Repository: https://github.com/senthil-netxyper/techjays_rag_senthil

## Overview

#### Purpose and entry points
RAGVault is a Django server-rendered application for PDF-scoped question answering. Users upload PDFs, which are indexed locally for semantic retrieval; chat answers are generated through OpenAI. Primary runtime entry points are `rag_project/manage.py`, `rag_project/rag_project/wsgi.py`, and `rag_project/rag_project/asgi.py`; root routing is in `rag_project/rag_project/urls.py`.

#### Web and persistence boundary
The `documents` Django app owns HTTP workflows, HTML rendering, and relational records. Routes map upload, document listing, document chat, and deletion through `rag_project/documents/urls.py` and `rag_project/documents/views.py`. Templates in `rag_project/documents/templates/documents/` provide the upload, management, and chat UI.

SQLite, managed through Django ORM, stores document metadata and durable chat history via `rag_project/documents/models.py`. Uploaded files are saved as Django media files. This relational store is separate from the vector index.

#### Ingestion transaction
Upload handling validates and creates a document record, then invokes the RAG ingestion path. PDF extraction and chunking occur in `rag_project/rag/document_loader.py`: PyMuPDF extracts text and LangChain’s recursive splitter emits 500-character chunks with 50-character overlap. Failures in extraction or indexing trigger cleanup of the relational record.

#### Embedding and vector-index layer
`rag_project/rag/embedding.py` loads the local Sentence Transformers `all-MiniLM-L6-v2` model and produces 384-dimensional embeddings. `rag_project/rag/vector_store.py` persists chunk text, embeddings, IDs, and metadata in a local ChromaDB collection using `./chroma_db`. Chunk metadata includes `document_id`, providing the critical tenancy/isolation boundary between documents.

#### Retrieval and generation pipeline
The chat view delegates question answering to `rag_project/rag/rag_pipeline.py`. The pipeline encodes the question, retrieves the top three semantically similar chunks restricted to the selected document, assembles their text as context, and requests an answer. Retrieval logic is isolated in `rag_project/rag/retriever.py`; OpenAI prompt construction and API invocation (`gpt-4.1-mini`, key from `OPENAI_API_KEY`) are in `rag_project/rag/generator.py`.

#### Query and history flow
For each chat request: browser → Django view → `ask_question(question, document_id)` → embedding/query against ChromaDB with a document-ID filter → grounded OpenAI completion → `ChatMessage` persistence → rendered chat history. The answer depends on both local retrieval infrastructure and the external OpenAI API; embeddings and ChromaDB operate locally.

#### Deletion consistency
Document deletion crosses both persistence systems: Django removes the document and associated chat messages through relational ownership, while vector-store operations delete that document’s indexed chunks. The deletion workflow is orchestrated from `rag_project/documents/views.py` and vector deletion is implemented in `rag_project/rag/vector_store.py`; these stores must remain synchronized to prevent stale retrieval data.

Main entry points: [`rag_project/documents/views.py`](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/documents/views.py) (Upload, chat & delete), [`rag_project/rag/rag_pipeline.py`](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/rag_pipeline.py) (Question-answer pipeline), [`rag_project/rag_project/urls.py`](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag_project/urls.py) (Root routing), [`rag_project/documents/models.py`](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/documents/models.py) (Document & chat records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Django Runtime"]
  node_manage{{"Django CLI<br/>entry point<br/>[manage.py]"}}
  node_wsgi{{"WSGI server<br/>deployment entry<br/>[wsgi.py]"}}
  node_asgi{{"ASGI server<br/>deployment entry<br/>[asgi.py]"}}
  node_root_urls["Root routing<br/>URL router<br/>[urls.py]"]
end

subgraph group_documents["Documents App"]
  node_document_urls["Document routes<br/>URL router<br/>[urls.py]"]
  node_views["Upload, chat &amp; delete<br/>Django views<br/>[views.py]"]
  node_templates["Document UI<br/>Django templates"]
  node_models["Document &amp; chat records<br/>Django models<br/>[models.py]"]
  node_sqlite[("SQLite<br/>relational database")]
  node_media["PDF media files<br/>file storage"]
end

subgraph group_rag["Local RAG"]
  node_loader["PDF extraction &amp; chunking<br/>ingestion stage<br/>[document_loader.py]"]
  node_embedding["Local embeddings<br/>Sentence Transformers<br/>[embedding.py]"]
  node_vector_store[("Chroma vector store<br/>local vector index<br/>[vector_store.py]")]
  node_pipeline["Question-answer pipeline<br/>RAG orchestrator<br/>[rag_pipeline.py]"]
  node_retriever["Scoped retrieval<br/>retrieval stage<br/>[retriever.py]"]
  node_generator["Grounded generation<br/>OpenAI client<br/>[generator.py]"]
end

node_openai(("OpenAI API<br/>external AI service"))

node_manage -->|"runs app routing"| node_root_urls
node_wsgi -->|"serves"| node_root_urls
node_asgi -->|"serves"| node_root_urls
node_root_urls -->|"includes"| node_document_urls
node_document_urls -->|"dispatches"| node_views
node_views -->|"renders"| node_templates
node_views -->|"creates, reads &amp; deletes"| node_models
node_models -->|"persists via ORM"| node_sqlite
node_views -->|"saves uploaded PDFs"| node_media
node_views -->|"indexes upload"| node_loader
node_loader -->|"chunk text"| node_embedding
node_embedding -->|"stores chunk vectors"| node_vector_store
node_views -->|"ask_question&#40;question, document_id&#41;"| node_pipeline
node_pipeline -->|"embeds question"| node_embedding
node_pipeline -->|"retrieves context"| node_retriever
node_retriever -->|"top 3; document_id filter"| node_vector_store
node_pipeline -->|"sends grounded context"| node_generator
node_generator -->|"completion request"| node_openai
node_pipeline -->|"answer"| node_views
node_views -->|"persists ChatMessage"| node_models
node_views -->|"deletes document chunks"| node_vector_store

click node_manage "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/manage.py"
click node_wsgi "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag_project/wsgi.py"
click node_asgi "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag_project/asgi.py"
click node_root_urls "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag_project/urls.py"
click node_document_urls "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/documents/urls.py"
click node_views "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/documents/views.py"
click node_models "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/documents/models.py"
click node_loader "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/document_loader.py"
click node_embedding "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/embedding.py"
click node_vector_store "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/vector_store.py"
click node_pipeline "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/rag_pipeline.py"
click node_retriever "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/retriever.py"
click node_generator "https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/generator.py"

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_manage,node_wsgi,node_asgi,node_root_urls toneBlue
class node_document_urls,node_views,node_templates,node_models,node_sqlite,node_media toneAmber
class node_loader,node_embedding,node_vector_store,node_pipeline,node_retriever,node_generator toneMint
class node_openai toneNeutral
```

## Components

### Django Runtime

- [Django CLI](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/manage.py): entry point · `rag_project/manage.py`
- [WSGI server](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag_project/wsgi.py): deployment entry · `rag_project/rag_project/wsgi.py`
- [ASGI server](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag_project/asgi.py): deployment entry · `rag_project/rag_project/asgi.py`
- [Root routing](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag_project/urls.py): URL router · `rag_project/rag_project/urls.py`

### Documents App

- [Document routes](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/documents/urls.py): URL router · `rag_project/documents/urls.py`
- [Upload, chat & delete](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/documents/views.py): Django views · Orchestrates document workflows. · `rag_project/documents/views.py`
- **Document UI**: Django templates · Upload, management, and chat pages.
- [Document & chat records](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/documents/models.py): Django models · `rag_project/documents/models.py`
- **SQLite**: relational database · Metadata and durable chat history.
- **PDF media files**: file storage

### Local RAG

- [PDF extraction & chunking](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/document_loader.py): ingestion stage · PyMuPDF extraction; 500-character chunks with 50-character overlap. · `rag_project/rag/document_loader.py`
- [Local embeddings](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/embedding.py): Sentence Transformers · all-MiniLM-L6-v2 produces 384-dimensional vectors. · `rag_project/rag/embedding.py`
- [Chroma vector store](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/vector_store.py): local vector index · Chunks are isolated by document_id metadata. · `rag_project/rag/vector_store.py`
- [Question-answer pipeline](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/rag_pipeline.py): RAG orchestrator · `rag_project/rag/rag_pipeline.py`
- [Scoped retrieval](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/retriever.py): retrieval stage · Returns top three chunks filtered by document ID. · `rag_project/rag/retriever.py`
- [Grounded generation](https://github.com/senthil-netxyper/techjays_rag_senthil/blob/main/rag_project/rag/generator.py): OpenAI client · Builds prompts and invokes gpt-4.1-mini. · `rag_project/rag/generator.py`

### Other components

- **OpenAI API**: external AI service · Uses OPENAI_API_KEY.

## Connections

- Django CLI → Root routing: runs app routing
- WSGI server → Root routing: serves
- ASGI server → Root routing: serves
- Root routing → Document routes: includes
- Document routes → Upload, chat & delete: dispatches
- Upload, chat & delete → Document UI: renders
- Upload, chat & delete → Document & chat records: creates, reads & deletes
- Document & chat records → SQLite: persists via ORM
- Upload, chat & delete → PDF media files: saves uploaded PDFs
- Upload, chat & delete → PDF extraction & chunking: indexes upload
- PDF extraction & chunking → Local embeddings: chunk text
- Local embeddings → Chroma vector store: stores chunk vectors
- Upload, chat & delete → Question-answer pipeline: ask_question(question, document_id)
- Question-answer pipeline → Local embeddings: embeds question
- Question-answer pipeline → Scoped retrieval: retrieves context
- Scoped retrieval → Chroma vector store: top 3; document_id filter
- Question-answer pipeline → Grounded generation: sends grounded context
- Grounded generation → OpenAI API: completion request
- Question-answer pipeline → Upload, chat & delete: answer
- Upload, chat & delete → Document & chat records: persists ChatMessage
- Upload, chat & delete → Chroma vector store: deletes document chunks
