# johnwilfredd-curimo/health-insurance-premium-prediction architecture

> Architecture diagram of the GitHub repository johnwilfredd-curimo/health-insurance-premium-prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/johnwilfredd-curimo/health-insurance-premium-prediction
- Repository: https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction

## Overview

The product is a health-insurance premium predictor, served through a Streamlit demo and a FastAPI JSON API. In either interface, a user supplies customer details; the API validates and maps its request, while the demo gathers the corresponding fields, and both call the shared prediction module. That module encodes features, derives medical-history risk, scales inputs, selects a model by age, and returns a premium. The README also documents a notebook-based modeling lifecycle. Its implementation and its connection to the shipped artifacts were not sampled, so those links remain unverified.

Main entry points: [`src/prediction.py`](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py) (Prediction entry), [`api/main.py`](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/api/main.py) (FastAPI service), [`streamlit_app.py`](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/streamlit_app.py) (Streamlit demo), [`artifacts/model_young.joblib`](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/artifacts/model_young.joblib) (Young model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_demo["Streamlit demo<br/>[streamlit_app.py]"]
  node_api["FastAPI service<br/>[main.py]"]
  node_request["Input validation<br/>[main.py]"]
  node_response["Premium response<br/>[main.py]"]
end

subgraph group_inference["Prediction runtime"]
  node_predict["Prediction entry<br/>[prediction.py]"]
  node_features["Feature encoding<br/>[prediction.py]"]
  node_risk["Medical risk scoring<br/>[prediction.py]"]
  node_scaling["Feature scaling<br/>[prediction.py]"]
  node_routing["Age-based routing<br/>[prediction.py]"]
end

subgraph group_models["Models and lifecycle"]
  node_young["Young model<br/>[model_young.joblib]"]
  node_rest["26+ model<br/>[model_rest.joblib]"]
  node_scalers["Fitted scalers"]
  node_notebook["Modeling notebook"]
end

node_agent(("Agent / caller"))

node_agent -->|"enters details"| node_demo
node_agent -->|"submits request"| node_api
node_api -->|"validates payload"| node_request
node_request -->|"maps and calls"| node_predict
node_demo -->|"calls predict"| node_predict
node_predict -->|"preprocesses input"| node_features
node_features -->|"calculates risk"| node_risk
node_features -->|"scales features"| node_scaling
node_predict -->|"routes by age"| node_routing
node_routing -->|"predicts ages 18–25"| node_young
node_routing -->|"predicts ages 26+"| node_rest
node_scaling -->|"loads scaler pair"| node_scalers
node_api -->|"returns premium"| node_response
node_notebook -.->|"produces trained models"| node_young
node_notebook -.->|"produces trained models"| node_rest

click node_demo "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/streamlit_app.py"
click node_api "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/api/main.py"
click node_request "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/api/main.py"
click node_response "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/api/main.py"
click node_predict "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py"
click node_features "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py"
click node_risk "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py"
click node_scaling "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py"
click node_routing "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py"
click node_young "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/artifacts/model_young.joblib"
click node_rest "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/artifacts/model_rest.joblib"
click node_scalers "https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/tree/main/artifacts"

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_demo,node_api,node_request,node_response toneBlue
class node_predict,node_features,node_risk,node_scaling,node_routing toneAmber
class node_young,node_rest,node_scalers,node_notebook toneMint
class node_agent toneIndigo
```

## Components

### User interfaces

- [Streamlit demo](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/streamlit_app.py): `streamlit_app.py`
- [FastAPI service](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/api/main.py): `api/main.py`
- [Input validation](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/api/main.py): `api/main.py`
- [Premium response](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/api/main.py): `api/main.py`

### Prediction runtime

- [Prediction entry](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py): `src/prediction.py`
- [Feature encoding](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py): `src/prediction.py`
- [Medical risk scoring](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py): `src/prediction.py`
- [Feature scaling](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py): `src/prediction.py`
- [Age-based routing](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/src/prediction.py): `src/prediction.py`

### Models and lifecycle

- [Young model](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/artifacts/model_young.joblib): `artifacts/model_young.joblib`
- [26+ model](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/blob/main/artifacts/model_rest.joblib): `artifacts/model_rest.joblib`
- [Fitted scalers](https://github.com/johnwilfredd-curimo/health-insurance-premium-prediction/tree/main/artifacts): `artifacts`
- **Modeling notebook**

### Other components

- **Agent / caller**

## Connections

- Agent / caller → Streamlit demo: enters details (evidence: `streamlit_app.py`)
- Agent / caller → FastAPI service: submits request (evidence: `README.md`)
- FastAPI service → Input validation: validates payload (evidence: `api/main.py`)
- Input validation → Prediction entry: maps and calls (evidence: `api/main.py`)
- Streamlit demo → Prediction entry: calls predict (evidence: `streamlit_app.py`)
- Prediction entry → Feature encoding: preprocesses input (evidence: `src/prediction.py`)
- Feature encoding → Medical risk scoring: calculates risk (evidence: `src/prediction.py`)
- Feature encoding → Feature scaling: scales features (evidence: `src/prediction.py`)
- Prediction entry → Age-based routing: routes by age (evidence: `src/prediction.py`)
- Age-based routing → Young model: predicts ages 18–25 (evidence: `src/prediction.py`)
- Age-based routing → 26+ model: predicts ages 26+ (evidence: `src/prediction.py`)
- Feature scaling → Fitted scalers: loads scaler pair (evidence: `src/prediction.py`)
- FastAPI service → Premium response: returns premium (evidence: `api/main.py`)
- Modeling notebook → Young model: produces trained models
- Modeling notebook → 26+ model: produces trained models
