How sant-0/retail-forecasting-system-with-gmail-automation works
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: forecasters.py Forecaster abstraction · __init__.py Dataset boundary · forecast_api.py Forecast API · gmail_forecast_workflow.json Scheduled email workflow
Components 18
Local forecasting
- Forecast CLI
main.py - Interactive app
app.py - Operational diagnostics
diagnose.py
Data and models
- Dataset boundary · Creates and loads prepared category time series.
datasets/__init__.py - Dataset generator
datasets/generate_datasets.py - Forecaster abstraction · Selects, fits, and forecasts by model and category.
models/forecasters.py - Model exports
models/__init__.py - Forecast implementations · Individual model families are hidden behind the forecaster API.
models/forecasters.py - Weighted ensemble
models/forecasters.py - Saved model artifacts · Category/model-specific pretrained artifacts support prediction without retraining.
models/saved/electronics_gadgets_Linear_Regression.pkl
Analysis output
- Shared helpers
utils/helpers.py - Forecast insights
utils/insights.py - Forecast visualization
utils/visualise.py
Production automation
- Forecast API · Serves forecasts, metrics, and model discovery.
n8n_automation/api/forecast_api.py - Compose orchestration
n8n_automation/docker-compose.yml - Scheduled email workflow · Requests forecasts and sends Gmail reports.
n8n_automation/n8n_workflows/gmail_forecast_workflow.json - Gmail
- Environment credentials · Supplies automation credentials and output settings.
.env.example
Connections 23
- 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