# ayush-hassan07/liverguard architecture

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

- Interactive diagram: https://gitdiagram.com/ayush-hassan07/liverguard
- Repository: https://github.com/ayush-hassan07/liverguard

## Overview

LiverGuard is an educational NAFLD-risk prediction web application. Users enter health markers in the frontend, which submits them through the ASP.NET API to the FastAPI inference service; the result page presents the score, threshold, model scores, and SHAP feature contributions. The README documents this service chain and the model’s capabilities. Backend implementation details were not excerpted, so its internal handling is summarized rather than decomposed; unsampled informational pages are retained as distinct product capabilities.

Main entry points: [`ml-service/app/main.py`](https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/main.py) (FastAPI endpoints), [`frontend/components/PredictionForm.tsx`](https://github.com/ayush-hassan07/liverguard/blob/master/frontend/components/PredictionForm.tsx) (Marker form), [`ml-service/app/inference.py`](https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/inference.py) (Preprocessing and ensemble inference), [`frontend/lib/api.ts`](https://github.com/ayush-hassan07/liverguard/blob/master/frontend/lib/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_home["Home page<br/>[page.tsx]"]
  node_model_info["Model overview<br/>[page.tsx]"]
  node_privacy["Privacy information<br/>[page.tsx]"]
  node_predict_page["Prediction page<br/>[page.tsx]"]
  node_form["Marker form<br/>[PredictionForm.tsx]"]
  node_web_client["API client<br/>[api.ts]"]
  node_results["Results and explanations<br/>[page.tsx]"]
end

subgraph group_api["API boundary"]
  node_api["ASP.NET prediction API<br/>[Program.cs]"]
end

subgraph group_inference["Inference service"]
  node_ml_api["FastAPI endpoints<br/>[main.py]"]
  node_request_schema["Request and response schemas<br/>[schemas.py]"]
  node_artifact_loader["Artifact loader<br/>[model_loader.py]"]
  node_inference_logic["Preprocessing and ensemble inference<br/>[inference.py]"]
  node_explanations["SHAP contributions<br/>[inference.py]"]
end

subgraph group_models["Model artifacts"]
  node_model_config["Model configuration<br/>[config.py]"]
  node_trained_artifacts[("Trained models and thresholds")]
end

node_browser(("User browser"))

node_browser -->|"opens"| node_home
node_browser -->|"enters markers"| node_predict_page
node_predict_page -->|"renders"| node_form
node_form -->|"submits payload"| node_web_client
node_web_client -->|"POSTs prediction"| node_api
node_api -->|"calls ML service"| node_ml_api
node_ml_api -->|"validates and returns"| node_request_schema
node_ml_api -->|"loads artifacts"| node_artifact_loader
node_ml_api -->|"dispatches prediction"| node_inference_logic
node_artifact_loader -->|"loads models"| node_trained_artifacts
node_inference_logic -->|"uses ensemble"| node_trained_artifacts
node_inference_logic -->|"computes SHAP"| node_explanations
node_form -->|"stores result"| node_results
node_results -->|"uses response type"| node_web_client
node_browser -->|"reads about model"| node_model_info
node_browser -->|"reads privacy details"| node_privacy
node_ml_api -->|"configures service"| node_model_config
node_model_config -->|"locates model files"| node_trained_artifacts

click node_home "https://github.com/ayush-hassan07/liverguard/blob/master/frontend/app/page.tsx"
click node_model_info "https://github.com/ayush-hassan07/liverguard/blob/master/frontend/app/about-model/page.tsx"
click node_privacy "https://github.com/ayush-hassan07/liverguard/blob/master/frontend/app/privacy/page.tsx"
click node_predict_page "https://github.com/ayush-hassan07/liverguard/blob/master/frontend/app/predict/page.tsx"
click node_form "https://github.com/ayush-hassan07/liverguard/blob/master/frontend/components/PredictionForm.tsx"
click node_web_client "https://github.com/ayush-hassan07/liverguard/blob/master/frontend/lib/api.ts"
click node_results "https://github.com/ayush-hassan07/liverguard/blob/master/frontend/app/results/page.tsx"
click node_api "https://github.com/ayush-hassan07/liverguard/blob/master/backend/Program.cs"
click node_ml_api "https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/main.py"
click node_request_schema "https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/schemas.py"
click node_artifact_loader "https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/model_loader.py"
click node_inference_logic "https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/inference.py"
click node_explanations "https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/inference.py"
click node_model_config "https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/config.py"
click node_trained_artifacts "https://github.com/ayush-hassan07/liverguard/tree/master/ml-service/models"

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_home,node_model_info,node_privacy,node_predict_page,node_form,node_web_client,node_results,node_browser toneBlue
class node_api toneAmber
class node_ml_api,node_request_schema,node_artifact_loader,node_inference_logic,node_explanations toneMint
class node_model_config,node_trained_artifacts toneRose
```

## Components

### Web experience

- [Home page](https://github.com/ayush-hassan07/liverguard/blob/master/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Model overview](https://github.com/ayush-hassan07/liverguard/blob/master/frontend/app/about-model/page.tsx): `frontend/app/about-model/page.tsx`
- [Privacy information](https://github.com/ayush-hassan07/liverguard/blob/master/frontend/app/privacy/page.tsx): `frontend/app/privacy/page.tsx`
- [Prediction page](https://github.com/ayush-hassan07/liverguard/blob/master/frontend/app/predict/page.tsx): `frontend/app/predict/page.tsx`
- [Marker form](https://github.com/ayush-hassan07/liverguard/blob/master/frontend/components/PredictionForm.tsx): `frontend/components/PredictionForm.tsx`
- [API client](https://github.com/ayush-hassan07/liverguard/blob/master/frontend/lib/api.ts): `frontend/lib/api.ts`
- [Results and explanations](https://github.com/ayush-hassan07/liverguard/blob/master/frontend/app/results/page.tsx): `frontend/app/results/page.tsx`

### API boundary

- [ASP.NET prediction API](https://github.com/ayush-hassan07/liverguard/blob/master/backend/Program.cs): `backend/Program.cs`

### Inference service

- [FastAPI endpoints](https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/main.py): `ml-service/app/main.py`
- [Request and response schemas](https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/schemas.py): `ml-service/app/schemas.py`
- [Artifact loader](https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/model_loader.py): `ml-service/app/model_loader.py`
- [Preprocessing and ensemble inference](https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/inference.py): `ml-service/app/inference.py`
- [SHAP contributions](https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/inference.py): `ml-service/app/inference.py`

### Model artifacts

- [Model configuration](https://github.com/ayush-hassan07/liverguard/blob/master/ml-service/app/config.py): `ml-service/app/config.py`
- [Trained models and thresholds](https://github.com/ayush-hassan07/liverguard/tree/master/ml-service/models): `ml-service/models`

### Other components

- **User browser**

## Connections

- User browser → Home page: opens (evidence: `README.md`)
- User browser → Prediction page: enters markers (evidence: `README.md`)
- Prediction page → Marker form: renders (evidence: `frontend/app/predict/page.tsx`)
- Marker form → API client: submits payload (evidence: `frontend/components/PredictionForm.tsx`)
- API client → ASP.NET prediction API: POSTs prediction (evidence: `README.md`)
- ASP.NET prediction API → FastAPI endpoints: calls ML service (evidence: `README.md`)
- FastAPI endpoints → Request and response schemas: validates and returns (evidence: `ml-service/app/main.py`)
- FastAPI endpoints → Artifact loader: loads artifacts (evidence: `ml-service/app/main.py`)
- FastAPI endpoints → Preprocessing and ensemble inference: dispatches prediction (evidence: `ml-service/app/main.py`)
- Artifact loader → Trained models and thresholds: loads models (evidence: `ml-service/app/model_loader.py`)
- Preprocessing and ensemble inference → Trained models and thresholds: uses ensemble (evidence: `ml-service/app/inference.py`)
- Preprocessing and ensemble inference → SHAP contributions: computes SHAP (evidence: `ml-service/app/inference.py`)
- Marker form → Results and explanations: stores result (evidence: `frontend/components/PredictionForm.tsx`)
- Results and explanations → API client: uses response type (evidence: `frontend/app/results/page.tsx`)
- User browser → Model overview: reads about model
- User browser → Privacy information: reads privacy details
- FastAPI endpoints → Model configuration: configures service (evidence: `ml-service/app/main.py`)
- Model configuration → Trained models and thresholds: locates model files (evidence: `ml-service/app/config.py`)
