# anuragbiradar2305/medical-agent-rag architecture

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

- Interactive diagram: https://gitdiagram.com/anuragbiradar2305/medical-agent-rag
- Repository: https://github.com/anuragbiradar2305/medical-agent-rag

## Overview

Medical Agent RAG is a Laravel web application for uploading medical documents and asking questions answered from their content, with strict and hybrid response modes. The main flow is upload → document extraction and vector indexing → query embedding and retrieval → mode-dependent answer generation → chat response with sources. The sampled controller and RagAgent show the orchestration and retrieval wiring; framework-internal indexing details and the MedicalAgent implementation were not sampled, so those links are kept at the documented integration level.

Main entry points: [`app/Http/Controllers/MedicalAgentController.php`](https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Http/Controllers/MedicalAgentController.php) (Agent controller), [`app/Neuron/RagAgent.php`](https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Neuron/RagAgent.php) (RAG agent), [`routes/web.php`](https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/routes/web.php) (Web routes), [`app/Neuron/MedicalAgent.php`](https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Neuron/MedicalAgent.php) (Medical agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_routes["Web routes<br/>[web.php]"]
  node_controller["Agent controller"]
  node_views["Agent pages"]
  node_chatresponse["Chat answer and sources"]
end

subgraph group_ingest["Document ingestion"]
  node_loader["Document loader"]
end

subgraph group_rag["Retrieval and answers"]
  node_rag["RAG agent<br/>[RagAgent.php]"]
  node_vectorstore[("Vector store<br/>[RagAgent.php]")]
  node_medical["Medical agent<br/>[MedicalAgent.php]"]
end

node_user(("User"))
node_gemini{{"Gemini API"}}

node_user -->|"requests pages"| node_routes
node_routes -->|"dispatches"| node_controller
node_controller -->|"renders pages"| node_views
node_user -->|"uploads or asks"| node_controller
node_controller -->|"extracts documents"| node_loader
node_controller -->|"indexes documents"| node_rag
node_controller -->|"retrieves matches"| node_rag
node_rag -->|"searches vectors"| node_vectorstore
node_rag -->|"embeds text"| node_gemini
node_controller -->|"selects mode and prompts"| node_medical
node_medical -.->|"generates answer"| node_gemini
node_controller -->|"returns answer and sources"| node_chatresponse
node_chatresponse -->|"displays response"| node_user

click node_routes "https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/routes/web.php"
click node_controller "https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Http/Controllers/MedicalAgentController.php"
click node_views "https://github.com/anuragbiradar2305/medical-agent-rag/tree/main/resources/views/agent"
click node_rag "https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Neuron/RagAgent.php"
click node_vectorstore "https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Neuron/RagAgent.php"
click node_medical "https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Neuron/MedicalAgent.php"
click node_chatresponse "https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Http/Controllers/MedicalAgentController.php"

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_routes,node_controller,node_views,node_chatresponse,node_user toneBlue
class node_loader toneAmber
class node_rag,node_vectorstore,node_medical,node_gemini toneMint
```

## Components

### Web experience

- [Web routes](https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/routes/web.php): `routes/web.php`
- [Agent controller](https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Http/Controllers/MedicalAgentController.php): `app/Http/Controllers/MedicalAgentController.php`
- [Agent pages](https://github.com/anuragbiradar2305/medical-agent-rag/tree/main/resources/views/agent): `resources/views/agent`
- [Chat answer and sources](https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Http/Controllers/MedicalAgentController.php): `app/Http/Controllers/MedicalAgentController.php`

### Document ingestion

- **Document loader**

### Retrieval and answers

- [RAG agent](https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Neuron/RagAgent.php): `app/Neuron/RagAgent.php`
- [Vector store](https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Neuron/RagAgent.php): `app/Neuron/RagAgent.php`
- [Medical agent](https://github.com/anuragbiradar2305/medical-agent-rag/blob/main/app/Neuron/MedicalAgent.php): `app/Neuron/MedicalAgent.php`

### Other components

- **User**
- **Gemini API**

## Connections

- User → Web routes: requests pages
- Web routes → Agent controller: dispatches
- Agent controller → Agent pages: renders pages
- User → Agent controller: uploads or asks
- Agent controller → Document loader: extracts documents
- Agent controller → RAG agent: indexes documents
- Agent controller → RAG agent: retrieves matches
- RAG agent → Vector store: searches vectors
- RAG agent → Gemini API: embeds text
- Agent controller → Medical agent: selects mode and prompts
- Medical agent → Gemini API: generates answer
- Agent controller → Chat answer and sources: returns answer and sources
- Chat answer and sources → User: displays response
