A full-stack demand forecasting app that allows users to:
- Upload sales data (CSV/XLSX)
- Map and validate fields
- Save cleaned data to a database
- Generate and view forecasts per SKU
- Visualize predictions on interactive charts
- Manage users and configurations (admin only)
Built with:
- Frontend: React + TypeScript + MUI + Vite
- Backend: Node.js + Express + Prisma + PostgreSQL
- Auth: JWT-based login/logout with refresh tokens
- Deployment: Docker + Railway
- CI/CD: Manual builds via Railway
- Register/Login with JWT-based auth
- Upload & preview sales files
- Map columns to required fields
- Validate and clean data row-by-row
- Save to database only when valid
- Generate forecasts for:
- All SKUs
- A specific SKU (on-demand)
- View forecasts:
- Tabular format
- Filter by SKU, data quality, pagination
- Interactive chart per SKU
- View all users
- Delete non-admin users
- View user roles
- Future: manage user-specific configurations
- Node.js v20+
- Docker & Docker Compose
- Railway account (for deployment)
git clone https://github.com/sahinmeric/demand-forecast.git
cd demand-forecastCreate backend/.env.dev and frontend/.env.dev based on .env.example. Example backend env:
PORT=3000
DATABASE_URL=postgres://forecast_user:forecast_pass@postgres:5432/forecastdb
ACCESS_TOKEN_SECRET=your-secret
REFRESH_TOKEN_SECRET=your-refresh-secret
ACCESS_TOKEN_EXPIRES_IN=8h
REFRESH_TOKEN_EXPIRES_IN=7d
Frontend:
VITE_API_URL=http://localhost:3000
docker compose -f docker-compose.dev.yml up --buildUse the seeded admin:
Email: [email protected]
Password: password123This app is fully containerized.
-
Create 3 services on Railway:
- PostgreSQL
- Backend
- Frontend
-
Use
docker-compose.prod.ymlandDockerfilefor backend + frontend builds. -
Set environment variables:
VITE_API_URL=https://your-backend-service-name.up.railway.app(frontend)- Database credentials (backend)
-
Railway automatically builds & deploys on push.
βββ backend
β βββ src/
β βββ prisma/
β βββ Dockerfile
β βββ .env.dev
βββ frontend
β βββ src/
β βββ Dockerfile
β βββ nginx.conf
β βββ .env.dev
βββ docker-compose.dev.yml
βββ docker-compose.prod.yml
βββ README.md
- Server-side pagination and filters
- Per-user configuration controls
- ML-based forecast model swapping
- Scheduled re-training of forecasts
- Notification settings (alerts, warnings)
The frontend is a well-structured, modular React + TypeScript application built with Vite and Material UI (MUI). It prioritizes type safety, code reuse, responsive design, and maintainability.
frontend/
βββ src/
β βββ components/ # Reusable UI components (Loader, Snackbar, ConfirmDialog, etc.)
β βββ hooks/ # Custom hooks (useLogin, useForecasts, useSaveCleanData, etc.)
β βββ pages/ # Top-level route views (Login, UploadPage, ForecastPage, AdminPage)
β βββ utils/ # Validation, filtering, formatting utilities
β βββ context/ # Global providers (SnackbarContext, ConfirmDialogContext)
β βββ types/ # Centralized TypeScript interfaces
β βββ auth.ts # Auth helpers (token management, role checks)
β βββ App.tsx # Main router and layout
β βββ main.tsx # App bootstrap
Encapsulate API logic (auth, forecasting, saving data) to keep components clean.
- SnackbarContext: Feedback system for success/error messages.
- ConfirmDialogContext: Replaces
window.confirmwith MUI-based modal.
All shared data models are fully typed, enabling better dev experience and avoiding runtime issues.
Built using Material UIβs grid system and Box, all views adapt to mobile and desktop.
With Vite pages can be dynamically loaded to reduce bundle size.
The backend is a Node.js + Express API using Prisma ORM and JWT-based authentication. It connects to a PostgreSQL database and exposes RESTful endpoints for auth, file uploads, forecasting, and admin features.
backend/
βββ prisma/ # Prisma schema and migration config
β βββ seed.js # Seed script for admin user, config, and test data
βββ src/
β βββ controllers/ # Route logic: auth, forecast, upload, user
β βββ middleware/ # Auth & role-check middlewares
β βββ routes/ # Route definitions (auth, forecast, admin, upload)
β βββ services/ # Forecasting and token utilities
β βββ utils/ # CSV parsing, validation helpers (if added)
β βββ index.js # Express app bootstrap
- JWT access and refresh token system
- Role-based route protection via
authMiddlewareandisAdmin - Secrets and expiration via
.env
- Sales data processed by statistical model
- Forecasts saved with base, upper, lower bounds
- Confidence intervals and quality scores computed
- User uploads CSV/XLSX β preview β map fields β validate β save
- Async validation with inline editing before DB save
seed.jsinserts admin + demo data- Prisma handles schema migration
- Docker-based local dev and production configs available
MIT β use freely with attribution