# sant-0/retail-forecasting-system-with-gmail-automation architecture

> Architecture diagram of the GitHub repository sant-0/retail-forecasting-system-with-gmail-automation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sant-0/retail-forecasting-system-with-gmail-automation
- Repository: https://github.com/sant-0/retail-forecasting-system-with-gmail-automation

## Overview

#### Purpose and Entry Points
This is a Python retail-sales forecasting suite: it trains or loads category-specific forecasting models, produces predictions/metrics/visualizations, and exposes forecasts through an automated n8n/email workflow. Primary local entry points are `main.py` (CLI forecasting) and `app.py` (interactive application). `diagnose.py` is the operational diagnostic entry point.

Paths: `main.py`, `app.py`, `diagnose.py`

#### Data Generation and Dataset Boundary
The dataset package owns creation/loading of retail-category time-series data. Dataset generation is separate from forecasting execution, allowing models and command/API callers to consume prepared category data rather than raw external feeds.

Paths: `datasets/__init__.py`, `datasets/generate_datasets.py`

#### Forecasting Model Layer
`models/forecasters.py` is the central ML abstraction boundary. It provides individual forecasting implementations (including boosting and regression families) plus weighted ensemble behavior. Callers select a model/category, fit against dataset data, then request a forecast horizon; they should not couple to individual library APIs.

Paths: `models/forecasters.py`, `models/__init__.py`

#### Persisted Model Artifacts
Pretrained serialized models are checked into `models/saved`, enabling prediction-oriented workflows without necessarily retraining. Artifacts are category/model-specific, so artifact naming is the practical resolution contract between category/model selection and loading.

Paths: `models/saved/electronics_gadgets_Linear_Regression.pkl`, `models/saved/luxury_brand_LightGBM.pkl`, `models/saved/pharmacy_daily_Gradient_Boosting.pkl`

#### Analysis and Presentation Support
The utility layer supports post-forecast interpretation and presentation: helpers provide shared transformations, insights derives analytical summaries, and visualization renders forecast/trend outputs. This layer should consume model/data outputs rather than implement model selection or persistence.

Paths: `utils/helpers.py`, `utils/insights.py`, `utils/visualise.py`

#### Automation and Service Boundary
A separately deployable forecast API is packaged for Docker and is orchestrated alongside n8n through Compose. The n8n workflow invokes forecasting and sends Gmail-based reports/notifications on a schedule. This is the primary production integration boundary; credentials and output settings come from environment configuration rather than source code.

Paths: `n8n_automation/api/forecast_api.py`, `n8n_automation/api/Dockerfile`, `n8n_automation/docker-compose.yml`, `n8n_automation/n8n_workflows/gmail_forecast_workflow.json`

#### Runtime and External Dependencies
The core runtime is Python 3.8+ with pandas/numpy and scikit-learn-style modeling, plus CatBoost and XGBoost. CatBoost emits local training diagnostics under `catboost_info`. Deployment automation requires Docker/Compose, n8n, and Gmail credentials; the API is intended to serve forecast, metrics, and model-discovery requests.

Paths: `requirements.txt`, `catboost_info/catboost_training.json`, `.env.example`

Main entry points: [`models/forecasters.py`](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/forecasters.py) (Forecaster abstraction), [`datasets/__init__.py`](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/datasets/__init__.py) (Dataset boundary), [`n8n_automation/api/forecast_api.py`](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/n8n_automation/api/forecast_api.py) (Forecast API), [`n8n_automation/n8n_workflows/gmail_forecast_workflow.json`](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/n8n_automation/n8n_workflows/gmail_forecast_workflow.json) (Scheduled email workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_local["Local forecasting"]
  node_cli["Forecast CLI<br/>Python entry point<br/>[main.py]"]
  node_interactive_app["Interactive app<br/>Python entry point<br/>[app.py]"]
  node_diagnostics["Operational diagnostics<br/>Python entry point<br/>[diagnose.py]"]
end

subgraph group_ml["Data and models"]
  node_dataset_package["Dataset boundary<br/>Python package<br/>[__init__.py]"]
  node_dataset_generator["Dataset generator<br/>data pipeline"]
  node_forecaster_api["Forecaster abstraction<br/>ML model layer<br/>[forecasters.py]"]
  node_model_package["Model exports<br/>Python package<br/>[__init__.py]"]
  node_forecast_implementations{{"Forecast implementations<br/>boosting and regression<br/>[forecasters.py]"}}
  node_weighted_ensemble{{"Weighted ensemble<br/>forecast combiner<br/>[forecasters.py]"}}
  node_saved_models[("Saved model artifacts<br/>serialized model")]
end

subgraph group_analysis["Analysis output"]
  node_helpers["Shared helpers<br/>utility layer<br/>[helpers.py]"]
  node_insights["Forecast insights<br/>analysis layer<br/>[insights.py]"]
  node_visualization["Forecast visualization<br/>presentation layer<br/>[visualise.py]"]
end

subgraph group_automation["Production automation"]
  node_forecast_api["Forecast API<br/>containerized service<br/>[forecast_api.py]"]
  node_compose["Compose orchestration<br/>deployment configuration<br/>[docker-compose.yml]"]
  node_n8n_workflow["Scheduled email workflow<br/>n8n workflow"]
  node_gmail(("Gmail<br/>external email service"))
  node_environment["Environment credentials<br/>runtime configuration<br/>[.env.example]"]
end

node_dataset_generator -->|"creates category data"| node_dataset_package
node_cli -->|"loads data"| node_dataset_package
node_interactive_app -->|"loads data"| node_dataset_package
node_diagnostics -->|"inspects forecasting"| node_forecaster_api
node_dataset_package -->|"prepared time series"| node_forecaster_api
node_model_package -->|"exports"| node_forecaster_api
node_forecaster_api -->|"delegates fitting"| node_forecast_implementations
node_forecaster_api -->|"supports"| node_weighted_ensemble
node_saved_models -->|"loads by category/model"| node_forecaster_api
node_cli -->|"trains or forecasts"| node_forecaster_api
node_interactive_app -->|"trains or forecasts"| node_forecaster_api
node_forecaster_api -->|"model outputs"| node_helpers
node_helpers -->|"transforms"| node_insights
node_forecaster_api -->|"forecast results"| node_visualization
node_helpers -->|"prepared outputs"| node_visualization
node_compose -->|"deploys"| node_forecast_api
node_compose -->|"orchestrates"| node_n8n_workflow
node_n8n_workflow -->|"requests forecast"| node_forecast_api
node_forecast_api -->|"serves via"| node_forecaster_api
node_forecast_api -->|"loads data"| node_dataset_package
node_n8n_workflow -->|"sends reports"| node_gmail
node_environment -.->|"configures"| node_compose
node_environment -.->|"provides Gmail credentials"| node_n8n_workflow

click node_cli "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/main.py"
click node_interactive_app "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/app.py"
click node_diagnostics "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/diagnose.py"
click node_dataset_package "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/datasets/__init__.py"
click node_dataset_generator "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/datasets/generate_datasets.py"
click node_forecaster_api "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/forecasters.py"
click node_model_package "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/__init__.py"
click node_forecast_implementations "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/forecasters.py"
click node_weighted_ensemble "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/forecasters.py"
click node_saved_models "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/saved/electronics_gadgets_Linear_Regression.pkl"
click node_helpers "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/utils/helpers.py"
click node_insights "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/utils/insights.py"
click node_visualization "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/utils/visualise.py"
click node_forecast_api "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/n8n_automation/api/forecast_api.py"
click node_compose "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/n8n_automation/docker-compose.yml"
click node_n8n_workflow "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/n8n_automation/n8n_workflows/gmail_forecast_workflow.json"
click node_environment "https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/.env.example"

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_cli,node_interactive_app,node_diagnostics toneBlue
class node_dataset_package,node_dataset_generator,node_forecaster_api,node_model_package,node_forecast_implementations,node_weighted_ensemble,node_saved_models toneAmber
class node_helpers,node_insights,node_visualization toneMint
class node_forecast_api,node_compose,node_n8n_workflow,node_gmail,node_environment toneRose
```

## Components

### Local forecasting

- [Forecast CLI](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/main.py): Python entry point · `main.py`
- [Interactive app](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/app.py): Python entry point · `app.py`
- [Operational diagnostics](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/diagnose.py): Python entry point · `diagnose.py`

### Data and models

- [Dataset boundary](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/datasets/__init__.py): Python package · Creates and loads prepared category time series. · `datasets/__init__.py`
- [Dataset generator](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/datasets/generate_datasets.py): data pipeline · `datasets/generate_datasets.py`
- [Forecaster abstraction](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/forecasters.py): ML model layer · Selects, fits, and forecasts by model and category. · `models/forecasters.py`
- [Model exports](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/__init__.py): Python package · `models/__init__.py`
- [Forecast implementations](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/forecasters.py): boosting and regression · Individual model families are hidden behind the forecaster API. · `models/forecasters.py`
- [Weighted ensemble](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/forecasters.py): forecast combiner · `models/forecasters.py`
- [Saved model artifacts](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/models/saved/electronics_gadgets_Linear_Regression.pkl): serialized model · Category/model-specific pretrained artifacts support prediction without retraining. · `models/saved/electronics_gadgets_Linear_Regression.pkl`

### Analysis output

- [Shared helpers](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/utils/helpers.py): utility layer · `utils/helpers.py`
- [Forecast insights](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/utils/insights.py): analysis layer · `utils/insights.py`
- [Forecast visualization](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/utils/visualise.py): presentation layer · `utils/visualise.py`

### Production automation

- [Forecast API](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/n8n_automation/api/forecast_api.py): containerized service · Serves forecasts, metrics, and model discovery. · `n8n_automation/api/forecast_api.py`
- [Compose orchestration](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/n8n_automation/docker-compose.yml): deployment configuration · `n8n_automation/docker-compose.yml`
- [Scheduled email workflow](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/n8n_automation/n8n_workflows/gmail_forecast_workflow.json): n8n workflow · Requests forecasts and sends Gmail reports. · `n8n_automation/n8n_workflows/gmail_forecast_workflow.json`
- **Gmail**: external email service
- [Environment credentials](https://github.com/sant-0/retail-forecasting-system-with-gmail-automation/blob/main/.env.example): runtime configuration · Supplies automation credentials and output settings. · `.env.example`

## Connections

- Dataset generator → Dataset boundary: creates category data
- Forecast CLI → Dataset boundary: loads data
- Interactive app → Dataset boundary: loads data
- Operational diagnostics → Forecaster abstraction: inspects forecasting
- Dataset boundary → Forecaster abstraction: prepared time series
- Model exports → Forecaster abstraction: exports
- Forecaster abstraction → Forecast implementations: delegates fitting
- Forecaster abstraction → Weighted ensemble: supports
- Saved model artifacts → Forecaster abstraction: loads by category/model
- Forecast CLI → Forecaster abstraction: trains or forecasts
- Interactive app → Forecaster abstraction: trains or forecasts
- Forecaster abstraction → Shared helpers: model outputs
- Shared helpers → Forecast insights: transforms
- Forecaster abstraction → Forecast visualization: forecast results
- Shared helpers → Forecast visualization: prepared outputs
- Compose orchestration → Forecast API: deploys
- Compose orchestration → Scheduled email workflow: orchestrates
- Scheduled email workflow → Forecast API: requests forecast
- Forecast API → Forecaster abstraction: serves via
- Forecast API → Dataset boundary: loads data
- Scheduled email workflow → Gmail: sends reports
- Environment credentials → Compose orchestration: configures
- Environment credentials → Scheduled email workflow: provides Gmail credentials
