# deepakk200/radiology_rag architecture

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

- Interactive diagram: https://gitdiagram.com/deepakk200/radiology_rag
- Repository: https://github.com/deepakk200/radiology_rag

## Overview

CXRAG accepts a chest X-ray, radiology text, or both, validates the inputs, retrieves similar images and reports, grounds findings against RadLex, and generates a structured impression with faithfulness checks. The CLI and Flask API invoke the pipeline; the API also offers radiology follow-up chat. The README documents parallel visual/text retrieval and the main agent stages. The graph uses those documented relationships where orchestration details were not excerpted; it does not treat index builders or experiment artifacts as runtime product components.

Main entry points: [`orchestrator/pipeline.py`](https://github.com/deepakk200/radiology_rag/blob/master/orchestrator/pipeline.py) (Pipeline), [`agent4_summarize/summarize_agent.py`](https://github.com/deepakk200/radiology_rag/blob/master/agent4_summarize/summarize_agent.py) (Structured Summarizer), [`agent1_visual/visual_agent.py`](https://github.com/deepakk200/radiology_rag/blob/master/agent1_visual/visual_agent.py) (Visual Retrieval), [`agent3_knowledge/knowledge_agent.py`](https://github.com/deepakk200/radiology_rag/blob/master/agent3_knowledge/knowledge_agent.py) (RadLex Grounding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User Interfaces"]
  node_cli["CLI<br/>[main.py]"]
  node_web["Web API<br/>[app.py]"]
  node_chat["Radiology Chat<br/>[app.py]"]
end

subgraph group_flow["Pipeline Control"]
  node_pipeline["Pipeline<br/>[pipeline.py]"]
  node_validation["Input Validation"]
  node_imagecheck["Image Validation<br/>[image_validator.py]"]
  node_formats["Pipeline Data Types<br/>[data_format.py]"]
end

subgraph group_retrieval["Evidence Retrieval"]
  node_visual["Visual Retrieval<br/>[visual_agent.py]"]
  node_text["Text Retrieval<br/>[text_agent.py]"]
end

subgraph group_clinical["Grounding and Output"]
  node_knowledge["RadLex Grounding<br/>[knowledge_agent.py]"]
  node_summarizer["Structured Summarizer<br/>[summarize_agent.py]"]
  node_labels["Finding Labels<br/>[label_detector.py]"]
  node_faithfulness["Faithfulness Check<br/>[faithfulness.py]"]
  node_outputcheck["Output Guard"]
end

node_user(("Requester"))
node_impression["Structured Impression"]
node_groq{{"Groq LLM"}}
node_radlex[("RadLex Index")]

node_user -->|"submits input"| node_cli
node_user -->|"submits input"| node_web
node_user -->|"asks follow-up"| node_chat
node_cli -->|"runs"| node_pipeline
node_web -->|"runs"| node_pipeline
node_pipeline -->|"validates text"| node_validation
node_pipeline -->|"validates image"| node_imagecheck
node_pipeline -->|"dispatches image"| node_visual
node_pipeline -->|"dispatches text"| node_text
node_pipeline -->|"dispatches grounding"| node_knowledge
node_pipeline -->|"sends evidence"| node_summarizer
node_visual -->|"checks scores"| node_imagecheck
node_visual -->|"provides retrieval"| node_summarizer
node_text -->|"provides retrieval"| node_summarizer
node_knowledge -->|"searches concepts"| node_radlex
node_knowledge -->|"provides concepts"| node_summarizer
node_summarizer -->|"detects labels"| node_labels
node_summarizer -->|"checks faithfulness"| node_faithfulness
node_summarizer -->|"generates text"| node_groq
node_pipeline -->|"guards output"| node_outputcheck
node_summarizer -->|"returns JSON"| node_impression
node_chat -->|"answers questions"| node_groq
node_pipeline -.->|"uses result types"| node_formats

click node_cli "https://github.com/deepakk200/radiology_rag/blob/master/main.py"
click node_web "https://github.com/deepakk200/radiology_rag/blob/master/app.py"
click node_chat "https://github.com/deepakk200/radiology_rag/blob/master/app.py"
click node_pipeline "https://github.com/deepakk200/radiology_rag/blob/master/orchestrator/pipeline.py"
click node_validation "https://github.com/deepakk200/radiology_rag/blob/master/shared/medical_validator.py"
click node_imagecheck "https://github.com/deepakk200/radiology_rag/blob/master/shared/image_validator.py"
click node_visual "https://github.com/deepakk200/radiology_rag/blob/master/agent1_visual/visual_agent.py"
click node_text "https://github.com/deepakk200/radiology_rag/blob/master/agent2_text/text_agent.py"
click node_knowledge "https://github.com/deepakk200/radiology_rag/blob/master/agent3_knowledge/knowledge_agent.py"
click node_summarizer "https://github.com/deepakk200/radiology_rag/blob/master/agent4_summarize/summarize_agent.py"
click node_labels "https://github.com/deepakk200/radiology_rag/blob/master/agent4_summarize/label_detector.py"
click node_faithfulness "https://github.com/deepakk200/radiology_rag/blob/master/agent4_summarize/faithfulness.py"
click node_outputcheck "https://github.com/deepakk200/radiology_rag/blob/master/shared/medical_validator.py"
click node_formats "https://github.com/deepakk200/radiology_rag/blob/master/shared/data_format.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_cli,node_web,node_chat toneBlue
class node_pipeline,node_validation,node_imagecheck,node_formats,node_radlex toneAmber
class node_visual,node_text,node_user toneMint
class node_knowledge,node_summarizer,node_labels,node_faithfulness,node_outputcheck toneRose
class node_impression,node_groq toneIndigo
```

## Components

### User Interfaces

- [CLI](https://github.com/deepakk200/radiology_rag/blob/master/main.py): `main.py`
- [Web API](https://github.com/deepakk200/radiology_rag/blob/master/app.py): `app.py`
- [Radiology Chat](https://github.com/deepakk200/radiology_rag/blob/master/app.py): `app.py`

### Pipeline Control

- [Pipeline](https://github.com/deepakk200/radiology_rag/blob/master/orchestrator/pipeline.py): `orchestrator/pipeline.py`
- [Input Validation](https://github.com/deepakk200/radiology_rag/blob/master/shared/medical_validator.py): `shared/medical_validator.py`
- [Image Validation](https://github.com/deepakk200/radiology_rag/blob/master/shared/image_validator.py): `shared/image_validator.py`
- [Pipeline Data Types](https://github.com/deepakk200/radiology_rag/blob/master/shared/data_format.py): `shared/data_format.py`

### Evidence Retrieval

- [Visual Retrieval](https://github.com/deepakk200/radiology_rag/blob/master/agent1_visual/visual_agent.py): `agent1_visual/visual_agent.py`
- [Text Retrieval](https://github.com/deepakk200/radiology_rag/blob/master/agent2_text/text_agent.py): `agent2_text/text_agent.py`

### Grounding and Output

- [RadLex Grounding](https://github.com/deepakk200/radiology_rag/blob/master/agent3_knowledge/knowledge_agent.py): `agent3_knowledge/knowledge_agent.py`
- [Structured Summarizer](https://github.com/deepakk200/radiology_rag/blob/master/agent4_summarize/summarize_agent.py): `agent4_summarize/summarize_agent.py`
- [Finding Labels](https://github.com/deepakk200/radiology_rag/blob/master/agent4_summarize/label_detector.py): `agent4_summarize/label_detector.py`
- [Faithfulness Check](https://github.com/deepakk200/radiology_rag/blob/master/agent4_summarize/faithfulness.py): `agent4_summarize/faithfulness.py`
- [Output Guard](https://github.com/deepakk200/radiology_rag/blob/master/shared/medical_validator.py): `shared/medical_validator.py`

### Other components

- **Requester**
- **Structured Impression**
- **Groq LLM**
- **RadLex Index**

## Connections

- Requester → CLI: submits input (evidence: `README.md`)
- Requester → Web API: submits input (evidence: `README.md`)
- Requester → Radiology Chat: asks follow-up (evidence: `README.md`)
- CLI → Pipeline: runs (evidence: `main.py`)
- Web API → Pipeline: runs (evidence: `app.py`)
- Pipeline → Input Validation: validates text (evidence: `orchestrator/pipeline.py`)
- Pipeline → Image Validation: validates image (evidence: `orchestrator/pipeline.py`)
- Pipeline → Visual Retrieval: dispatches image (evidence: `README.md`)
- Pipeline → Text Retrieval: dispatches text (evidence: `README.md`)
- Pipeline → RadLex Grounding: dispatches grounding (evidence: `README.md`)
- Pipeline → Structured Summarizer: sends evidence (evidence: `README.md`)
- Visual Retrieval → Image Validation: checks scores (evidence: `agent1_visual/visual_agent.py`)
- Visual Retrieval → Structured Summarizer: provides retrieval (evidence: `README.md`)
- Text Retrieval → Structured Summarizer: provides retrieval (evidence: `README.md`)
- RadLex Grounding → RadLex Index: searches concepts (evidence: `agent3_knowledge/knowledge_agent.py`)
- RadLex Grounding → Structured Summarizer: provides concepts (evidence: `README.md`)
- Structured Summarizer → Finding Labels: detects labels (evidence: `agent4_summarize/summarize_agent.py`)
- Structured Summarizer → Faithfulness Check: checks faithfulness (evidence: `agent4_summarize/summarize_agent.py`)
- Structured Summarizer → Groq LLM: generates text (evidence: `README.md`)
- Pipeline → Output Guard: guards output (evidence: `orchestrator/pipeline.py`)
- Structured Summarizer → Structured Impression: returns JSON (evidence: `README.md`)
- Radiology Chat → Groq LLM: answers questions (evidence: `app.py`)
- Pipeline → Pipeline Data Types: uses result types (evidence: `orchestrator/pipeline.py`)
