This microservice forecasts product demand using pre-trained ML models and integrates with a warehouse service to determine restocking needs.
| Folder/File | Purpose |
|---|---|
forecast_system/ |
Main Django project config (settings, URLs, wsgi/asgi) |
forecaster/ |
App containing all forecast logic |
feature_pipelines/ |
Per-product feature engineering modules |
models/ |
Pre-trained .joblib models for each product |
utils/warehouse_api.py |
Makes HTTP requests to warehouse management service |
forecast_runner.py |
Orchestrates model loading, forecasting, warehouse fetch |
views.py |
Exposes the forecast API endpoint |
migrations/ |
Django migration folder |
manage.py |
Django project entry point |
git clone https://github.com/IASSCMS/Forecasting-Service.git
cd forecast_systempython -m venv venv
source venv/bin/activate # Linux/macOS
# or
. venv\Scripts\activate # Windows in GitBashpip install -r requirements.txtpython manage.py migrate
python manage.py runserver- Or use Make commands in the root dir
make run- for migrations
make migrate- Now can find the root view at http://localhost:8000/api/
POST /api/forecast/
{
"product_SKU": "SKU001",
"days" : 30
}{
"product_SKU": "SKU001",
"current_stock": 10000,
"average_forecasted_demand": 14608.27,
"maximum_forecast": 16425.71,
"minimum_forecast": 12764.46,
"stock_shortfall": 4608.27,
"daily_predictions": [
{
"date": "2025-05-03",
"predicted": 593.5,
"lower_bound": 530.5,
"upper_bound": 651.77
},
{
"date": "2025-05-04",
"predicted": 635.67,
"lower_bound": 575.94,
"upper_bound": 697.32
},
...
]
}- Django – Backend web framework
- Prophet – Time series forecasting
- Pandas – Data manipulation
- Joblib – Model serialization
- Requests – HTTP requests to warehouse service
The service calls the external warehouse API:
GET http://warehouse-service/api/stock/<product_SKU>/
→ Expected response: { "current_stock": 120 }You can change the warehouse base URL in forecaster/utils/warehouse_api.py.
To support a new product:
- Save its trained model as
forecaster/models/<product>.joblib - Add a feature engineering file:
forecaster/feature_pipelines/<product>.pywith a function:
def prepare_features(df):
# Add custom columns to df
return df