# samarth3394/medical-insurance-cost-predictor architecture

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

- Interactive diagram: https://gitdiagram.com/samarth3394/medical-insurance-cost-predictor
- Repository: https://github.com/samarth3394/medical-insurance-cost-predictor

## Overview

This is a medical-insurance cost prediction application: users submit a health profile through a web interface, the FastAPI endpoint validates and encodes it, applies the saved model, and returns an estimated charge with model metrics. Separate capabilities include model exploration/training, a results dashboard, and health/model-info endpoints. The API implementation is excerpted; training and frontend details are documented in the README but their source contents were not sampled, so those relationships are shown only where documented.

Main entry points: [`app/main.py`](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py) (Prediction endpoint), [`model/model_results.json`](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/model/model_results.json) (Model metrics), [`notebooks/insurance_eda.ipynb`](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/notebooks/insurance_eda.ipynb) (EDA and training), [`templates/index.html`](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/templates/index.html) (Prediction form)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_prediction_ui["Prediction form<br/>[index.html]"]
  node_dashboard_ui["EDA dashboard<br/>[dashboard.html]"]
  node_web_routes["Page routes<br/>[main.py]"]
end

subgraph group_prediction["Prediction API"]
  node_prediction_route["Prediction endpoint<br/>[main.py]"]
  node_input_validation["Input validation<br/>[main.py]"]
  node_feature_encoding["Feature encoding<br/>[main.py]"]
  node_feature_scaling["Feature scaling<br/>[main.py]"]
  node_predictor["Saved predictor<br/>[model_bundle.pkl]"]
  node_prediction_response["Prediction response<br/>[main.py]"]
end

subgraph group_modeling["Model lifecycle"]
  node_training_data[("Insurance records<br/>[insurance.csv]")]
  node_analysis_training["EDA and training"]
  node_model_artifacts["Model bundle<br/>[model_bundle.pkl]"]
  node_model_metrics["Model metrics<br/>[model_results.json]"]
end

subgraph group_operations["API status"]
  node_health_endpoint["Health endpoint<br/>[main.py]"]
  node_model_info_endpoint["Model-info endpoint<br/>[main.py]"]
end

node_person(("Insurance user"))

node_person -->|"enters profile"| node_prediction_ui
node_prediction_ui -->|"submits profile"| node_prediction_route
node_person -->|"opens dashboard"| node_dashboard_ui
node_web_routes -->|"renders page"| node_prediction_ui
node_web_routes -->|"renders page"| node_dashboard_ui
node_prediction_route -->|"validates input"| node_input_validation
node_prediction_route -->|"encodes features"| node_feature_encoding
node_prediction_route -->|"scales features"| node_feature_scaling
node_prediction_route -->|"predicts charge"| node_predictor
node_prediction_route -->|"returns result"| node_prediction_response
node_analysis_training -->|"analyzes records"| node_training_data
node_analysis_training -->|"serializes model"| node_model_artifacts
node_analysis_training -->|"records comparisons"| node_model_metrics
node_prediction_route -->|"reads metrics"| node_model_metrics
node_web_routes -->|"provides dashboard data"| node_model_metrics
node_health_endpoint -->|"reports model"| node_model_artifacts
node_model_info_endpoint -->|"returns comparisons"| node_model_metrics

click node_prediction_ui "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/templates/index.html"
click node_dashboard_ui "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/templates/dashboard.html"
click node_web_routes "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py"
click node_prediction_route "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py"
click node_input_validation "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py"
click node_feature_encoding "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py"
click node_feature_scaling "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py"
click node_predictor "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/model/model_bundle.pkl"
click node_prediction_response "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py"
click node_training_data "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/data/insurance.csv"
click node_analysis_training "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/notebooks/insurance_eda.ipynb"
click node_model_artifacts "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/model/model_bundle.pkl"
click node_model_metrics "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/model/model_results.json"
click node_health_endpoint "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py"
click node_model_info_endpoint "https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.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_prediction_ui,node_dashboard_ui,node_web_routes,node_person toneBlue
class node_prediction_route,node_input_validation,node_feature_encoding,node_feature_scaling,node_predictor,node_prediction_response toneAmber
class node_training_data,node_analysis_training,node_model_artifacts,node_model_metrics toneMint
class node_health_endpoint,node_model_info_endpoint toneRose
```

## Components

### Web experience

- [Prediction form](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/templates/index.html): `templates/index.html`
- [EDA dashboard](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/templates/dashboard.html): `templates/dashboard.html`
- [Page routes](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py): `app/main.py`

### Prediction API

- [Prediction endpoint](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py): `app/main.py`
- [Input validation](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py): `app/main.py`
- [Feature encoding](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py): `app/main.py`
- [Feature scaling](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py): `app/main.py`
- [Saved predictor](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/model/model_bundle.pkl): `model/model_bundle.pkl`
- [Prediction response](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py): `app/main.py`

### Model lifecycle

- [Insurance records](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/data/insurance.csv): `data/insurance.csv`
- [EDA and training](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/notebooks/insurance_eda.ipynb): `notebooks/insurance_eda.ipynb`
- [Model bundle](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/model/model_bundle.pkl): `model/model_bundle.pkl`
- [Model metrics](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/model/model_results.json): `model/model_results.json`

### API status

- [Health endpoint](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py): `app/main.py`
- [Model-info endpoint](https://github.com/samarth3394/medical-insurance-cost-predictor/blob/main/app/main.py): `app/main.py`

### Other components

- **Insurance user**

## Connections

- Insurance user → Prediction form: enters profile (evidence: `README.md`)
- Prediction form → Prediction endpoint: submits profile (evidence: `README.md`)
- Insurance user → EDA dashboard: opens dashboard (evidence: `README.md`)
- Page routes → Prediction form: renders page (evidence: `app/main.py`)
- Page routes → EDA dashboard: renders page (evidence: `app/main.py`)
- Prediction endpoint → Input validation: validates input (evidence: `app/main.py`)
- Prediction endpoint → Feature encoding: encodes features (evidence: `app/main.py`)
- Prediction endpoint → Feature scaling: scales features (evidence: `app/main.py`)
- Prediction endpoint → Saved predictor: predicts charge (evidence: `app/main.py`)
- Prediction endpoint → Prediction response: returns result (evidence: `app/main.py`)
- EDA and training → Insurance records: analyzes records (evidence: `README.md`)
- EDA and training → Model bundle: serializes model (evidence: `README.md`)
- EDA and training → Model metrics: records comparisons (evidence: `README.md`)
- Prediction endpoint → Model metrics: reads metrics (evidence: `app/main.py`)
- Page routes → Model metrics: provides dashboard data (evidence: `app/main.py`)
- Health endpoint → Model bundle: reports model (evidence: `app/main.py`)
- Model-info endpoint → Model metrics: returns comparisons (evidence: `app/main.py`)
