Design & architecture diagrams

How the application is structured, how data moves through the system, and how you iterate (fine-tune) a research model. Drawn from the real code paths in this repository.

1. Big-picture architecture

Three entry surfaces (browser, CLI, OpenAPI) share one FastAPI + ML core. Artifacts live on the host filesystem.

2. End-to-end application data flow

Every research run follows the same pipeline. Numbers match the stages below.

1Ingest

Demo CSV, upload, form JSON, SQL, or map-import → data/uploads/

2Health

GET /v1/datasets/health blockers / warnings

3Task

YAML or Config: horizon, windows, split, model

4Features

Index truncate + w7d_/w30d_/w180d_

5Train

Fit ± calibrate → metrics + model.pkl

6Trust

Leakage audit, SHAP, fairness, Analytics

7Serve

POST /v1/predict + Predict UI

3. Temporal / feature design (why leakage matters)

Hard rule: features use only events at or before index_time. Labels use only events after index, inside the horizon.

Patient timeline → past events (labs, visits, ICD…) index_time FEATURE WINDOWS (w7d / w30d / w180d) — past only LABEL HORIZON H outcome only in (index, index+H] ✗ never use as features
Feature columns look like:  w7d_glucose, w30d_visit_count, w180d_icd_unique_count
Prediction form uses THESE names — not raw EHR column names.

4. HTTP request path (UI → API → ML)

Example: user clicks Predict in the Angular workbench (Compose: nginx proxies /v1/*api:8000; hosted demo calls ehr-api.larucare.com via baked API_ENDPOINT).

Train path

POST /v1/jobs/train → background ThreadPool → training.train → poll GET /v1/jobs/{id}

Analytics path

GET /v1/datasets/profile?path=&age_band=&label= → KPIs, charts, cohort table

5. Training pipeline internals

6. Fine-tuning & model iteration (overview)

This framework does not fine-tune large language models. “Fine-tuning” here means iterating a tabular risk model: better data, windows, splits, model family, and calibration — then promoting the best artifact.

Full step-by-step guide: Fine-tuning playbook →

1. Lock task YAML 2. Health gate 3. Train baseline 4. Leakage + SHAP 5. Compare models 6. Tune knobs windows · calibrate · split 7. Promote best iterate until metrics + audits look honest

7. Runtime topology (Docker)

8. Trust & serve loop

After every serious train

  1. Run leakage audit (Train page or API job)
  2. Check Brier / ECE; enable calibrate if needed
  3. Generate SHAP; inspect Analytics + Results
  4. Download results ZIP for your methods appendix

Before you demo Predict

  1. Confirm GET /v1/model/schema matches your features
  2. Fill medians → predict → read SHAP drivers
  3. State clearly: research score, not clinical advice
Analytics dashboard
Analytics — cohort + model charts after training

Next: Fine-tuning playbook · Architecture notes · Commands