InsightRetail is a university portfolio project for retail sales forecasting and analytics. It combines data cleaning, customer segmentation, model training, a PostgreSQL analytics pipeline, a FastAPI backend, and a Streamlit dashboard.
- Retail data cleaning and validation
- Customer segmentation and revenue analysis
- Forecasting with trained regression and time-series models
- PostgreSQL-backed analytics queries
- FastAPI backend with sales, products, customers, segments, forecast, and prediction endpoints
- Streamlit dashboard for interactive visualization
The project uses retail transaction data stored in data/raw/ and processed into data/processed/. The data format follows an Online Retail-style dataset with invoices, customers, products, and sales amounts.
flowchart LR
A[User / Analyst] -->|browser| B[Streamlit dashboard]
A -->|HTTP| C[FastAPI backend]
C -->|SQL| D[PostgreSQL database]
C -->|model file| E[Trained forecast model]
B -->|local data| F[Processed CSV files]
B -->|optionally| C
D ---|data ingestion| F
api/— FastAPI backend and route definitionsdashboard/— Streamlit dashboard appdata/— raw and processed datasetsmodels/— trained model artifacts and metricssql/— database schema and analytics queriessrc/— data cleaning, training, forecasting, and loading scriptstests/— pytest coverage for project componentsREADME.md— project documentation
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtpython -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt- Copy
.env.exampleto.env. - Edit
.envand set yourDATABASE_URL. - Run the database loader:
python src/load_database.pyDATABASE_URL=postgresql+psycopg2://user:password@localhost:5432/insightretailTrain or retrain the forecasting model with:
python src/train.pyRun the API locally with:
uvicorn api.main:app --reloadThen visit:
http://127.0.0.1:8000/healthhttp://127.0.0.1:8000/docs
Run the dashboard locally with:
streamlit run dashboard/app.pyBuild and start all services with:
docker compose up --buildOr on older systems:
docker-compose up --buildThe project reports model metrics such as MAE, RMSE, and MAPE. Metrics are saved to models/model_metrics.json after training.
Add project screenshots here once the dashboard and results are generated.
- The dashboard depends on local processed CSV files.
- The API assumes PostgreSQL data has already been loaded.
- The forecasting model may require retraining for new datasets.
- Add authentication for API access
- Enable dynamic model retraining from the dashboard
- Add more production-ready logging and monitoring
- Expand the dataset ingestion pipeline for new retail sources
This project includes a simple backend API under api/ for summary, sales, product, customer, segment, forecast, and prediction endpoints.
From the repository root:
uvicorn api.main:app --reloadGET /healthGET /summaryGET /sales/dailyGET /products/topGET /customers/topGET /segmentsGET /forecastPOST /predict
Create a .env file from .env.example and set the PostgreSQL DATABASE_URL.
Example:
DATABASE_URL=postgresql://user:password@localhost:5432/insightretailRun the FastAPI tests with:
pytest tests/test_api.py -qRun the dashboard locally with:
streamlit run dashboard/app.py- Ensure your repository contains
dashboard/app.py,.streamlit/config.toml, andrequirements.txt. - Deploy the repository to Streamlit Cloud.
- In Streamlit Cloud app settings, set environment variables as needed.
If you need a public dashboard demo, Streamlit Cloud is a good fit for this project because it can host the dashboard directly from the repo.