# harshvardhansalve/cse_department_rag architecture

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

- Interactive diagram: https://gitdiagram.com/harshvardhansalve/cse_department_rag
- Repository: https://github.com/harshvardhansalve/cse_department_rag

## Overview

This is a document-grounded department assistant with an admin upload interface. Staff upload and manage documents; ingestion parses and chunks files, embeds them, and stores them. Users chat with the assistant, whose API retrieves relevant chunks and uses an LLM to answer; the UI presents answers and source/download links. A separate API generates downloadable DOCX files from prompts and supplied context. The excerpts show these main calls, but not all routing between UI and generation/download endpoints.

Main entry points: [`lib/supabase.ts`](https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/supabase.ts) (Supabase access), [`app/api/chat/route.ts`](https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/api/chat/route.ts) (Chat API), [`app/api/generate-file/route.ts`](https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/api/generate-file/route.ts) (File generation API), [`app/page.tsx`](https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/page.tsx) (Home and tabs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_home["Home and tabs<br/>[page.tsx]"]
  node_chatui["Chat interface<br/>[ChatUI.tsx]"]
  node_messages["Answer and downloads<br/>[Message.tsx]"]
  node_upload["Upload manager<br/>[FileUpload.tsx]"]
end

subgraph group_api["API workflows"]
  node_chatapi["Chat API<br/>[route.ts]"]
  node_ingestapi["Ingest API<br/>[route.ts]"]
  node_generateapi["File generation API<br/>[route.ts]"]
  node_downloadapi["Download API<br/>[route.ts]"]
end

subgraph group_processing["Document intelligence"]
  node_ingest["Parse and index<br/>[ingest.ts]"]
  node_embeddings["Text embeddings<br/>[embeddings.ts]"]
  node_retriever["Hybrid retrieval<br/>[retriever.ts]"]
  node_docgen["DOCX builder<br/>[fileGenerator.ts]"]
end

subgraph group_storage["Persistence and services"]
  node_supabase["Supabase access<br/>[supabase.ts]"]
  node_documents[("Document records")]
  node_filebucket[("File storage")]
end

node_user(("User or staff"))
node_groq{{"Groq LLM"}}
node_huggingface{{"Hugging Face"}}

node_user -->|"uses"| node_home
node_home -->|"loads"| node_chatui
node_home -->|"loads"| node_upload
node_chatui -->|"sends chat"| node_chatapi
node_chatui -->|"renders"| node_messages
node_upload -->|"uploads files"| node_ingestapi
node_upload -->|"lists files"| node_ingestapi
node_ingestapi -->|"ingests or deletes"| node_ingest
node_ingest -->|"embeds chunks"| node_embeddings
node_embeddings -->|"requests vectors"| node_huggingface
node_ingest -->|"stores files and chunks"| node_supabase
node_chatapi -->|"retrieves context"| node_retriever
node_retriever -->|"embeds queries"| node_embeddings
node_retriever -->|"searches chunks"| node_supabase
node_chatapi -->|"generates answers"| node_groq
node_chatapi -->|"looks up download paths"| node_supabase
node_chatapi -.->|"returns answer data"| node_messages
node_generateapi -->|"generates content"| node_groq
node_generateapi -->|"builds DOCX"| node_docgen
node_generateapi -->|"uploads and signs"| node_supabase
node_downloadapi -->|"signs download"| node_supabase
node_supabase -.->|"reads and writes records"| node_documents
node_supabase -.->|"stores files"| node_filebucket
node_user -.->|"requests file"| node_generateapi

click node_home "https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/page.tsx"
click node_chatui "https://github.com/harshvardhansalve/cse_department_rag/blob/main/components/ChatUI.tsx"
click node_messages "https://github.com/harshvardhansalve/cse_department_rag/blob/main/components/Message.tsx"
click node_upload "https://github.com/harshvardhansalve/cse_department_rag/blob/main/components/FileUpload.tsx"
click node_chatapi "https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/api/chat/route.ts"
click node_ingestapi "https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/api/ingest/route.ts"
click node_generateapi "https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/api/generate-file/route.ts"
click node_downloadapi "https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/api/download/route.ts"
click node_ingest "https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/ingest.ts"
click node_embeddings "https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/embeddings.ts"
click node_retriever "https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/retriever.ts"
click node_docgen "https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/fileGenerator.ts"
click node_supabase "https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/supabase.ts"
click node_documents "https://github.com/harshvardhansalve/cse_department_rag/blob/main/supabase_schema.sql"

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_home,node_chatui,node_messages,node_upload,node_user toneBlue
class node_chatapi,node_ingestapi,node_generateapi,node_downloadapi toneAmber
class node_ingest,node_embeddings,node_retriever,node_docgen toneMint
class node_supabase,node_documents,node_filebucket toneRose
class node_groq,node_huggingface toneIndigo
```

## Components

### User interface

- [Home and tabs](https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/page.tsx): `app/page.tsx`
- [Chat interface](https://github.com/harshvardhansalve/cse_department_rag/blob/main/components/ChatUI.tsx): `components/ChatUI.tsx`
- [Answer and downloads](https://github.com/harshvardhansalve/cse_department_rag/blob/main/components/Message.tsx): `components/Message.tsx`
- [Upload manager](https://github.com/harshvardhansalve/cse_department_rag/blob/main/components/FileUpload.tsx): `components/FileUpload.tsx`

### API workflows

- [Chat API](https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Ingest API](https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/api/ingest/route.ts): `app/api/ingest/route.ts`
- [File generation API](https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/api/generate-file/route.ts): `app/api/generate-file/route.ts`
- [Download API](https://github.com/harshvardhansalve/cse_department_rag/blob/main/app/api/download/route.ts): `app/api/download/route.ts`

### Document intelligence

- [Parse and index](https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/ingest.ts): `lib/ingest.ts`
- [Text embeddings](https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/embeddings.ts): `lib/embeddings.ts`
- [Hybrid retrieval](https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/retriever.ts): `lib/retriever.ts`
- [DOCX builder](https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/fileGenerator.ts): `lib/fileGenerator.ts`

### Persistence and services

- [Supabase access](https://github.com/harshvardhansalve/cse_department_rag/blob/main/lib/supabase.ts): `lib/supabase.ts`
- [Document records](https://github.com/harshvardhansalve/cse_department_rag/blob/main/supabase_schema.sql): `supabase_schema.sql`
- **File storage**

### Other components

- **User or staff**
- **Groq LLM**
- **Hugging Face**

## Connections

- User or staff → Home and tabs: uses
- Home and tabs → Chat interface: loads (evidence: `app/page.tsx`)
- Home and tabs → Upload manager: loads (evidence: `app/page.tsx`)
- Chat interface → Chat API: sends chat (evidence: `components/ChatUI.tsx`)
- Chat interface → Answer and downloads: renders (evidence: `components/ChatUI.tsx`)
- Upload manager → Ingest API: uploads files (evidence: `components/FileUpload.tsx`)
- Upload manager → Ingest API: lists files (evidence: `components/FileUpload.tsx`)
- Ingest API → Parse and index: ingests or deletes (evidence: `app/api/ingest/route.ts`)
- Parse and index → Text embeddings: embeds chunks (evidence: `lib/ingest.ts`)
- Text embeddings → Hugging Face: requests vectors (evidence: `lib/embeddings.ts`)
- Parse and index → Supabase access: stores files and chunks (evidence: `lib/ingest.ts`)
- Chat API → Hybrid retrieval: retrieves context (evidence: `app/api/chat/route.ts`)
- Hybrid retrieval → Text embeddings: embeds queries (evidence: `lib/retriever.ts`)
- Hybrid retrieval → Supabase access: searches chunks (evidence: `lib/retriever.ts`)
- Chat API → Groq LLM: generates answers (evidence: `app/api/chat/route.ts`)
- Chat API → Supabase access: looks up download paths (evidence: `app/api/chat/route.ts`)
- Chat API → Answer and downloads: returns answer data
- File generation API → Groq LLM: generates content (evidence: `app/api/generate-file/route.ts`)
- File generation API → DOCX builder: builds DOCX (evidence: `app/api/generate-file/route.ts`)
- File generation API → Supabase access: uploads and signs (evidence: `app/api/generate-file/route.ts`)
- Download API → Supabase access: signs download (evidence: `app/api/download/route.ts`)
- Supabase access → Document records: reads and writes records
- Supabase access → File storage: stores files
- User or staff → File generation API: requests file
