# dhruva-0206/aersi-forecast-alerts architecture

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

- Interactive diagram: https://gitdiagram.com/dhruva-0206/aersi-forecast-alerts
- Repository: https://github.com/dhruva-0206/aersi-forecast-alerts

## Overview

AERSI builds station-day AQI and weather features, trains a next-day XGBoost forecaster, and dispatches city-specific alerts for dangerous forecasts. A separate subscription Lambda registers contacts. The main runtime flow is documented as a daily AWS schedule invoking the dispatcher, which reads forecasts and subscribers and publishes alerts. Training and weather ingestion are source-backed; the README documents the AWS schedule and delivery capabilities. Snapshot inputs and AWS wiring are not present in the supplied tree, so those relationships are shown only where documented.

Main entry points: [`src/train_forecast.py`](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/src/train_forecast.py) (Train and validate), [`aws/lambda_function.py`](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/aws/lambda_function.py) (Alert dispatcher), [`data/processed/station_daily_panel.csv`](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/station_daily_panel.csv) (Station-day panel), [`src/fetch_weather.py`](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/src/fetch_weather.py) (Fetch weather)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Data preparation"]
  node_snapshots["AQI snapshots"]
  node_panel_builder["Build AQI panel"]
  node_station_panel["Station-day panel"]
  node_weather_api["Open-Meteo ERA5"]
  node_weather_fetch["Fetch weather<br/>[fetch_weather.py]"]
  node_weather_features["Weather features"]
end

subgraph group_forecast["Forecast modeling"]
  node_trainer["Train and validate<br/>[train_forecast.py]"]
  node_model["XGBoost model"]
  node_validation["Validation forecasts"]
  node_metadata["Model metadata"]
end

subgraph group_alerts["Alert delivery"]
  node_eventbridge["Daily schedule"]
  node_dispatcher["Alert dispatcher<br/>[lambda_function.py]"]
  node_forecasts_db[("Forecast registry")]
  node_subscribers_db[("Subscriber registry")]
  node_sns["Amazon SNS"]
  node_recipients(("SMS and email recipients"))
end

subgraph group_registration["Subscriber registration"]
  node_subscription_lambda["Register subscriber"]
end

node_registrant(("Subscriber"))

node_snapshots -->|"reads snapshots"| node_panel_builder
node_panel_builder -->|"writes panel"| node_station_panel
node_station_panel -->|"provides stations"| node_weather_fetch
node_weather_fetch -->|"fetches weather"| node_weather_api
node_weather_fetch -->|"writes features"| node_weather_features
node_station_panel -->|"loads panel"| node_trainer
node_weather_features -->|"loads features"| node_trainer
node_trainer -->|"saves model"| node_model
node_trainer -->|"writes predictions"| node_validation
node_trainer -->|"writes metrics"| node_metadata
node_eventbridge -->|"triggers daily"| node_dispatcher
node_dispatcher -->|"queries forecasts"| node_forecasts_db
node_dispatcher -->|"scans subscribers"| node_subscribers_db
node_dispatcher -->|"publishes alerts"| node_sns
node_subscription_lambda -->|"subscribes contact"| node_sns
node_subscription_lambda -->|"stores subscriber"| node_subscribers_db
node_registrant -.->|"registers"| node_subscription_lambda
node_sns -->|"delivers SMS email"| node_recipients

click node_panel_builder "https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/src/build_station_panel.py"
click node_station_panel "https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/station_daily_panel.csv"
click node_weather_fetch "https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/src/fetch_weather.py"
click node_weather_features "https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/weather_features.csv"
click node_trainer "https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/src/train_forecast.py"
click node_model "https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/aersi_forecast_model.pkl"
click node_validation "https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/forecast_validation.csv"
click node_metadata "https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/model_metadata.json"
click node_dispatcher "https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/aws/lambda_function.py"
click node_subscription_lambda "https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/aws/subscribe_lambda.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_snapshots,node_panel_builder,node_station_panel,node_weather_api,node_weather_fetch,node_weather_features toneBlue
class node_trainer,node_model,node_validation,node_metadata toneAmber
class node_eventbridge,node_dispatcher,node_forecasts_db,node_subscribers_db,node_sns,node_recipients toneMint
class node_subscription_lambda toneRose
class node_registrant toneIndigo
```

## Components

### Data preparation

- **AQI snapshots**
- [Build AQI panel](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/src/build_station_panel.py): `src/build_station_panel.py`
- [Station-day panel](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/station_daily_panel.csv): `data/processed/station_daily_panel.csv`
- **Open-Meteo ERA5**
- [Fetch weather](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/src/fetch_weather.py): `src/fetch_weather.py`
- [Weather features](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/weather_features.csv): `data/processed/weather_features.csv`

### Forecast modeling

- [Train and validate](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/src/train_forecast.py): `src/train_forecast.py`
- [XGBoost model](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/aersi_forecast_model.pkl): `data/processed/aersi_forecast_model.pkl`
- [Validation forecasts](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/forecast_validation.csv): `data/processed/forecast_validation.csv`
- [Model metadata](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/data/processed/model_metadata.json): `data/processed/model_metadata.json`

### Alert delivery

- **Daily schedule**
- [Alert dispatcher](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/aws/lambda_function.py): `aws/lambda_function.py`
- **Forecast registry**
- **Subscriber registry**
- **Amazon SNS**
- **SMS and email recipients**

### Subscriber registration

- [Register subscriber](https://github.com/dhruva-0206/aersi-forecast-alerts/blob/main/aws/subscribe_lambda.py): `aws/subscribe_lambda.py`

### Other components

- **Subscriber**

## Connections

- AQI snapshots → Build AQI panel: reads snapshots (evidence: `README.md`)
- Build AQI panel → Station-day panel: writes panel (evidence: `src/build_station_panel.py`)
- Station-day panel → Fetch weather: provides stations (evidence: `src/fetch_weather.py`)
- Fetch weather → Open-Meteo ERA5: fetches weather (evidence: `src/fetch_weather.py`)
- Fetch weather → Weather features: writes features (evidence: `src/fetch_weather.py`)
- Station-day panel → Train and validate: loads panel (evidence: `src/train_forecast.py`)
- Weather features → Train and validate: loads features (evidence: `src/train_forecast.py`)
- Train and validate → XGBoost model: saves model (evidence: `src/train_forecast.py`)
- Train and validate → Validation forecasts: writes predictions (evidence: `src/train_forecast.py`)
- Train and validate → Model metadata: writes metrics (evidence: `src/train_forecast.py`)
- Daily schedule → Alert dispatcher: triggers daily (evidence: `README.md`)
- Alert dispatcher → Forecast registry: queries forecasts (evidence: `aws/lambda_function.py`)
- Alert dispatcher → Subscriber registry: scans subscribers (evidence: `aws/lambda_function.py`)
- Alert dispatcher → Amazon SNS: publishes alerts (evidence: `aws/lambda_function.py`)
- Register subscriber → Amazon SNS: subscribes contact (evidence: `aws/subscribe_lambda.py`)
- Register subscriber → Subscriber registry: stores subscriber (evidence: `aws/subscribe_lambda.py`)
- Subscriber → Register subscriber: registers
- Amazon SNS → SMS and email recipients: delivers SMS email (evidence: `README.md`)
