# nithyaviswak/enterprise_rag_chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/nithyaviswak/enterprise_rag_chatbot
- Repository: https://github.com/nithyaviswak/enterprise_rag_chatbot

## Overview

Enterprise RAG chatbot: users upload documents and ask questions through a Next.js interface; the FastAPI backend ingests and indexes documents, retrieves grounded context, generates and verifies answers, then streams answers and sources. Separate branches provide knowledge-graph exploration, evaluation/metrics, and enterprise controls. The README documents several product capabilities whose implementations were not sampled; those are represented at their supported directory or module paths, with uncertain wiring omitted.

Main entry points: [`frontend/src/lib/api.ts`](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/lib/api.ts) (API client), [`backend/app/rag/pipeline.py`](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/pipeline.py) (RAG orchestration), [`backend/app/main.py`](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/main.py) (FastAPI app), [`backend/app/rag/retriever.py`](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/retriever.py) (Hybrid retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Chat interface"]
  node_web["Chat UI<br/>[ChatInterface.tsx]"]
  node_chatmsg["Chat messages<br/>[ChatMessage.tsx]"]
  node_uploadui["File upload<br/>[FileUpload.tsx]"]
  node_explorer["Graph explorer<br/>[GraphExplorer.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API and governance"]
  node_app["FastAPI app<br/>[main.py]"]
  node_chat_route["Chat endpoint<br/>[chat.py]"]
  node_docs_route["Document endpoints<br/>[documents.py]"]
  node_security["Auth and limits<br/>[auth.py]"]
  node_chat_service["Chat orchestration<br/>[chat_service.py]"]
end

subgraph group_rag["RAG pipeline"]
  node_ingestion["Document ingestion<br/>[ingestion.py]"]
  node_pipeline["RAG orchestration<br/>[pipeline.py]"]
  node_retriever["Hybrid retrieval<br/>[retriever.py]"]
  node_vector[("Vector store<br/>[vector_store.py]")]
  node_embedding["Embeddings"]
  node_generator["Grounded generation<br/>[generator.py]"]
  node_guardrails["Retrieval guardrails<br/>[guardrails.py]"]
  node_hallucination["Grounding checks<br/>[hallucination.py]"]
  node_gemini["Gemini service<br/>[gemini_service.py]"]
  node_ragflow["RAGFlow plugin<br/>[ragflow_client.py]"]
end

subgraph group_knowledge["Knowledge graph"]
  node_graph_route["Graph API<br/>[graph.py]"]
  node_graph_service["Graph services<br/>[graph_service.py]"]
end

subgraph group_quality["Quality and observability"]
  node_eval_route["Evaluation API<br/>[evaluation.py]"]
  node_eval_service["Evaluation service"]
  node_tracing["Request tracing<br/>[tracing.py]"]
  node_metrics["Evaluation metrics<br/>[metrics.py]"]
end

node_user(("User"))

node_user -->|"asks"| node_web
node_web -->|"uses"| node_api_client
node_api_client -->|"sends chat"| node_chat_route
node_chat_route -.->|"delegates"| node_chat_service
node_chat_service -.->|"runs RAG"| node_pipeline
node_pipeline -->|"retrieves"| node_retriever
node_retriever -->|"searches"| node_vector
node_retriever -->|"embeds query"| node_embedding
node_retriever -.->|"retrieves optionally"| node_ragflow
node_pipeline -->|"checks context"| node_guardrails
node_pipeline -->|"generates"| node_generator
node_pipeline -->|"verifies answer"| node_hallucination
node_generator -.->|"calls model"| node_gemini
node_user -->|"uploads files"| node_uploadui
node_uploadui -->|"submits file"| node_api_client
node_api_client -->|"uploads"| node_docs_route
node_docs_route -.->|"ingests"| node_ingestion
node_ingestion -.->|"embeds documents"| node_embedding
node_app -->|"registers"| node_chat_route
node_app -->|"registers"| node_docs_route
node_app -->|"registers"| node_graph_route
node_app -->|"configures middleware"| node_security
node_user -->|"explores graph"| node_explorer
node_explorer -->|"requests graph"| node_api_client
node_api_client -->|"queries graph"| node_graph_route
node_graph_route -.->|"uses graph"| node_graph_service
node_api_client -->|"requests metrics"| node_eval_route
node_eval_route -->|"delegates"| node_eval_service
node_pipeline -->|"records stages"| node_tracing
node_eval_service -.->|"computes metrics"| node_metrics
node_web -->|"renders"| node_chatmsg

click node_web "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/components/ChatInterface.tsx"
click node_chatmsg "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/components/ChatMessage.tsx"
click node_uploadui "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/components/FileUpload.tsx"
click node_explorer "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/components/GraphExplorer.tsx"
click node_api_client "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/lib/api.ts"
click node_app "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/main.py"
click node_chat_route "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/routers/chat.py"
click node_docs_route "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/routers/documents.py"
click node_security "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/middleware/auth.py"
click node_chat_service "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/chat_service.py"
click node_ingestion "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/ingestion.py"
click node_pipeline "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/pipeline.py"
click node_retriever "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/retriever.py"
click node_vector "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/vector_store.py"
click node_embedding "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/embedding_service.py"
click node_generator "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/generator.py"
click node_guardrails "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/guardrails.py"
click node_hallucination "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/hallucination.py"
click node_gemini "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/gemini_service.py"
click node_ragflow "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/ragflow_client.py"
click node_graph_route "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/routers/graph.py"
click node_graph_service "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/knowledge_graph/graph_service.py"
click node_eval_route "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/routers/evaluation.py"
click node_eval_service "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/evaluation_service.py"
click node_tracing "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/observability/tracing.py"
click node_metrics "https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/evaluation/metrics.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_web,node_chatmsg,node_uploadui,node_explorer,node_api_client,node_user toneBlue
class node_app,node_chat_route,node_docs_route,node_security,node_chat_service toneAmber
class node_ingestion,node_pipeline,node_retriever,node_vector,node_embedding,node_generator,node_guardrails,node_hallucination,node_gemini,node_ragflow toneMint
class node_graph_route,node_graph_service toneRose
class node_eval_route,node_eval_service,node_tracing,node_metrics toneIndigo
```

## Components

### Chat interface

- [Chat UI](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/components/ChatInterface.tsx): `frontend/src/components/ChatInterface.tsx`
- [Chat messages](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/components/ChatMessage.tsx): `frontend/src/components/ChatMessage.tsx`
- [File upload](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/components/FileUpload.tsx): `frontend/src/components/FileUpload.tsx`
- [Graph explorer](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/components/GraphExplorer.tsx): `frontend/src/components/GraphExplorer.tsx`
- [API client](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`

### API and governance

- [FastAPI app](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/main.py): `backend/app/main.py`
- [Chat endpoint](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/routers/chat.py): `backend/app/routers/chat.py`
- [Document endpoints](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/routers/documents.py): `backend/app/routers/documents.py`
- [Auth and limits](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/middleware/auth.py): `backend/app/middleware/auth.py`
- [Chat orchestration](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/chat_service.py): `backend/app/services/chat_service.py`

### RAG pipeline

- [Document ingestion](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/ingestion.py): `backend/app/rag/ingestion.py`
- [RAG orchestration](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/pipeline.py): `backend/app/rag/pipeline.py`
- [Hybrid retrieval](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/retriever.py): `backend/app/rag/retriever.py`
- [Vector store](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/vector_store.py): `backend/app/services/vector_store.py`
- [Embeddings](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/embedding_service.py): `backend/app/services/embedding_service.py`
- [Grounded generation](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/generator.py): `backend/app/rag/generator.py`
- [Retrieval guardrails](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/guardrails.py): `backend/app/rag/guardrails.py`
- [Grounding checks](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/rag/hallucination.py): `backend/app/rag/hallucination.py`
- [Gemini service](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/gemini_service.py): `backend/app/services/gemini_service.py`
- [RAGFlow plugin](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/ragflow_client.py): `backend/app/services/ragflow_client.py`

### Knowledge graph

- [Graph API](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/routers/graph.py): `backend/app/routers/graph.py`
- [Graph services](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/knowledge_graph/graph_service.py): `backend/app/services/knowledge_graph/graph_service.py`

### Quality and observability

- [Evaluation API](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/routers/evaluation.py): `backend/app/routers/evaluation.py`
- [Evaluation service](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/services/evaluation_service.py): `backend/app/services/evaluation_service.py`
- [Request tracing](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/backend/app/observability/tracing.py): `backend/app/observability/tracing.py`
- [Evaluation metrics](https://github.com/nithyaviswak/enterprise_rag_chatbot/blob/main/evaluation/metrics.py): `evaluation/metrics.py`

### Other components

- **User**

## Connections

- User → Chat UI: asks
- Chat UI → API client: uses (evidence: `frontend/src/components/ChatInterface.tsx`)
- API client → Chat endpoint: sends chat
- Chat endpoint → Chat orchestration: delegates
- Chat orchestration → RAG orchestration: runs RAG
- RAG orchestration → Hybrid retrieval: retrieves (evidence: `backend/app/rag/pipeline.py`)
- Hybrid retrieval → Vector store: searches (evidence: `backend/app/rag/retriever.py`)
- Hybrid retrieval → Embeddings: embeds query (evidence: `backend/app/rag/retriever.py`)
- Hybrid retrieval → RAGFlow plugin: retrieves optionally
- RAG orchestration → Retrieval guardrails: checks context (evidence: `backend/app/rag/pipeline.py`)
- RAG orchestration → Grounded generation: generates (evidence: `backend/app/rag/pipeline.py`)
- RAG orchestration → Grounding checks: verifies answer (evidence: `backend/app/rag/pipeline.py`)
- Grounded generation → Gemini service: calls model
- User → File upload: uploads files
- File upload → API client: submits file
- API client → Document endpoints: uploads
- Document endpoints → Document ingestion: ingests
- Document ingestion → Embeddings: embeds documents
- FastAPI app → Chat endpoint: registers (evidence: `backend/app/main.py`)
- FastAPI app → Document endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI app → Graph API: registers (evidence: `backend/app/main.py`)
- FastAPI app → Auth and limits: configures middleware (evidence: `backend/app/main.py`)
- User → Graph explorer: explores graph
- Graph explorer → API client: requests graph
- API client → Graph API: queries graph
- Graph API → Graph services: uses graph
- API client → Evaluation API: requests metrics
- Evaluation API → Evaluation service: delegates (evidence: `backend/app/routers/evaluation.py`)
- RAG orchestration → Request tracing: records stages (evidence: `backend/app/rag/pipeline.py`)
- Evaluation service → Evaluation metrics: computes metrics
- Chat UI → Chat messages: renders (evidence: `frontend/src/components/ChatInterface.tsx`)
