# kayessp-26/clearmed-ai architecture

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

- Interactive diagram: https://gitdiagram.com/kayessp-26/clearmed-ai
- Repository: https://github.com/kayessp-26/clearmed-ai

## Overview

ClearMed AI turns pasted clinical text or uploaded medical reports into plain-language explanations, using OCR for scanned or image reports and RAG context during simplification. The main user flow runs from the React workspace through the API to the backend simplifier, then returns an explanation with readability metrics. The product also includes corpus ingestion, request logging, and an evaluation dashboard/benchmark workflow. The graph uses README claims where backend routing or unsampled capabilities were not shown; those implementation details are not inferred beyond the documented relationships.

Main entry points: [`frontend/react/src/features/simplify/SimplifyWorkspace.jsx`](https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/features/simplify/SimplifyWorkspace.jsx) (Simplify workspace), [`backend/app/main.py`](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/main.py) (FastAPI endpoints), [`backend/app/pipeline/simplifier.py`](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/pipeline/simplifier.py) (Text simplifier), [`backend/app/rag/ingest.py`](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/rag/ingest.py) (Corpus ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User experience"]
  node_app["App composition<br/>[App.jsx]"]
  node_workspace["Simplify workspace"]
  node_api_client["API client<br/>[api.js]"]
  node_results["Explanation results"]
  node_dashboard["Evaluation dashboard"]
  node_landing["Landing guidance<br/>[HowItWorks.jsx]"]
  node_shell["App shell<br/>[AppShell.jsx]"]
end

subgraph group_backend["Simplification service"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_ocr["Report OCR<br/>[ocr.py]"]
  node_simplifier["Text simplifier<br/>[simplifier.py]"]
  node_prompt["Simplification prompt<br/>[simplify_v2.txt]"]
  node_gemini_client["Gemini client<br/>[gemini.py]"]
  node_config["Service settings<br/>[config.py]"]
end

subgraph group_rag["Medical context"]
  node_retriever["Context retriever<br/>[retriever.py]"]
  node_embedder["Text embedder<br/>[embedder.py]"]
  node_vector_store[("Pinecone index")]
  node_ingestion["Corpus ingestion<br/>[ingest.py]"]
  node_ingest_runner["Ingestion runner<br/>[ingest_corpus.py]"]
end

subgraph group_ops["Supporting capabilities"]
  node_logger["Request logger<br/>[logger.py]"]
  node_benchmark["Evaluation benchmark<br/>[evaluate.py]"]
end

node_user(("Report user"))
node_gemini["Google Gemini"]
node_supabase[("Supabase logging")]
node_tesseract["Tesseract OCR"]
node_pubmed["PubMedQA corpus"]

node_user -->|"enters text or file"| node_workspace
node_app -->|"renders"| node_shell
node_app -->|"renders"| node_landing
node_app -->|"renders"| node_workspace
node_workspace -->|"submits input"| node_api_client
node_api_client -->|"sends simplify request"| node_api
node_workspace -->|"renders response"| node_results
node_workspace -->|"renders"| node_dashboard
node_api -->|"processes uploaded reports"| node_ocr
node_ocr -->|"extracts text"| node_tesseract
node_api -->|"simplifies clinical text"| node_simplifier
node_simplifier -->|"retrieves context"| node_retriever
node_simplifier -->|"fills template"| node_prompt
node_simplifier -->|"requests generation"| node_gemini_client
node_gemini_client -.->|"calls model"| node_gemini
node_retriever -.->|"embeds query"| node_embedder
node_embedder -->|"requests embeddings"| node_gemini_client
node_retriever -->|"queries vectors"| node_vector_store
node_ingest_runner -->|"starts ingestion"| node_ingestion
node_ingestion -->|"loads abstracts"| node_pubmed
node_ingestion -->|"embeds chunks"| node_embedder
node_ingestion -->|"upserts vectors"| node_vector_store
node_api -.->|"logs requests"| node_logger
node_logger -.->|"writes logs"| node_supabase
node_logger -->|"reads credentials"| node_config
node_benchmark -->|"evaluates responses"| node_api

click node_app "https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/App.jsx"
click node_workspace "https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/features/simplify/SimplifyWorkspace.jsx"
click node_api_client "https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/services/api.js"
click node_results "https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/features/simplify/SimplifyWorkspace.jsx"
click node_dashboard "https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/features/evaluation/EvaluationDashboard.jsx"
click node_landing "https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/features/landing/HowItWorks.jsx"
click node_shell "https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/components/layout/AppShell.jsx"
click node_api "https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/main.py"
click node_ocr "https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/pipeline/ocr.py"
click node_simplifier "https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/pipeline/simplifier.py"
click node_prompt "https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/prompts/simplify_v2.txt"
click node_gemini_client "https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/gemini.py"
click node_logger "https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/db/logger.py"
click node_config "https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/config.py"
click node_retriever "https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/rag/retriever.py"
click node_embedder "https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/rag/embedder.py"
click node_ingestion "https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/rag/ingest.py"
click node_ingest_runner "https://github.com/kayessp-26/clearmed-ai/blob/main/scripts/ingest_corpus.py"
click node_benchmark "https://github.com/kayessp-26/clearmed-ai/blob/main/eval/evaluate.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_workspace,node_api_client,node_results,node_dashboard,node_landing,node_shell,node_user toneBlue
class node_api,node_ocr,node_simplifier,node_prompt,node_gemini_client,node_config,node_supabase toneAmber
class node_retriever,node_embedder,node_vector_store,node_ingestion,node_ingest_runner toneMint
class node_logger,node_benchmark toneRose
class node_gemini,node_tesseract,node_pubmed toneIndigo
```

## Components

### User experience

- [App composition](https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/App.jsx): `frontend/react/src/App.jsx`
- [Simplify workspace](https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/features/simplify/SimplifyWorkspace.jsx): `frontend/react/src/features/simplify/SimplifyWorkspace.jsx`
- [API client](https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/services/api.js): `frontend/react/src/services/api.js`
- [Explanation results](https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/features/simplify/SimplifyWorkspace.jsx): `frontend/react/src/features/simplify/SimplifyWorkspace.jsx`
- [Evaluation dashboard](https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/features/evaluation/EvaluationDashboard.jsx): `frontend/react/src/features/evaluation/EvaluationDashboard.jsx`
- [Landing guidance](https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/features/landing/HowItWorks.jsx): `frontend/react/src/features/landing/HowItWorks.jsx`
- [App shell](https://github.com/kayessp-26/clearmed-ai/blob/main/frontend/react/src/components/layout/AppShell.jsx): `frontend/react/src/components/layout/AppShell.jsx`

### Simplification service

- [FastAPI endpoints](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [Report OCR](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/pipeline/ocr.py): `backend/app/pipeline/ocr.py`
- [Text simplifier](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/pipeline/simplifier.py): `backend/app/pipeline/simplifier.py`
- [Simplification prompt](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/prompts/simplify_v2.txt): `backend/app/prompts/simplify_v2.txt`
- [Gemini client](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/gemini.py): `backend/app/gemini.py`
- [Service settings](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/config.py): `backend/app/config.py`

### Medical context

- [Context retriever](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/rag/retriever.py): `backend/app/rag/retriever.py`
- [Text embedder](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/rag/embedder.py): `backend/app/rag/embedder.py`
- **Pinecone index**
- [Corpus ingestion](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/rag/ingest.py): `backend/app/rag/ingest.py`
- [Ingestion runner](https://github.com/kayessp-26/clearmed-ai/blob/main/scripts/ingest_corpus.py): `scripts/ingest_corpus.py`

### Supporting capabilities

- [Request logger](https://github.com/kayessp-26/clearmed-ai/blob/main/backend/app/db/logger.py): `backend/app/db/logger.py`
- [Evaluation benchmark](https://github.com/kayessp-26/clearmed-ai/blob/main/eval/evaluate.py): `eval/evaluate.py`

### Other components

- **Report user**
- **Google Gemini**
- **Supabase logging**
- **Tesseract OCR**
- **PubMedQA corpus**

## Connections

- Report user → Simplify workspace: enters text or file (evidence: `frontend/react/src/features/simplify/SimplifyWorkspace.jsx`)
- App composition → App shell: renders (evidence: `frontend/react/src/App.jsx`)
- App composition → Landing guidance: renders (evidence: `frontend/react/src/App.jsx`)
- App composition → Simplify workspace: renders (evidence: `frontend/react/src/App.jsx`)
- Simplify workspace → API client: submits input (evidence: `frontend/react/src/features/simplify/SimplifyWorkspace.jsx`)
- API client → FastAPI endpoints: sends simplify request (evidence: `README.md`)
- Simplify workspace → Explanation results: renders response (evidence: `frontend/react/src/features/simplify/SimplifyWorkspace.jsx`)
- Simplify workspace → Evaluation dashboard: renders (evidence: `frontend/react/src/features/simplify/SimplifyWorkspace.jsx`)
- FastAPI endpoints → Report OCR: processes uploaded reports (evidence: `README.md`)
- Report OCR → Tesseract OCR: extracts text (evidence: `README.md`)
- FastAPI endpoints → Text simplifier: simplifies clinical text (evidence: `README.md`)
- Text simplifier → Context retriever: retrieves context (evidence: `backend/app/pipeline/simplifier.py`)
- Text simplifier → Simplification prompt: fills template (evidence: `backend/app/pipeline/simplifier.py`)
- Text simplifier → Gemini client: requests generation (evidence: `backend/app/pipeline/simplifier.py`)
- Gemini client → Google Gemini: calls model
- Context retriever → Text embedder: embeds query
- Text embedder → Gemini client: requests embeddings (evidence: `backend/app/rag/embedder.py`)
- Context retriever → Pinecone index: queries vectors (evidence: `README.md`)
- Ingestion runner → Corpus ingestion: starts ingestion (evidence: `scripts/ingest_corpus.py`)
- Corpus ingestion → PubMedQA corpus: loads abstracts (evidence: `backend/app/rag/ingest.py`)
- Corpus ingestion → Text embedder: embeds chunks (evidence: `backend/app/rag/ingest.py`)
- Corpus ingestion → Pinecone index: upserts vectors (evidence: `backend/app/rag/ingest.py`)
- FastAPI endpoints → Request logger: logs requests (evidence: `README.md`)
- Request logger → Supabase logging: writes logs (evidence: `README.md`)
- Request logger → Service settings: reads credentials (evidence: `backend/app/db/logger.py`)
- Evaluation benchmark → FastAPI endpoints: evaluates responses (evidence: `README.md`)
