# aravind13115/medrag-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/aravind13115/medrag-chatbot
- Repository: https://github.com/aravind13115/medrag-chatbot

## Overview

Medical RAG chatbot for educational, evidence-based answers, including surgical consultation and medication information. The principal flow is a user question through the chat API and retrieval/generation to a cited response; the documented interface also exposes emergency handling and specialty selection. The repository contains overlapping Python and Node services and a separate MedRAG pipeline/UI. The graph shows documented capabilities and source-index relationships; several connections to unsampled route and frontend code are omitted rather than assumed.

Main entry points: [`api/rag_pipeline.py`](https://github.com/aravind13115/medrag-chatbot/blob/main/api/rag_pipeline.py) (RAG pipeline), [`src/App.jsx`](https://github.com/aravind13115/medrag-chatbot/blob/main/src/App.jsx) (Web application), [`api/chat.py`](https://github.com/aravind13115/medrag-chatbot/blob/main/api/chat.py) (Chat endpoint), [`api/index.py`](https://github.com/aravind13115/medrag-chatbot/blob/main/api/index.py) (API entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_web["Web application<br/>[App.jsx]"]
  node_chatui["Chat interface<br/>[Chat.jsx]"]
  node_evidence["Evidence view<br/>[EvidencePage.jsx]"]
  node_formulary["Formulary view<br/>[Formulary.jsx]"]
end

subgraph group_api["Medical API"]
  node_api_entry["API entry<br/>[index.py]"]
  node_chat["Chat endpoint<br/>[chat.py]"]
end

subgraph group_rag["RAG and evidence"]
  node_pipeline["RAG pipeline<br/>[rag_pipeline.py]"]
  node_knowledge[("Clinical knowledge<br/>[knowledge.py]")]
  node_vectors[("Vector search<br/>[vector_store.py]")]
  node_site_search["Site search<br/>[site_search.py]"]
  node_reranker["Result reranking<br/>[reranker.py]"]
  node_generator["Answer generation<br/>[generator.py]"]
end

subgraph group_domain["Clinical capabilities"]
  node_intent["Intent classification"]
  node_entities["Medical entities"]
  node_safety["Safety checks<br/>[safety_layer.py]"]
  node_surgery["Surgical procedures<br/>[neurosurgery.py]"]
  node_medications["Medication information<br/>[fda.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_web
node_web -->|"routes to"| node_chatui
node_chatui -.->|"submits question"| node_chat
node_user -->|"posts question"| node_chat
node_api_entry -->|"imports"| node_chat
node_chat -.->|"uses"| node_pipeline
node_pipeline -->|"classifies"| node_intent
node_pipeline -->|"extracts"| node_entities
node_pipeline -->|"checks safety"| node_safety
node_pipeline -->|"retrieves from"| node_knowledge
node_knowledge -->|"searches"| node_vectors
node_pipeline -->|"adds context"| node_site_search
node_pipeline -->|"reranks"| node_reranker
node_pipeline -.->|"generates answer"| node_generator
node_web -->|"routes to"| node_evidence
node_web -->|"routes to"| node_formulary
node_api_entry -->|"imports"| node_surgery
node_api_entry -->|"imports"| node_medications

click node_web "https://github.com/aravind13115/medrag-chatbot/blob/main/src/App.jsx"
click node_chatui "https://github.com/aravind13115/medrag-chatbot/blob/main/src/pages/Chat.jsx"
click node_api_entry "https://github.com/aravind13115/medrag-chatbot/blob/main/api/index.py"
click node_chat "https://github.com/aravind13115/medrag-chatbot/blob/main/api/chat.py"
click node_pipeline "https://github.com/aravind13115/medrag-chatbot/blob/main/api/rag_pipeline.py"
click node_intent "https://github.com/aravind13115/medrag-chatbot/blob/main/api/medical_intent_classifier.py"
click node_entities "https://github.com/aravind13115/medrag-chatbot/blob/main/api/medical_entity_extractor.py"
click node_safety "https://github.com/aravind13115/medrag-chatbot/blob/main/api/safety_layer.py"
click node_knowledge "https://github.com/aravind13115/medrag-chatbot/blob/main/api/knowledge.py"
click node_vectors "https://github.com/aravind13115/medrag-chatbot/blob/main/api/vector_store.py"
click node_site_search "https://github.com/aravind13115/medrag-chatbot/blob/main/api/site_search.py"
click node_reranker "https://github.com/aravind13115/medrag-chatbot/blob/main/api/reranker.py"
click node_generator "https://github.com/aravind13115/medrag-chatbot/blob/main/medrag/generation/generator.py"
click node_surgery "https://github.com/aravind13115/medrag-chatbot/blob/main/api/neurosurgery.py"
click node_medications "https://github.com/aravind13115/medrag-chatbot/blob/main/api/fda.py"
click node_evidence "https://github.com/aravind13115/medrag-chatbot/blob/main/src/pages/EvidencePage.jsx"
click node_formulary "https://github.com/aravind13115/medrag-chatbot/blob/main/src/pages/Formulary.jsx"

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_chatui,node_evidence,node_formulary,node_user toneBlue
class node_api_entry,node_chat toneAmber
class node_pipeline,node_knowledge,node_vectors,node_site_search,node_reranker,node_generator toneMint
class node_intent,node_entities,node_safety,node_surgery,node_medications toneRose
```

## Components

### User experience

- [Web application](https://github.com/aravind13115/medrag-chatbot/blob/main/src/App.jsx): `src/App.jsx`
- [Chat interface](https://github.com/aravind13115/medrag-chatbot/blob/main/src/pages/Chat.jsx): `src/pages/Chat.jsx`
- [Evidence view](https://github.com/aravind13115/medrag-chatbot/blob/main/src/pages/EvidencePage.jsx): `src/pages/EvidencePage.jsx`
- [Formulary view](https://github.com/aravind13115/medrag-chatbot/blob/main/src/pages/Formulary.jsx): `src/pages/Formulary.jsx`

### Medical API

- [API entry](https://github.com/aravind13115/medrag-chatbot/blob/main/api/index.py): `api/index.py`
- [Chat endpoint](https://github.com/aravind13115/medrag-chatbot/blob/main/api/chat.py): `api/chat.py`

### RAG and evidence

- [RAG pipeline](https://github.com/aravind13115/medrag-chatbot/blob/main/api/rag_pipeline.py): `api/rag_pipeline.py`
- [Clinical knowledge](https://github.com/aravind13115/medrag-chatbot/blob/main/api/knowledge.py): `api/knowledge.py`
- [Vector search](https://github.com/aravind13115/medrag-chatbot/blob/main/api/vector_store.py): `api/vector_store.py`
- [Site search](https://github.com/aravind13115/medrag-chatbot/blob/main/api/site_search.py): `api/site_search.py`
- [Result reranking](https://github.com/aravind13115/medrag-chatbot/blob/main/api/reranker.py): `api/reranker.py`
- [Answer generation](https://github.com/aravind13115/medrag-chatbot/blob/main/medrag/generation/generator.py): `medrag/generation/generator.py`

### Clinical capabilities

- [Intent classification](https://github.com/aravind13115/medrag-chatbot/blob/main/api/medical_intent_classifier.py): `api/medical_intent_classifier.py`
- [Medical entities](https://github.com/aravind13115/medrag-chatbot/blob/main/api/medical_entity_extractor.py): `api/medical_entity_extractor.py`
- [Safety checks](https://github.com/aravind13115/medrag-chatbot/blob/main/api/safety_layer.py): `api/safety_layer.py`
- [Surgical procedures](https://github.com/aravind13115/medrag-chatbot/blob/main/api/neurosurgery.py): `api/neurosurgery.py`
- [Medication information](https://github.com/aravind13115/medrag-chatbot/blob/main/api/fda.py): `api/fda.py`

### Other components

- **User**

## Connections

- User → Web application: uses
- Web application → Chat interface: routes to (evidence: `src/App.jsx`)
- Chat interface → Chat endpoint: submits question
- User → Chat endpoint: posts question
- API entry → Chat endpoint: imports (evidence: `api/index.py`)
- Chat endpoint → RAG pipeline: uses (evidence: `api/rag_pipeline.py`)
- RAG pipeline → Intent classification: classifies (evidence: `api/rag_pipeline.py`)
- RAG pipeline → Medical entities: extracts (evidence: `api/rag_pipeline.py`)
- RAG pipeline → Safety checks: checks safety (evidence: `api/rag_pipeline.py`)
- RAG pipeline → Clinical knowledge: retrieves from (evidence: `api/rag_pipeline.py`)
- Clinical knowledge → Vector search: searches (evidence: `api/knowledge.py`)
- RAG pipeline → Site search: adds context (evidence: `api/rag_pipeline.py`)
- RAG pipeline → Result reranking: reranks (evidence: `api/rag_pipeline.py`)
- RAG pipeline → Answer generation: generates answer
- Web application → Evidence view: routes to (evidence: `src/App.jsx`)
- Web application → Formulary view: routes to (evidence: `src/App.jsx`)
- API entry → Surgical procedures: imports (evidence: `api/index.py`)
- API entry → Medication information: imports (evidence: `api/index.py`)
