# asif3359/dengu_out_break_final_capstone architecture

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

- Interactive diagram: https://gitdiagram.com/asif3359/dengu_out_break_final_capstone
- Repository: https://github.com/asif3359/dengu_out_break_final_capstone

## Overview

#### Purpose and Entry Points
This repository is an end-to-end dengue outbreak risk prediction system for WHO SEARO countries. It supports offline data/model workflows, a Python REST inference service, and an interactive dashboard.

Primary entry points:
- Data preparation: `data_preprocessing.py`
- Classical model training/selection: `train.py`
- Experimental sequence-model training: `train_lstm.py`
- CLI inference: `predict.py`
- API application: `backend/app/main.py`
- Dashboard route: `dashboard/src/app/page.tsx`

#### Data Acquisition and Feature Pipeline
The training pipeline combines OpenDengue surveillance CSV data with NASA POWER weather observations. Country/year weather responses are persisted as Parquet cache files, avoiding repeated external API retrieval. Preprocessing produces the merged, feature-engineered training dataset, including temporal lags, rolling statistics, and cyclical fields.

Key boundaries:
- Source and generated datasets: `data/filtered_data_SEARO_1769008875181.csv`, `data/merged_data.csv`
- Cached meteorology: `data/weather_cache/IND_1981_2025.parquet`
- Pipeline implementation and training settings: `data_preprocessing.py`, `config.py`

#### Model Training and Artifact Contract
`train.py` evaluates classical classifiers and selects a serialized production model, described as XGBoost. It accounts for imbalance and tunes the decision threshold. `train_lstm.py` produces LSTM and Transformer artifacts as experimental alternatives; the API’s artifact contract is centered on the joblib model path.

Inference depends on a version-coupled artifact set:
- Classifier and preprocessing: `models/model.joblib`, `models/scaler.joblib`, `models/encoder.joblib`
- Feature ordering and serving metadata: `models/feature_names.json`, `models/metadata.json`
- Experimental deep-learning outputs: `models/lstm_model.keras`, `models/transformer_model.keras`

#### FastAPI Inference Service
The backend is a modular FastAPI application. `backend/app/main.py` initializes the application, versioned API routing, CORS, and service lifecycle. Request schemas constrain prediction payloads, while the predictor service loads artifacts, aligns/scales feature vectors, calculates probability, and applies the configured or metadata threshold.

Core service stages:
- Settings and shared dependencies: `backend/app/core/config.py`, `backend/app/core/dependencies.py`
- Request/response models: `backend/app/models/schemas.py`
- Artifact-backed inference: `backend/app/services/predictor.py`
- Public endpoints: `backend/app/api/v1/endpoints/predict.py`, `backend/app/api/v1/endpoints/features.py`, `backend/app/api/v1/endpoints/health.py`

The API exposes health status, required feature names, single prediction, and batch prediction. It is the authoritative boundary between browser clients and Python/ML artifacts.

#### Dashboard Client
The dashboard is a Next.js App Router application that gathers feature inputs, invokes the backend using `NEXT_PUBLIC_API_URL`, and renders results and interpretability-oriented visualizations. It does not host model logic; browser-to-API calls are its key runtime boundary.

Main client flow:
- Page composition: `dashboard/src/app/page.tsx`, `dashboard/src/app/layout.tsx`
- Form and result presentation: `dashboard/src/components/PredictionForm.tsx`, `dashboard/src/components/ResultsDisplay.tsx`
- Prediction state/API transport: `dashboard/src/hooks/usePrediction.ts`, `dashboard/src/services/api.ts`
- Supporting risk/history views: `dashboard/src/components/FeatureImportance.tsx`, `dashboard/src/components/HistoryChart.tsx`

#### Runtime and Deployment Boundaries
The backend targets Python 3.11+, FastAPI/Pydantic/Uvicorn, and XGBoost/scikit-learn artifacts. It is containerized independently; `backend/docker-compose.yml` and `backend/Dockerfile` define API deployment, including access to the repository-level `models/` directory. Dashboard deployment is a separate Node.js/Next.js runtime.

External dependencies are limited to historical OpenDengue data and NASA POWER meteorological data during pipeline construction. Serving is artifact-local and should not require those external services. Backend configuration—including model locations, threshold fallback, and CORS origins—is centralized in `backend/app/core/config.py` and exposed through `backend/.env.example`.

Main entry points: [`data_preprocessing.py`](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/data_preprocessing.py) (Feature pipeline), [`backend/app/api/v1/endpoints/predict.py`](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/api/v1/endpoints/predict.py) (v1 endpoints), [`data/merged_data.csv`](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/data/merged_data.csv) (Training dataset), [`models/model.joblib`](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/models/model.joblib) (Serving artifact bundle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["Data &amp; Training"]
  node_sources[("Surveillance &amp; weather sources<br/>external data")]
  node_preprocessing["Feature pipeline<br/>Python pipeline"]
  node_weather_cache[("Weather cache<br/>Parquet cache")]
  node_merged_data[("Training dataset<br/>CSV dataset<br/>[merged_data.csv]")]
  node_training_config["Training settings<br/>Python config<br/>[config.py]"]
  node_classical_training["Classical model selection<br/>Python training<br/>[train.py]"]
  node_deep_training["Sequence-model experiments<br/>Python training<br/>[train_lstm.py]"]
end

subgraph group_artifacts["Model Artifacts"]
  node_artifact_bundle[("Serving artifact bundle<br/>joblib + JSON<br/>[model.joblib]")]
  node_deep_artifacts[("Experimental deep artifacts<br/>Keras models<br/>[lstm_model.keras]")]
  node_cli_inference["CLI inference<br/>Python CLI<br/>[predict.py]"]
end

subgraph group_api["Inference API"]
  node_api_app["FastAPI application<br/>Python service<br/>[main.py]"]
  node_api_settings["Backend settings<br/>Python config<br/>[config.py]"]
  node_api_schemas["Prediction schemas<br/>Pydantic models<br/>[schemas.py]"]
  node_predictor["Predictor service<br/>Inference service<br/>[predictor.py]"]
  node_api_endpoints["v1 endpoints<br/>FastAPI routes<br/>[predict.py]"]
  node_api_container{{"API container deployment<br/>Docker deployment"}}
end

subgraph group_dashboard["Dashboard"]
  node_dashboard_page["Dashboard page<br/>Next.js route<br/>[page.tsx]"]
  node_prediction_ui["Prediction UI<br/>React components<br/>[PredictionForm.tsx]"]
  node_dashboard_transport["Prediction client<br/>[usePrediction.ts]"]
  node_risk_views["Risk &amp; history views<br/>React components"]
end

node_sources -->|"retrieve input data"| node_preprocessing
node_weather_cache -->|"reuse cached weather"| node_preprocessing
node_preprocessing -->|"persist weather responses"| node_weather_cache
node_preprocessing -->|"write engineered data"| node_merged_data
node_training_config -.->|"pipeline settings"| node_preprocessing
node_merged_data -->|"train and evaluate"| node_classical_training
node_training_config -.->|"training settings"| node_classical_training
node_merged_data -->|"train experiments"| node_deep_training
node_classical_training -->|"serialize selected model"| node_artifact_bundle
node_deep_training -->|"write Keras models"| node_deep_artifacts
node_artifact_bundle -->|"load for local inference"| node_cli_inference
node_api_settings -.->|"configure app"| node_api_app
node_api_app -->|"register v1 routes"| node_api_endpoints
node_api_endpoints -->|"validate payloads"| node_api_schemas
node_api_endpoints -->|"prediction requests"| node_predictor
node_api_settings -.->|"model paths and threshold"| node_predictor
node_artifact_bundle -->|"load artifacts"| node_predictor
node_api_container -->|"run service"| node_api_app
node_dashboard_page -->|"compose"| node_prediction_ui
node_prediction_ui -->|"submit inputs"| node_dashboard_transport
node_dashboard_transport -->|"browser API calls"| node_api_endpoints
node_prediction_ui -->|"render result context"| node_risk_views

click node_preprocessing "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/data_preprocessing.py"
click node_weather_cache "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/data/weather_cache/IND_1981_2025.parquet"
click node_merged_data "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/data/merged_data.csv"
click node_training_config "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/config.py"
click node_classical_training "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/train.py"
click node_deep_training "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/train_lstm.py"
click node_artifact_bundle "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/models/model.joblib"
click node_deep_artifacts "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/models/lstm_model.keras"
click node_cli_inference "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/predict.py"
click node_api_app "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/main.py"
click node_api_settings "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/core/config.py"
click node_api_schemas "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/models/schemas.py"
click node_predictor "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/services/predictor.py"
click node_api_endpoints "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/api/v1/endpoints/predict.py"
click node_api_container "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/Dockerfile"
click node_dashboard_page "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/dashboard/src/app/page.tsx"
click node_prediction_ui "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/dashboard/src/components/PredictionForm.tsx"
click node_dashboard_transport "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/dashboard/src/hooks/usePrediction.ts"
click node_risk_views "https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/dashboard/src/components/FeatureImportance.tsx"

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_sources,node_preprocessing,node_weather_cache,node_merged_data,node_training_config,node_classical_training,node_deep_training toneBlue
class node_artifact_bundle,node_deep_artifacts,node_cli_inference toneAmber
class node_api_app,node_api_settings,node_api_schemas,node_predictor,node_api_endpoints,node_api_container toneMint
class node_dashboard_page,node_prediction_ui,node_dashboard_transport,node_risk_views toneRose
```

## Components

### Data & Training

Offline acquisition, feature engineering, and model selection.

- **Surveillance & weather sources**: external data · OpenDengue CSV data and NASA POWER observations.
- [Feature pipeline](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/data_preprocessing.py): Python pipeline · Merges data and creates lags, rolling, and cyclical features. · `data_preprocessing.py`
- [Weather cache](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/data/weather_cache/IND_1981_2025.parquet): Parquet cache · Avoids repeated NASA POWER retrieval. · `data/weather_cache/IND_1981_2025.parquet`
- [Training dataset](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/data/merged_data.csv): CSV dataset · Merged feature-engineered data. · `data/merged_data.csv`
- [Training settings](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/config.py): Python config · `config.py`
- [Classical model selection](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/train.py): Python training · Evaluates classifiers, handles imbalance, and tunes threshold. · `train.py`
- [Sequence-model experiments](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/train_lstm.py): Python training · Produces LSTM and Transformer alternatives. · `train_lstm.py`

### Model Artifacts

Version-coupled files used by serving.

- [Serving artifact bundle](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/models/model.joblib): joblib + JSON · Classifier, scaler, encoder, feature order, and metadata must remain aligned. · `models/model.joblib`
- [Experimental deep artifacts](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/models/lstm_model.keras): Keras models · `models/lstm_model.keras`
- [CLI inference](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/predict.py): Python CLI · `predict.py`

### Inference API

FastAPI boundary for artifact-backed predictions.

- [FastAPI application](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/main.py): Python service · Initializes lifecycle, CORS, and versioned routing. · `backend/app/main.py`
- [Backend settings](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/core/config.py): Python config · Centralizes artifact locations, threshold fallback, and CORS. · `backend/app/core/config.py`
- [Prediction schemas](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/models/schemas.py): Pydantic models · Constrains request and response payloads. · `backend/app/models/schemas.py`
- [Predictor service](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/services/predictor.py): Inference service · Aligns and scales features, then applies probability threshold. · `backend/app/services/predictor.py`
- [v1 endpoints](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/app/api/v1/endpoints/predict.py): FastAPI routes · Health, required features, single, and batch prediction. · `backend/app/api/v1/endpoints/predict.py`
- [API container deployment](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/backend/Dockerfile): Docker deployment · Mounts or accesses repository model artifacts. · `backend/Dockerfile`

### Dashboard

Separate Next.js browser runtime.

- [Dashboard page](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/dashboard/src/app/page.tsx): Next.js route · Composes the interactive prediction experience. · `dashboard/src/app/page.tsx`
- [Prediction UI](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/dashboard/src/components/PredictionForm.tsx): React components · Collects inputs and renders risk results. · `dashboard/src/components/PredictionForm.tsx`
- [Prediction client](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/dashboard/src/hooks/usePrediction.ts): React hook + API client · Calls the API using NEXT_PUBLIC_API_URL. · `dashboard/src/hooks/usePrediction.ts`
- [Risk & history views](https://github.com/asif3359/dengu_out_break_final_capstone/blob/main/dashboard/src/components/FeatureImportance.tsx): React components · Interpretability-oriented feature and history visualizations. · `dashboard/src/components/FeatureImportance.tsx`

## Connections

- Surveillance & weather sources → Feature pipeline: retrieve input data
- Weather cache → Feature pipeline: reuse cached weather
- Feature pipeline → Weather cache: persist weather responses
- Feature pipeline → Training dataset: write engineered data
- Training settings → Feature pipeline: pipeline settings
- Training dataset → Classical model selection: train and evaluate
- Training settings → Classical model selection: training settings
- Training dataset → Sequence-model experiments: train experiments
- Classical model selection → Serving artifact bundle: serialize selected model
- Sequence-model experiments → Experimental deep artifacts: write Keras models
- Serving artifact bundle → CLI inference: load for local inference
- Backend settings → FastAPI application: configure app
- FastAPI application → v1 endpoints: register v1 routes
- v1 endpoints → Prediction schemas: validate payloads
- v1 endpoints → Predictor service: prediction requests
- Backend settings → Predictor service: model paths and threshold
- Serving artifact bundle → Predictor service: load artifacts
- API container deployment → FastAPI application: run service
- Dashboard page → Prediction UI: compose
- Prediction UI → Prediction client: submit inputs
- Prediction client → v1 endpoints: browser API calls · Health, features, single, and batch prediction.
- Prediction UI → Risk & history views: render result context
