# balanandakumar05-cyber/ayurnex architecture

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

- Interactive diagram: https://gitdiagram.com/balanandakumar05-cyber/ayurnex
- Repository: https://github.com/balanandakumar05-cyber/ayurnex

## Overview

AYURNEX is an Ayurveda knowledge assistant: a user selects country and language, asks a question in the React app, and receives a generated answer with source metadata. The API routes requests into a retrieval-augmented answering service; retrieval embeds the question and searches PostgreSQL/pgvector before generation. A separate ingestion workflow turns PDF documents into searchable chunks. The graph preserves the documented frontend, API, RAG, storage, and ingestion capabilities. Some ingestion helpers and backend wiring are not excerpted, so those relationships are limited to source-index references or documented behavior.

Main entry points: [`backend/rag/ingest.py`](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/ingest.py) (PDF ingestion), [`backend/rag/rag_pipeline.py`](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/rag_pipeline.py) (Answer pipeline), [`backend/rag/retriever.py`](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/retriever.py) (Chunk retriever), [`backend/routes/chat.py`](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/routes/chat.py) (Chat endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User interface"]
  node_app["Chat interface<br/>[App.jsx]"]
  node_webapi["API client<br/>[api.js]"]
end

subgraph group_api["API services"]
  node_chat_route["Chat endpoint<br/>[chat.py]"]
  node_chat_schema["Chat schemas<br/>[chat.py]"]
  node_rag_service["Answer service<br/>[rag_service.py]"]
  node_entry["API application<br/>[main.py]"]
end

subgraph group_rag["Knowledge processing"]
  node_pipeline["Answer pipeline<br/>[rag_pipeline.py]"]
  node_prompt["Prompt builder<br/>[prompts.py]"]
  node_retriever["Chunk retriever<br/>[retriever.py]"]
  node_embedder["Text embeddings<br/>[embeddings.py]"]
  node_ingest["PDF ingestion<br/>[ingest.py]"]
  node_pdf_loader["PDF extraction<br/>[pdf_loader.py]"]
  node_cleaner["Text cleaning<br/>[text_cleaner.py]"]
  node_chunker["Chunk creation<br/>[chunker.py]"]
  node_settings["RAG settings<br/>[config.py]"]
end

subgraph group_store["Knowledge storage"]
  node_rag_db["Vector database access<br/>[database.py]"]
  node_database[("PostgreSQL pgvector")]
  node_documents["PDF knowledge base"]
end

node_user(("Question asker"))
node_gemini{{"Gemini generation"}}

node_user -->|"asks question"| node_app
node_app -->|"submits question"| node_webapi
node_webapi -->|"POST /chat"| node_entry
node_entry -->|"registers route"| node_chat_route
node_chat_route -->|"validates request"| node_chat_schema
node_chat_route -->|"calls service"| node_rag_service
node_rag_service -->|"requests answer"| node_pipeline
node_pipeline -->|"retrieves chunks"| node_retriever
node_pipeline -->|"builds prompt"| node_prompt
node_pipeline -.->|"generates answer"| node_gemini
node_retriever -->|"embeds query"| node_embedder
node_retriever -->|"matches chunks"| node_rag_db
node_rag_db -->|"queries and stores"| node_database
node_ingest -->|"scans PDFs"| node_documents
node_ingest -->|"extracts pages"| node_pdf_loader
node_ingest -->|"cleans text"| node_cleaner
node_ingest -->|"creates chunks"| node_chunker
node_ingest -->|"embeds chunks"| node_embedder
node_ingest -->|"writes chunks"| node_rag_db
node_ingest -->|"uses settings"| node_settings
node_retriever -->|"uses settings"| node_settings
node_rag_service -->|"builds response"| node_chat_schema

click node_app "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/src/App.jsx"
click node_webapi "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/src/services/api.js"
click node_chat_route "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/routes/chat.py"
click node_chat_schema "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/schemas/chat.py"
click node_rag_service "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/services/rag_service.py"
click node_entry "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/main.py"
click node_pipeline "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/rag_pipeline.py"
click node_prompt "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/prompts.py"
click node_retriever "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/retriever.py"
click node_embedder "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/embeddings.py"
click node_ingest "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/ingest.py"
click node_pdf_loader "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/pdf_loader.py"
click node_cleaner "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/text_cleaner.py"
click node_chunker "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/chunker.py"
click node_settings "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/config.py"
click node_rag_db "https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/database.py"
click node_documents "https://github.com/balanandakumar05-cyber/ayurnex/tree/main/data/documents"

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_app,node_webapi toneBlue
class node_chat_route,node_chat_schema,node_rag_service,node_entry toneAmber
class node_pipeline,node_prompt,node_retriever,node_embedder,node_ingest,node_pdf_loader,node_cleaner,node_chunker,node_settings toneMint
class node_rag_db,node_database,node_documents toneRose
class node_user,node_gemini toneIndigo
```

## Components

### User interface

- [Chat interface](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/src/App.jsx): `src/App.jsx`
- [API client](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/src/services/api.js): `src/services/api.js`

### API services

- [Chat endpoint](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/routes/chat.py): `backend/routes/chat.py`
- [Chat schemas](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/schemas/chat.py): `backend/schemas/chat.py`
- [Answer service](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/services/rag_service.py): `backend/services/rag_service.py`
- [API application](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/main.py): `backend/main.py`

### Knowledge processing

- [Answer pipeline](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/rag_pipeline.py): `backend/rag/rag_pipeline.py`
- [Prompt builder](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/prompts.py): `backend/rag/prompts.py`
- [Chunk retriever](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/retriever.py): `backend/rag/retriever.py`
- [Text embeddings](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/embeddings.py): `backend/rag/embeddings.py`
- [PDF ingestion](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/ingest.py): `backend/rag/ingest.py`
- [PDF extraction](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/pdf_loader.py): `backend/rag/pdf_loader.py`
- [Text cleaning](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/text_cleaner.py): `backend/rag/text_cleaner.py`
- [Chunk creation](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/chunker.py): `backend/rag/chunker.py`
- [RAG settings](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/config.py): `backend/rag/config.py`

### Knowledge storage

- [Vector database access](https://github.com/balanandakumar05-cyber/ayurnex/blob/main/backend/rag/database.py): `backend/rag/database.py`
- **PostgreSQL pgvector**
- [PDF knowledge base](https://github.com/balanandakumar05-cyber/ayurnex/tree/main/data/documents): `data/documents`

### Other components

- **Question asker**
- **Gemini generation**

## Connections

- Question asker → Chat interface: asks question (evidence: `src/App.jsx`)
- Chat interface → API client: submits question (evidence: `src/App.jsx`)
- API client → API application: POST /chat (evidence: `src/services/api.js`)
- API application → Chat endpoint: registers route (evidence: `backend/main.py`)
- Chat endpoint → Chat schemas: validates request (evidence: `backend/routes/chat.py`)
- Chat endpoint → Answer service: calls service (evidence: `backend/routes/chat.py`)
- Answer service → Answer pipeline: requests answer (evidence: `backend/services/rag_service.py`)
- Answer pipeline → Chunk retriever: retrieves chunks (evidence: `backend/rag/rag_pipeline.py`)
- Answer pipeline → Prompt builder: builds prompt (evidence: `backend/rag/rag_pipeline.py`)
- Answer pipeline → Gemini generation: generates answer
- Chunk retriever → Text embeddings: embeds query (evidence: `backend/rag/retriever.py`)
- Chunk retriever → Vector database access: matches chunks (evidence: `backend/rag/retriever.py`)
- Vector database access → PostgreSQL pgvector: queries and stores (evidence: `backend/rag/database.py`)
- PDF ingestion → PDF knowledge base: scans PDFs (evidence: `backend/rag/ingest.py`)
- PDF ingestion → PDF extraction: extracts pages (evidence: `backend/rag/ingest.py`)
- PDF ingestion → Text cleaning: cleans text (evidence: `backend/rag/ingest.py`)
- PDF ingestion → Chunk creation: creates chunks (evidence: `backend/rag/ingest.py`)
- PDF ingestion → Text embeddings: embeds chunks (evidence: `backend/rag/ingest.py`)
- PDF ingestion → Vector database access: writes chunks (evidence: `backend/rag/ingest.py`)
- PDF ingestion → RAG settings: uses settings (evidence: `backend/rag/ingest.py`)
- Chunk retriever → RAG settings: uses settings (evidence: `backend/rag/retriever.py`)
- Answer service → Chat schemas: builds response (evidence: `backend/services/rag_service.py`)
