# ayushi2110/nestjs-react-rag-gemini-pgvector architecture

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

- Interactive diagram: https://gitdiagram.com/ayushi2110/nestjs-react-rag-gemini-pgvector
- Repository: https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector

## Overview

RAG Assistant is an administrator-managed document knowledge base with a public grounded-chat interface. Users ask questions that are embedded, searched against stored chunks, filtered for relevance, and answered with cited sources; administrators authenticate to ingest or manage documents. The README also describes retrieval evaluation, resilient Gemini requests, and the React chat/upload experience. Backend relationships below are supported by excerpts or the source index; frontend files are absent from the supplied tree, so its implementation links rely on README documentation.

Main entry points: [`backend/src/documents/documents.controller.ts`](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/documents/documents.controller.ts) (Document API), [`backend/src/documents/documents.service.ts`](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/documents/documents.service.ts) (Document Operations), [`backend/src/auth/auth.controller.ts`](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/auth/auth.controller.ts) (Authentication API), [`frontend`](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/tree/main/frontend) (Chat and Upload UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User Experience"]
  node_frontend["Chat and Upload UI"]
  node_chat_api["Chat API<br/>[chat.controller.ts]"]
end

subgraph group_knowledge["Knowledge Management"]
  node_document_api["Document API"]
  node_file_extract["File Text Extraction"]
  node_document_service["Document Operations"]
  node_chunking["Text Chunking"]
end

subgraph group_rag["Retrieval and Generation"]
  node_chat_service["RAG and Evaluation<br/>[chat.service.ts]"]
  node_gemini["Gemini Embeddings and Generation<br/>[gemini.service.ts]"]
end

subgraph group_security["Admin Security"]
  node_auth_api["Authentication API<br/>[auth.controller.ts]"]
  node_auth_service["Admin Sessions and Tokens<br/>[auth.service.ts]"]
  node_admin_guard["Admin Authorization<br/>[admin.guard.ts]"]
  node_jwt_guard["JWT Authentication<br/>[jwt-auth.guard.ts]"]
end

subgraph group_platform["Application Platform"]
  node_database_pool["PostgreSQL Connection Pool<br/>[database.module.ts]"]
  node_vector_store[("PostgreSQL pgvector Store<br/>[init.sql]")]
  node_app["NestJS Application<br/>[app.module.ts]"]
end

node_visitor(("Chat User"))
node_admin(("Administrator"))
node_gemini_provider{{"Google Gemini"}}

node_visitor -->|"asks questions"| node_frontend
node_admin -->|"manages documents"| node_frontend
node_frontend -->|"submits chat"| node_chat_api
node_frontend -->|"uploads documents"| node_document_api
node_visitor -->|"asks question"| node_chat_api
node_admin -->|"ingests documents"| node_document_api
node_chat_api -->|"dispatches chat"| node_chat_service
node_document_api -->|"dispatches operations"| node_document_service
node_document_api -->|"extracts upload text"| node_file_extract
node_file_extract -->|"passes extracted text"| node_document_service
node_document_service -->|"cleans and chunks"| node_chunking
node_document_service -->|"embeds chunks"| node_gemini
node_document_service -->|"queries through"| node_database_pool
node_database_pool -->|"connects to"| node_vector_store
node_document_service -->|"writes and searches"| node_vector_store
node_chat_service -->|"embeds and generates"| node_gemini
node_chat_service -->|"retrieves candidates"| node_document_service
node_gemini -->|"requests AI models"| node_gemini_provider
node_auth_api -->|"handles sessions"| node_auth_service
node_auth_service -->|"stores session state"| node_database_pool
node_document_api -->|"requires authentication"| node_jwt_guard
node_document_api -->|"requires admin role"| node_admin_guard
node_auth_api -->|"protects profile route"| node_jwt_guard
node_auth_api -->|"protects profile route"| node_admin_guard
node_app -->|"registers auth module"| node_auth_api
node_app -->|"registers chat module"| node_chat_api
node_app -->|"registers document module"| node_document_api

click node_frontend "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/tree/main/frontend"
click node_chat_api "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/chat/chat.controller.ts"
click node_document_api "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/documents/documents.controller.ts"
click node_file_extract "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/documents/documents.controller.ts"
click node_document_service "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/documents/documents.service.ts"
click node_chunking "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/documents/chunking.service.ts"
click node_chat_service "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/chat/chat.service.ts"
click node_gemini "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/gemini/gemini.service.ts"
click node_database_pool "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/common/database.module.ts"
click node_vector_store "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/database/init.sql"
click node_auth_api "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/auth/auth.controller.ts"
click node_auth_service "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/auth/auth.service.ts"
click node_admin_guard "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/auth/guards/admin.guard.ts"
click node_jwt_guard "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/auth/guards/jwt-auth.guard.ts"
click node_app "https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/app.module.ts"

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_frontend,node_chat_api,node_visitor toneBlue
class node_document_api,node_file_extract,node_document_service,node_chunking toneAmber
class node_chat_service,node_gemini toneMint
class node_auth_api,node_auth_service,node_admin_guard,node_jwt_guard toneRose
class node_database_pool,node_vector_store,node_app,node_admin,node_gemini_provider toneIndigo
```

## Components

### User Experience

- [Chat and Upload UI](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/tree/main/frontend): `frontend`
- [Chat API](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/chat/chat.controller.ts): `backend/src/chat/chat.controller.ts`

### Knowledge Management

- [Document API](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/documents/documents.controller.ts): `backend/src/documents/documents.controller.ts`
- [File Text Extraction](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/documents/documents.controller.ts): `backend/src/documents/documents.controller.ts`
- [Document Operations](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/documents/documents.service.ts): `backend/src/documents/documents.service.ts`
- [Text Chunking](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/documents/chunking.service.ts): `backend/src/documents/chunking.service.ts`

### Retrieval and Generation

- [RAG and Evaluation](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/chat/chat.service.ts): `backend/src/chat/chat.service.ts`
- [Gemini Embeddings and Generation](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/gemini/gemini.service.ts): `backend/src/gemini/gemini.service.ts`

### Admin Security

- [Authentication API](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/auth/auth.controller.ts): `backend/src/auth/auth.controller.ts`
- [Admin Sessions and Tokens](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/auth/auth.service.ts): `backend/src/auth/auth.service.ts`
- [Admin Authorization](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/auth/guards/admin.guard.ts): `backend/src/auth/guards/admin.guard.ts`
- [JWT Authentication](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/auth/guards/jwt-auth.guard.ts): `backend/src/auth/guards/jwt-auth.guard.ts`

### Application Platform

- [PostgreSQL Connection Pool](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/common/database.module.ts): `backend/src/common/database.module.ts`
- [PostgreSQL pgvector Store](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/database/init.sql): `database/init.sql`
- [NestJS Application](https://github.com/ayushi2110/nestjs-react-rag-gemini-pgvector/blob/main/backend/src/app.module.ts): `backend/src/app.module.ts`

### Other components

- **Chat User**
- **Administrator**
- **Google Gemini**

## Connections

- Chat User → Chat and Upload UI: asks questions (evidence: `README.md`)
- Administrator → Chat and Upload UI: manages documents (evidence: `README.md`)
- Chat and Upload UI → Chat API: submits chat (evidence: `README.md`)
- Chat and Upload UI → Document API: uploads documents (evidence: `README.md`)
- Chat User → Chat API: asks question (evidence: `README.md`)
- Administrator → Document API: ingests documents (evidence: `README.md`)
- Chat API → RAG and Evaluation: dispatches chat (evidence: `backend/src/chat/chat.controller.ts`)
- Document API → Document Operations: dispatches operations (evidence: `backend/src/documents/documents.controller.ts`)
- Document API → File Text Extraction: extracts upload text (evidence: `backend/src/documents/documents.controller.ts`)
- File Text Extraction → Document Operations: passes extracted text (evidence: `backend/src/documents/documents.controller.ts`)
- Document Operations → Text Chunking: cleans and chunks (evidence: `backend/src/documents/documents.service.ts`)
- Document Operations → Gemini Embeddings and Generation: embeds chunks (evidence: `backend/src/documents/documents.service.ts`)
- Document Operations → PostgreSQL Connection Pool: queries through (evidence: `backend/src/documents/documents.service.ts`)
- PostgreSQL Connection Pool → PostgreSQL pgvector Store: connects to (evidence: `backend/src/common/database.module.ts`)
- Document Operations → PostgreSQL pgvector Store: writes and searches (evidence: `backend/src/documents/documents.service.ts`)
- RAG and Evaluation → Gemini Embeddings and Generation: embeds and generates (evidence: `backend/src/chat/chat.service.ts`)
- RAG and Evaluation → Document Operations: retrieves candidates (evidence: `backend/src/chat/chat.service.ts`)
- Gemini Embeddings and Generation → Google Gemini: requests AI models (evidence: `backend/src/gemini/gemini.service.ts`)
- Authentication API → Admin Sessions and Tokens: handles sessions (evidence: `backend/src/auth/auth.controller.ts`)
- Admin Sessions and Tokens → PostgreSQL Connection Pool: stores session state (evidence: `backend/src/auth/auth.service.ts`)
- Document API → JWT Authentication: requires authentication (evidence: `backend/src/documents/documents.controller.ts`)
- Document API → Admin Authorization: requires admin role (evidence: `backend/src/documents/documents.controller.ts`)
- Authentication API → JWT Authentication: protects profile route (evidence: `backend/src/auth/auth.controller.ts`)
- Authentication API → Admin Authorization: protects profile route (evidence: `backend/src/auth/auth.controller.ts`)
- NestJS Application → Authentication API: registers auth module (evidence: `backend/src/app.module.ts`)
- NestJS Application → Chat API: registers chat module (evidence: `backend/src/app.module.ts`)
- NestJS Application → Document API: registers document module (evidence: `backend/src/app.module.ts`)
