# chinmaye5/ragent architecture

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

- Interactive diagram: https://gitdiagram.com/chinmaye5/ragent
- Repository: https://github.com/chinmaye5/ragent

## Overview

Theragent is a document-grounded chat application. Users register or log in, upload documents, and ask questions about them in chats; the backend ingests documents and runs a retrieval-and-answer graph. The frontend exposes home, account, dashboard, and chat screens. The graph shows explicit query-graph transitions and documented imports, while unshown route internals and external-service calls are left unconnected or marked unverified. The README is empty, so capability coverage is based on the supplied source index and excerpts.

Main entry points: [`backend/app/agents/nodes/query/retrieve.py`](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/retrieve.py) (Chunk retrieval), [`backend/app/agents/ingestion_graph.py`](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/ingestion_graph.py) (Ingestion graph), [`backend/app/agents/query_graph.py`](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/query_graph.py) (Query graph), [`backend/app/api/routes/documents.py`](https://github.com/chinmaye5/ragent/blob/main/backend/app/api/routes/documents.py) (Document routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web app"]
  node_app["App routing<br/>[App.jsx]"]
  node_home["Home and accounts<br/>[Home.jsx]"]
  node_chatui["Chat experience<br/>[ChatPage.jsx]"]
  node_chatparts["Chat components<br/>[ChatMessages.jsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.jsx]"]
  node_webapi["API client<br/>[api.js]"]
end

subgraph group_api["API and accounts"]
  node_apiapp["FastAPI app<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_chatapi["Chat routes<br/>[chats.py]"]
  node_docapi["Document routes<br/>[documents.py]"]
end

subgraph group_ingest["Document ingestion"]
  node_ingestgraph["Ingestion graph<br/>[ingestion_graph.py]"]
  node_classify["Document classification<br/>[classify.py]"]
  node_chunk["Document chunking<br/>[chunk.py]"]
  node_enrich["Chunk enrichment<br/>[enrich.py]"]
  node_critic["Ingestion review<br/>[critic.py]"]
  node_persist["Chunk persistence<br/>[persist.py]"]
end

subgraph group_query["Question answering"]
  node_querygraph["Query graph<br/>[query_graph.py]"]
  node_router["Query routing<br/>[router.py]"]
  node_retrieve["Chunk retrieval<br/>[retrieve.py]"]
  node_answer["Answer generation<br/>[answer.py]"]
  node_verify["Answer verification<br/>[verify.py]"]
  node_qstate["Query state and LLM<br/>[state.py]"]
end

subgraph group_infra["Shared services"]
  node_db[("Relational and vector DB<br/>[models.py]")]
  node_dbconn["Database connections<br/>[database.py]"]
  node_docservice["Document and model clients"]
  node_gateway["LLM gateway<br/>[gateway.py]"]
  node_guardrails["Query guardrails<br/>[guardrails.py]"]
end

node_visitor(("User"))
node_jina["Jina embeddings API"]
node_groq["Groq model API"]

node_visitor -->|"uses"| node_app
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_chatui
node_app -->|"routes to"| node_dashboard
node_chatui -->|"renders"| node_chatparts
node_chatui -.->|"calls"| node_webapi
node_home -.->|"calls"| node_webapi
node_dashboard -.->|"calls"| node_webapi
node_webapi -.->|"sends requests"| node_apiapp
node_apiapp -->|"registers"| node_auth
node_apiapp -->|"registers"| node_chatapi
node_apiapp -->|"registers"| node_docapi
node_auth -->|"gets sessions"| node_dbconn
node_auth -->|"queries users"| node_db
node_chatapi -->|"invokes"| node_querygraph
node_chatapi -->|"uses"| node_dbconn
node_chatapi -->|"stores chat data"| node_db
node_docapi -->|"invokes"| node_ingestgraph
node_docapi -->|"invokes"| node_querygraph
node_docapi -->|"uses"| node_db
node_docapi -->|"uses"| node_docservice
node_ingestgraph -.->|"dispatches"| node_classify
node_ingestgraph -.->|"dispatches"| node_chunk
node_ingestgraph -.->|"dispatches"| node_enrich
node_ingestgraph -.->|"dispatches"| node_critic
node_ingestgraph -.->|"dispatches"| node_persist
node_classify -->|"uses"| node_docservice
node_querygraph -->|"dispatches"| node_router
node_querygraph -->|"dispatches"| node_retrieve
node_querygraph -->|"dispatches"| node_answer
node_querygraph -->|"dispatches"| node_verify
node_router -->|"routes RAG"| node_retrieve
node_retrieve -->|"passes chunks"| node_answer
node_answer -->|"passes answer"| node_verify
node_verify -->|"retries"| node_retrieve
node_retrieve -->|"queries through"| node_dbconn
node_retrieve -->|"searches chunks"| node_db
node_retrieve -->|"embeds queries"| node_docservice
node_qstate -->|"gets LLM client"| node_docservice
node_qstate -->|"calls LLM gateway"| node_gateway
node_router -->|"uses"| node_guardrails
node_docservice -->|"requests embeddings"| node_jina
node_gateway -.->|"routes model calls"| node_groq

click node_app "https://github.com/chinmaye5/ragent/blob/main/frontend/src/App.jsx"
click node_home "https://github.com/chinmaye5/ragent/blob/main/frontend/src/pages/Home.jsx"
click node_chatui "https://github.com/chinmaye5/ragent/blob/main/frontend/src/pages/ChatPage.jsx"
click node_chatparts "https://github.com/chinmaye5/ragent/blob/main/frontend/src/components/ChatMessages.jsx"
click node_dashboard "https://github.com/chinmaye5/ragent/blob/main/frontend/src/pages/Dashboard.jsx"
click node_webapi "https://github.com/chinmaye5/ragent/blob/main/frontend/src/api.js"
click node_apiapp "https://github.com/chinmaye5/ragent/blob/main/backend/app/main.py"
click node_auth "https://github.com/chinmaye5/ragent/blob/main/backend/app/api/routes/auth.py"
click node_chatapi "https://github.com/chinmaye5/ragent/blob/main/backend/app/api/routes/chats.py"
click node_docapi "https://github.com/chinmaye5/ragent/blob/main/backend/app/api/routes/documents.py"
click node_ingestgraph "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/ingestion_graph.py"
click node_classify "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/ingestion/classify.py"
click node_chunk "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/ingestion/chunk.py"
click node_enrich "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/ingestion/enrich.py"
click node_critic "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/ingestion/critic.py"
click node_persist "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/ingestion/persist.py"
click node_querygraph "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/query_graph.py"
click node_router "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/router.py"
click node_retrieve "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/retrieve.py"
click node_answer "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/answer.py"
click node_verify "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/verify.py"
click node_qstate "https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/state.py"
click node_db "https://github.com/chinmaye5/ragent/blob/main/backend/app/models/models.py"
click node_dbconn "https://github.com/chinmaye5/ragent/blob/main/backend/app/core/database.py"
click node_docservice "https://github.com/chinmaye5/ragent/blob/main/backend/app/services/document_service.py"
click node_gateway "https://github.com/chinmaye5/ragent/blob/main/backend/app/core/gateway.py"
click node_guardrails "https://github.com/chinmaye5/ragent/blob/main/backend/app/core/guardrails.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_app,node_home,node_chatui,node_chatparts,node_dashboard,node_webapi,node_visitor toneBlue
class node_apiapp,node_auth,node_chatapi,node_docapi toneAmber
class node_ingestgraph,node_classify,node_chunk,node_enrich,node_critic,node_persist,node_jina,node_groq toneMint
class node_querygraph,node_router,node_retrieve,node_answer,node_verify,node_qstate toneRose
class node_db,node_dbconn,node_docservice,node_gateway,node_guardrails toneIndigo
```

## Components

### Web app

- [App routing](https://github.com/chinmaye5/ragent/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Home and accounts](https://github.com/chinmaye5/ragent/blob/main/frontend/src/pages/Home.jsx): `frontend/src/pages/Home.jsx`
- [Chat experience](https://github.com/chinmaye5/ragent/blob/main/frontend/src/pages/ChatPage.jsx): `frontend/src/pages/ChatPage.jsx`
- [Chat components](https://github.com/chinmaye5/ragent/blob/main/frontend/src/components/ChatMessages.jsx): `frontend/src/components/ChatMessages.jsx`
- [Dashboard](https://github.com/chinmaye5/ragent/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [API client](https://github.com/chinmaye5/ragent/blob/main/frontend/src/api.js): `frontend/src/api.js`

### API and accounts

- [FastAPI app](https://github.com/chinmaye5/ragent/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication](https://github.com/chinmaye5/ragent/blob/main/backend/app/api/routes/auth.py): `backend/app/api/routes/auth.py`
- [Chat routes](https://github.com/chinmaye5/ragent/blob/main/backend/app/api/routes/chats.py): `backend/app/api/routes/chats.py`
- [Document routes](https://github.com/chinmaye5/ragent/blob/main/backend/app/api/routes/documents.py): `backend/app/api/routes/documents.py`

### Document ingestion

- [Ingestion graph](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/ingestion_graph.py): `backend/app/agents/ingestion_graph.py`
- [Document classification](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/ingestion/classify.py): `backend/app/agents/nodes/ingestion/classify.py`
- [Document chunking](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/ingestion/chunk.py): `backend/app/agents/nodes/ingestion/chunk.py`
- [Chunk enrichment](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/ingestion/enrich.py): `backend/app/agents/nodes/ingestion/enrich.py`
- [Ingestion review](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/ingestion/critic.py): `backend/app/agents/nodes/ingestion/critic.py`
- [Chunk persistence](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/ingestion/persist.py): `backend/app/agents/nodes/ingestion/persist.py`

### Question answering

- [Query graph](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/query_graph.py): `backend/app/agents/query_graph.py`
- [Query routing](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/router.py): `backend/app/agents/nodes/query/router.py`
- [Chunk retrieval](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/retrieve.py): `backend/app/agents/nodes/query/retrieve.py`
- [Answer generation](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/answer.py): `backend/app/agents/nodes/query/answer.py`
- [Answer verification](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/verify.py): `backend/app/agents/nodes/query/verify.py`
- [Query state and LLM](https://github.com/chinmaye5/ragent/blob/main/backend/app/agents/nodes/query/state.py): `backend/app/agents/nodes/query/state.py`

### Shared services

- [Relational and vector DB](https://github.com/chinmaye5/ragent/blob/main/backend/app/models/models.py): `backend/app/models/models.py`
- [Database connections](https://github.com/chinmaye5/ragent/blob/main/backend/app/core/database.py): `backend/app/core/database.py`
- [Document and model clients](https://github.com/chinmaye5/ragent/blob/main/backend/app/services/document_service.py): `backend/app/services/document_service.py`
- [LLM gateway](https://github.com/chinmaye5/ragent/blob/main/backend/app/core/gateway.py): `backend/app/core/gateway.py`
- [Query guardrails](https://github.com/chinmaye5/ragent/blob/main/backend/app/core/guardrails.py): `backend/app/core/guardrails.py`

### Other components

- **User**
- **Jina embeddings API**
- **Groq model API**

## Connections

- User → App routing: uses (evidence: `frontend/src/App.jsx`)
- App routing → Home and accounts: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Chat experience: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Chat experience → Chat components: renders (evidence: `frontend/src/pages/ChatPage.jsx`)
- Chat experience → API client: calls (evidence: `frontend/src/pages/ChatPage.jsx`)
- Home and accounts → API client: calls (evidence: `frontend/src/pages/Home.jsx`)
- Dashboard → API client: calls (evidence: `frontend/src/pages/Dashboard.jsx`)
- API client → FastAPI app: sends requests
- FastAPI app → Authentication: registers (evidence: `backend/app/main.py`)
- FastAPI app → Chat routes: registers (evidence: `backend/app/main.py`)
- FastAPI app → Document routes: registers (evidence: `backend/app/main.py`)
- Authentication → Database connections: gets sessions (evidence: `backend/app/api/routes/auth.py`)
- Authentication → Relational and vector DB: queries users (evidence: `backend/app/api/routes/auth.py`)
- Chat routes → Query graph: invokes (evidence: `backend/app/api/routes/chats.py`)
- Chat routes → Database connections: uses (evidence: `backend/app/api/routes/chats.py`)
- Chat routes → Relational and vector DB: stores chat data (evidence: `backend/app/api/routes/chats.py`)
- Document routes → Ingestion graph: invokes (evidence: `backend/app/api/routes/documents.py`)
- Document routes → Query graph: invokes (evidence: `backend/app/api/routes/documents.py`)
- Document routes → Relational and vector DB: uses (evidence: `backend/app/api/routes/documents.py`)
- Document routes → Document and model clients: uses (evidence: `backend/app/api/routes/documents.py`)
- Ingestion graph → Document classification: dispatches
- Ingestion graph → Document chunking: dispatches
- Ingestion graph → Chunk enrichment: dispatches
- Ingestion graph → Ingestion review: dispatches
- Ingestion graph → Chunk persistence: dispatches
- Document classification → Document and model clients: uses (evidence: `backend/app/agents/nodes/ingestion/classify.py`)
- Query graph → Query routing: dispatches (evidence: `backend/app/agents/query_graph.py`)
- Query graph → Chunk retrieval: dispatches (evidence: `backend/app/agents/query_graph.py`)
- Query graph → Answer generation: dispatches (evidence: `backend/app/agents/query_graph.py`)
- Query graph → Answer verification: dispatches (evidence: `backend/app/agents/query_graph.py`)
- Query routing → Chunk retrieval: routes RAG
- Chunk retrieval → Answer generation: passes chunks
- Answer generation → Answer verification: passes answer
- Answer verification → Chunk retrieval: retries
- Chunk retrieval → Database connections: queries through (evidence: `backend/app/agents/nodes/query/retrieve.py`)
- Chunk retrieval → Relational and vector DB: searches chunks (evidence: `backend/app/agents/nodes/query/retrieve.py`)
- Chunk retrieval → Document and model clients: embeds queries (evidence: `backend/app/agents/nodes/query/retrieve.py`)
- Query state and LLM → Document and model clients: gets LLM client (evidence: `backend/app/agents/nodes/query/state.py`)
- Query state and LLM → LLM gateway: calls LLM gateway (evidence: `backend/app/agents/nodes/query/state.py`)
- Query routing → Query guardrails: uses (evidence: `backend/app/agents/nodes/query/router.py`)
- Document and model clients → Jina embeddings API: requests embeddings (evidence: `backend/app/services/document_service.py`)
- LLM gateway → Groq model API: routes model calls
