# ajay-pujari/insurance-renewal-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/ajay-pujari/insurance-renewal-prediction
- Repository: https://github.com/ajay-pujari/insurance-renewal-prediction

## Overview

This is a Flask insurance-renewal risk and retention system. Agents and admins use an authenticated dashboard and API to manage policyholder, policy, and payment records; the API scores policies approaching renewal, and admins can run offer campaigns whose responses and outcomes feed campaign analytics. The model is trained from policy data and serves predictions in the API; batch scoring also produces a risk report. The sampled excerpts show only parts of the monolithic API, so several subsystem boundaries and links below rely on README descriptions rather than inspected handlers.

Main entry points: [`app.py`](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py) (Flask API), [`renewal_model.joblib`](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/renewal_model.joblib) (Renewal model), [`batch_score.py`](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/batch_score.py) (Batch risk reports), [`build_features.py`](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/build_features.py) (Feature extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and UI"]
  node_api["Flask API<br/>[app.py]"]
  node_auth["Authentication and roles<br/>[app.py]"]
  node_dashboard["Dashboard<br/>[dashboard.html]"]
end

subgraph group_records["Policy records"]
  node_policyholders["Policyholders<br/>[app.py]"]
  node_policies["Policies and payments<br/>[app.py]"]
  node_database[("SQLite records<br/>[app.py]")]
end

subgraph group_renewal["Renewal workflow"]
  node_scoring["Renewal scoring<br/>[app.py]"]
  node_upcoming["Upcoming renewals<br/>[app.py]"]
  node_campaigns["Retention campaigns<br/>[app.py]"]
  node_responses["Responses and outcomes<br/>[app.py]"]
  node_analytics["Campaign analytics<br/>[app.py]"]
  node_batch["Batch risk reports<br/>[batch_score.py]"]
end

subgraph group_modeling["Prediction"]
  node_features["Feature extraction<br/>[build_features.py]"]
  node_training["Model training<br/>[train_model.py]"]
  node_model["Renewal model"]
end

node_user(("Agent or admin"))

node_user -->|"uses"| node_dashboard
node_dashboard -->|"calls API"| node_api
node_user -->|"signs in"| node_api
node_api -->|"checks access"| node_auth
node_api -->|"manages records"| node_policyholders
node_api -->|"manages records"| node_policies
node_policyholders -->|"reads and writes"| node_database
node_policies -->|"reads and writes"| node_database
node_features -->|"reads records"| node_database
node_features -->|"provides features"| node_training
node_training -->|"saves model"| node_model
node_api -->|"loads model"| node_model
node_api -->|"serves predictions"| node_scoring
node_scoring -->|"uses policy data"| node_policies
node_api -->|"lists renewals"| node_upcoming
node_api -->|"runs campaigns"| node_campaigns
node_campaigns -->|"scores candidates"| node_model
node_api -->|"records updates"| node_responses
node_api -->|"serves statistics"| node_analytics
node_batch -->|"imports scoring logic"| node_api
node_batch -->|"reads records"| node_database
node_batch -->|"scores policies"| node_model

click node_api "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py"
click node_auth "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py"
click node_dashboard "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/templates/dashboard.html"
click node_policyholders "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py"
click node_policies "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py"
click node_database "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py"
click node_features "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/build_features.py"
click node_training "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/train_model.py"
click node_model "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/renewal_model.joblib"
click node_scoring "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py"
click node_upcoming "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py"
click node_campaigns "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py"
click node_responses "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py"
click node_analytics "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py"
click node_batch "https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/batch_score.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_api,node_auth,node_dashboard toneBlue
class node_policyholders,node_policies,node_database toneAmber
class node_scoring,node_upcoming,node_campaigns,node_responses,node_analytics,node_batch toneMint
class node_features,node_training,node_model toneRose
class node_user toneIndigo
```

## Components

### Access and UI

- [Flask API](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py): `app.py`
- [Authentication and roles](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py): `app.py`
- [Dashboard](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/templates/dashboard.html): `templates/dashboard.html`

### Policy records

- [Policyholders](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py): `app.py`
- [Policies and payments](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py): `app.py`
- [SQLite records](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py): `app.py`

### Renewal workflow

- [Renewal scoring](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py): `app.py`
- [Upcoming renewals](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py): `app.py`
- [Retention campaigns](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py): `app.py`
- [Responses and outcomes](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py): `app.py`
- [Campaign analytics](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/app.py): `app.py`
- [Batch risk reports](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/batch_score.py): `batch_score.py`

### Prediction

- [Feature extraction](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/build_features.py): `build_features.py`
- [Model training](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/train_model.py): `train_model.py`
- [Renewal model](https://github.com/ajay-pujari/insurance-renewal-prediction/blob/main/renewal_model.joblib): `renewal_model.joblib`

### Other components

- **Agent or admin**

## Connections

- Agent or admin → Dashboard: uses (evidence: `README.md`)
- Dashboard → Flask API: calls API (evidence: `README.md`)
- Agent or admin → Flask API: signs in (evidence: `README.md`)
- Flask API → Authentication and roles: checks access (evidence: `README.md`)
- Flask API → Policyholders: manages records (evidence: `README.md`)
- Flask API → Policies and payments: manages records (evidence: `README.md`)
- Policyholders → SQLite records: reads and writes (evidence: `app.py`)
- Policies and payments → SQLite records: reads and writes (evidence: `app.py`)
- Feature extraction → SQLite records: reads records (evidence: `build_features.py`)
- Feature extraction → Model training: provides features (evidence: `README.md`)
- Model training → Renewal model: saves model (evidence: `README.md`)
- Flask API → Renewal model: loads model (evidence: `app.py`)
- Flask API → Renewal scoring: serves predictions (evidence: `README.md`)
- Renewal scoring → Policies and payments: uses policy data (evidence: `app.py`)
- Flask API → Upcoming renewals: lists renewals (evidence: `README.md`)
- Flask API → Retention campaigns: runs campaigns (evidence: `README.md`)
- Retention campaigns → Renewal model: scores candidates (evidence: `app.py`)
- Flask API → Responses and outcomes: records updates (evidence: `README.md`)
- Flask API → Campaign analytics: serves statistics (evidence: `README.md`)
- Batch risk reports → Flask API: imports scoring logic (evidence: `batch_score.py`)
- Batch risk reports → SQLite records: reads records (evidence: `batch_score.py`)
- Batch risk reports → Renewal model: scores policies (evidence: `batch_score.py`)
