SalesCast
Sales Forecasting & Analytics Platform
Overview
A full-stack sales forecasting and analytics platform with FastAPI backend for ML-powered predictions and Next.js dashboard for interactive visualizations. Ingest transactional data, train models, and deliver actionable insights through a documented REST API.
SalesCast turns historical sales records into actionable insight through ML-powered forecasting. A FastAPI backend trains and serves a persisted model, exposes analytics via REST API with OpenAPI docs, while a Next.js frontend renders interactive Recharts dashboards. Supports data upload, model evaluation, and dual deployment modes.
Key Features
ML Forecasting Engine
Trained model persisted with joblib, automatically retrained on first start, forward-looking sales predictions
Interactive Dashboard
Multi-page Recharts visualizations with light/dark themes and smooth scrolling
Model Evaluation
Month-by-month comparison of actual vs. predicted values with transparency and quality metrics
Data Upload
CSV/Excel support with validation, stored separately from sample data, configurable 350MB upload limit
Self-Bootstrapping
Generated sample dataset bundled, auto-created on first run if missing
Dual Deployment
Hot-reload dev mode or single-process production with FastAPI serving static frontend
Technology Stack
Challenges
Building a unified system that answers 'what happened' (analytics) and 'what will happen' (forecasting)
Training and persisting ML models efficiently on first start without blocking requests
Validating user-uploaded datasets and handling 350MB+ files without memory overflow
Supporting both hot-reload development and single-server production deployment
Ensuring model transparency with month-by-month evaluation views
Solutions
Designed state management that resolves dataset, trains model on first start, and reloads persisted model on restarts
Implemented streaming file upload to temporary storage with pandas validation and configurable size limits
Built multi-stage Docker image: Node.js stage for static frontend, slim Python final stage with no Node runtime
Created Next.js dev proxy for /api/* and static export mode where FastAPI serves frontend from one port
Exposed OpenAPI schema with Swagger UI for always-current, machine-readable API documentation
Used Docker Compose volumes (sf-data, sf-models) to persist uploads and trained models across restarts
Project Architecture
// Project Structure
salescast/ ├── backend/ │ ├── app/ │ │ ├── main.py # FastAPI entry + routes │ │ ├── config.py # Environment config │ │ ├── data.py # Dataset loading & validation │ │ ├── analytics.py # Aggregations & computations │ │ ├── ml.py # Model training & inference │ │ └── state.py # Startup & shared state │ ├── scripts/ │ │ └── generate_sample_data.py # Sample dataset generator │ ├── tests/ │ │ └── test_api.py # pytest API suite │ ├── data/ │ │ └── uploads/ # User-uploaded datasets │ └── models/ # Persisted model (joblib) ├── frontend/ │ ├── src/ │ │ ├── app/ # App Router pages & layout │ │ ├── components/ # Reusable UI components │ │ └── lib/api.ts # Typed API client │ ├── public/ │ ├── next.config.ts # Dev proxy & static export │ └── package.json ├── Dockerfile # Multi-stage build └── docker-compose.yml # Volumes for data & models
Key Learnings
FastAPI application architecture with modular separation (config, data, analytics, ml, state)
Model lifecycle management: train once, persist with joblib, reload on restart, evaluate with actual vs. predicted
Next.js App Router with dual-mode configuration: dev proxy for CORS-free development, static export for production
Multi-stage Docker builds to minimize final image size and exclude build-time dependencies
pandas data validation patterns for user-uploaded CSV/Excel with descriptive error messages
pytest API testing with test clients and fixture-based setup
Environment-driven configuration with sensible defaults for local development and production overrides
Future Enhancements
Real-time streaming updates via WebSocket, advanced time-series models (LSTM, Prophet), multi-tenant authentication, Prometheus metrics export, Kubernetes deployment, and interactive scenario planning.
