# ranasl62/ehr-risk-framework architecture

> Architecture diagram of the GitHub repository ranasl62/ehr-risk-framework, 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/ranasl62/ehr-risk-framework
- Repository: https://github.com/ranasl62/ehr-risk-framework

## Overview

EHR Risk Framework is a research workbench for leakage-aware clinical risk modeling, exposed through a FastAPI service and Angular UI. The principal loop is dataset/task setup, temporally safe feature construction and model training, audit and evaluation, then result review and prediction. Named runs, trust artifacts, fairness, SHAP, dataset health, adapters, and exports are additional capabilities documented in the README. Some links below use README workflow descriptions; unsampled implementations are represented only where the tree or README supports them.

Main entry points: [`api/framework_routes.py`](https://github.com/ranasl62/ehr-risk-framework/blob/main/api/framework_routes.py) (Framework routes), [`training/train.py`](https://github.com/ranasl62/ehr-risk-framework/blob/main/training/train.py) (Model training), [`api/main.py`](https://github.com/ranasl62/ehr-risk-framework/blob/main/api/main.py) (FastAPI application), [`api/researcher_routes.py`](https://github.com/ranasl62/ehr-risk-framework/blob/main/api/researcher_routes.py) (Research routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Research interface"]
  node_workbench["Workbench routes<br/>[app.routes.ts]"]
  node_ui_pages["Workbench pages"]
  node_api_client["API client<br/>[api.service.ts]"]
end

subgraph group_api["API and orchestration"]
  node_api_app["FastAPI application<br/>[main.py]"]
  node_research_routes["Research routes"]
  node_framework_routes["Framework routes"]
  node_job_runner["Job orchestration<br/>[jobs.py]"]
  node_data_io["Dataset operations<br/>[data_io.py]"]
  node_prediction["Prediction validation<br/>[validation.py]"]
end

subgraph group_data["Data preparation"]
  node_preprocessing["EHR preprocessing"]
  node_temporal_features["Temporal features"]
  node_adapters["Data adapters<br/>[adapters.py]"]
  node_health["Dataset health<br/>[health.py]"]
end

subgraph group_modeling["Modeling and assessment"]
  node_training["Model training<br/>[train.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_fairness["Fairness assessment<br/>[bias_metrics.py]"]
  node_explainability["SHAP explanations<br/>[shap_explainer.py]"]
end

subgraph group_research["Research records"]
  node_task_specs["Task specifications<br/>[task_spec.py]"]
  node_runs[("Experiment runs<br/>[runs.py]")]
  node_trust["Trust artifacts<br/>[trust_pack.py]"]
  node_events[("Workspace events<br/>[events.py]")]
end

node_researcher(("Researcher"))

node_researcher -->|"uses"| node_workbench
node_workbench -->|"routes to"| node_ui_pages
node_ui_pages -.->|"requests data"| node_api_client
node_api_client -.->|"calls API"| node_api_app
node_api_app -->|"registers"| node_research_routes
node_api_app -->|"registers"| node_framework_routes
node_research_routes -->|"manages datasets"| node_data_io
node_research_routes -->|"starts jobs"| node_job_runner
node_research_routes -->|"loads tasks"| node_task_specs
node_framework_routes -->|"writes task definitions"| node_task_specs
node_framework_routes -->|"reads events"| node_events
node_framework_routes -->|"reads runs"| node_runs
node_framework_routes -->|"imports payloads"| node_adapters
node_framework_routes -->|"reports health"| node_health
node_job_runner -->|"runs training"| node_training
node_job_runner -->|"runs fairness"| node_fairness
node_job_runner -->|"runs SHAP"| node_explainability
node_training -->|"applies task settings"| node_task_specs
node_training -->|"uses preprocessing"| node_preprocessing
node_preprocessing -->|"builds features"| node_temporal_features
node_training -->|"evaluates model"| node_evaluation
node_training -->|"validates features"| node_prediction
node_training -.->|"records experiment"| node_runs
node_runs -->|"summarizes trust"| node_trust
node_api_app -->|"validates prediction"| node_prediction
node_api_app -->|"serves explanations"| node_explainability
node_research_routes -->|"exposes run records"| node_runs
node_researcher -->|"uses research API"| node_api_app

click node_workbench "https://github.com/ranasl62/ehr-risk-framework/blob/main/web/src/app/app.routes.ts"
click node_ui_pages "https://github.com/ranasl62/ehr-risk-framework/tree/main/web/src/app/pages"
click node_api_client "https://github.com/ranasl62/ehr-risk-framework/blob/main/web/src/app/core/api.service.ts"
click node_api_app "https://github.com/ranasl62/ehr-risk-framework/blob/main/api/main.py"
click node_research_routes "https://github.com/ranasl62/ehr-risk-framework/blob/main/api/researcher_routes.py"
click node_framework_routes "https://github.com/ranasl62/ehr-risk-framework/blob/main/api/framework_routes.py"
click node_job_runner "https://github.com/ranasl62/ehr-risk-framework/blob/main/api/jobs.py"
click node_data_io "https://github.com/ranasl62/ehr-risk-framework/blob/main/api/data_io.py"
click node_task_specs "https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/task_spec.py"
click node_preprocessing "https://github.com/ranasl62/ehr-risk-framework/blob/main/preprocessing/feature_engineering.py"
click node_temporal_features "https://github.com/ranasl62/ehr-risk-framework/blob/main/feature_engineering/time_window_features.py"
click node_training "https://github.com/ranasl62/ehr-risk-framework/blob/main/training/train.py"
click node_evaluation "https://github.com/ranasl62/ehr-risk-framework/blob/main/training/evaluate.py"
click node_fairness "https://github.com/ranasl62/ehr-risk-framework/blob/main/fairness/bias_metrics.py"
click node_explainability "https://github.com/ranasl62/ehr-risk-framework/blob/main/explainability/shap_explainer.py"
click node_prediction "https://github.com/ranasl62/ehr-risk-framework/blob/main/inference/validation.py"
click node_runs "https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/runs.py"
click node_trust "https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/trust_pack.py"
click node_events "https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/events.py"
click node_adapters "https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/adapters.py"
click node_health "https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/health.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_workbench,node_ui_pages,node_api_client toneBlue
class node_api_app,node_research_routes,node_framework_routes,node_job_runner,node_data_io,node_prediction toneAmber
class node_preprocessing,node_temporal_features,node_adapters,node_health toneMint
class node_training,node_evaluation,node_fairness,node_explainability toneRose
class node_task_specs,node_runs,node_trust,node_events,node_researcher toneIndigo
```

## Components

### Research interface

- [Workbench routes](https://github.com/ranasl62/ehr-risk-framework/blob/main/web/src/app/app.routes.ts): `web/src/app/app.routes.ts`
- [Workbench pages](https://github.com/ranasl62/ehr-risk-framework/tree/main/web/src/app/pages): `web/src/app/pages`
- [API client](https://github.com/ranasl62/ehr-risk-framework/blob/main/web/src/app/core/api.service.ts): `web/src/app/core/api.service.ts`

### API and orchestration

- [FastAPI application](https://github.com/ranasl62/ehr-risk-framework/blob/main/api/main.py): `api/main.py`
- [Research routes](https://github.com/ranasl62/ehr-risk-framework/blob/main/api/researcher_routes.py): `api/researcher_routes.py`
- [Framework routes](https://github.com/ranasl62/ehr-risk-framework/blob/main/api/framework_routes.py): `api/framework_routes.py`
- [Job orchestration](https://github.com/ranasl62/ehr-risk-framework/blob/main/api/jobs.py): `api/jobs.py`
- [Dataset operations](https://github.com/ranasl62/ehr-risk-framework/blob/main/api/data_io.py): `api/data_io.py`
- [Prediction validation](https://github.com/ranasl62/ehr-risk-framework/blob/main/inference/validation.py): `inference/validation.py`

### Data preparation

- [EHR preprocessing](https://github.com/ranasl62/ehr-risk-framework/blob/main/preprocessing/feature_engineering.py): `preprocessing/feature_engineering.py`
- [Temporal features](https://github.com/ranasl62/ehr-risk-framework/blob/main/feature_engineering/time_window_features.py): `feature_engineering/time_window_features.py`
- [Data adapters](https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/adapters.py): `openhealth/adapters.py`
- [Dataset health](https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/health.py): `openhealth/health.py`

### Modeling and assessment

- [Model training](https://github.com/ranasl62/ehr-risk-framework/blob/main/training/train.py): `training/train.py`
- [Model evaluation](https://github.com/ranasl62/ehr-risk-framework/blob/main/training/evaluate.py): `training/evaluate.py`
- [Fairness assessment](https://github.com/ranasl62/ehr-risk-framework/blob/main/fairness/bias_metrics.py): `fairness/bias_metrics.py`
- [SHAP explanations](https://github.com/ranasl62/ehr-risk-framework/blob/main/explainability/shap_explainer.py): `explainability/shap_explainer.py`

### Research records

- [Task specifications](https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/task_spec.py): `openhealth/task_spec.py`
- [Experiment runs](https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/runs.py): `openhealth/runs.py`
- [Trust artifacts](https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/trust_pack.py): `openhealth/trust_pack.py`
- [Workspace events](https://github.com/ranasl62/ehr-risk-framework/blob/main/openhealth/events.py): `openhealth/events.py`

### Other components

- **Researcher**

## Connections

- Researcher → Workbench routes: uses (evidence: `README.md`)
- Workbench routes → Workbench pages: routes to (evidence: `web/src/app/app.routes.ts`)
- Workbench pages → API client: requests data
- API client → FastAPI application: calls API
- FastAPI application → Research routes: registers (evidence: `api/main.py`)
- FastAPI application → Framework routes: registers (evidence: `api/main.py`)
- Research routes → Dataset operations: manages datasets (evidence: `api/researcher_routes.py`)
- Research routes → Job orchestration: starts jobs (evidence: `api/researcher_routes.py`)
- Research routes → Task specifications: loads tasks (evidence: `api/researcher_routes.py`)
- Framework routes → Task specifications: writes task definitions (evidence: `api/framework_routes.py`)
- Framework routes → Workspace events: reads events (evidence: `api/framework_routes.py`)
- Framework routes → Experiment runs: reads runs (evidence: `api/framework_routes.py`)
- Framework routes → Data adapters: imports payloads (evidence: `api/framework_routes.py`)
- Framework routes → Dataset health: reports health (evidence: `api/framework_routes.py`)
- Job orchestration → Model training: runs training (evidence: `api/jobs.py`)
- Job orchestration → Fairness assessment: runs fairness (evidence: `api/jobs.py`)
- Job orchestration → SHAP explanations: runs SHAP (evidence: `api/jobs.py`)
- Model training → Task specifications: applies task settings (evidence: `training/train.py`)
- Model training → EHR preprocessing: uses preprocessing (evidence: `training/train.py`)
- EHR preprocessing → Temporal features: builds features (evidence: `preprocessing/feature_engineering.py`)
- Model training → Model evaluation: evaluates model (evidence: `training/train.py`)
- Model training → Prediction validation: validates features (evidence: `training/train.py`)
- Model training → Experiment runs: records experiment
- Experiment runs → Trust artifacts: summarizes trust (evidence: `openhealth/runs.py`)
- FastAPI application → Prediction validation: validates prediction (evidence: `api/main.py`)
- FastAPI application → SHAP explanations: serves explanations (evidence: `api/main.py`)
- Research routes → Experiment runs: exposes run records (evidence: `api/researcher_routes.py`)
- Researcher → FastAPI application: uses research API (evidence: `README.md`)
