SpareAI is a predictive inventory dashboard for spare-parts management. The repository contains:
- A Java servlet backend packaged as a WAR for Apache Tomcat 10
- A Python Flask microservice that runs Facebook Prophet forecasts
- MySQL schema and sample data
- Prophet training datasets and product documentation
The web UI is served from Tomcat. Forecast requests go from the Java API to the Flask service on port 5001.
Dashboard features: Overview KPIs, charts, inventory table, critical stock, demand forecast, and Stock Parameters (per-material reorder levels and alert thresholds with Excel-based and consumption-based preset defaults).
Install these tools on Windows before you run the project. Use Command Prompt (cmd.exe) for the commands in this guide unless a step says otherwise.
| Software | Version used in this project | Why you need it |
|---|---|---|
| Java JDK | 24 | Compiles and runs the servlet backend |
| Apache Maven | 3.9+ | Builds spareai.war |
| Apache Tomcat | 10.1.x | Hosts the Java web application |
| MySQL Server | 8.0+ | Stores inventory, consumption, and forecast cache data |
| Python | 3.11 recommended | Runs the Flask forecast service |
| Git | Latest stable | Clones and updates this repository |
Optional but useful:
- MySQL Workbench for database setup and inspection
- A browser for the dashboard and API checks
- Open Oracle JDK downloads or Adoptium Temurin.
- Download the Windows x64 JDK 24 installer.
- Run the installer and keep the default install path unless you have a reason to change it.
- Open a new Command Prompt window and verify the install:
java -version
javac -versionYou should see Java 24 in the output.
- Open the Apache Maven download page.
- Download the binary zip archive, for example
apache-maven-3.9.15-bin.zip. - Extract it to a folder such as
D:\maven\apache-maven-3.9.15. - Add Maven to your user
PATH:- Open Settings -> System -> About -> Advanced system settings -> Environment Variables.
- Under User variables, edit
Path. - Add the
binfolder, for exampleD:\maven\apache-maven-3.9.15\bin.
- Open a new Command Prompt window and verify:
mvn -version- Open the Apache Tomcat 10 download page.
- Download the Windows zip distribution for Tomcat 10.1.
- Extract it to a folder such as
C:\apache-tomcat-10.1.44. - Optional: add
C:\apache-tomcat-10.1.44\binto your userPATHso you can runcatalina.batfrom any folder. - Verify Tomcat starts:
cd /d C:\apache-tomcat-10.1.44\bin
startup.bat- Open
http://localhost:8080in your browser. Stop Tomcat when you are done testing:
cd /d C:\apache-tomcat-10.1.44\bin
shutdown.batTomcat 10 is required because the backend uses Jakarta Servlet 6.
- Open the MySQL Community downloads page.
- Download MySQL Installer for Windows.
- Run the installer and choose Server only or Developer Default.
- Set a root password during setup and remember it.
- Keep the default port
3306unless another service already uses it. - Verify MySQL is running:
mysql --versionIf mysql is not recognized, add the MySQL bin folder to your PATH or use MySQL Workbench for the database steps below.
- Open the Python downloads page.
- Download Python 3.11.x for Windows.
- Run the installer.
- Check Add python.exe to PATH.
- Verify in a new Command Prompt window:
python --version
pip --versionProphet installs more easily on Python 3.11 than on newer Python releases.
Clone the repository, then move into the project folder:
git clone https://github.com/<your-github-username>/SpareAI.git
cd SpareAIIf you already have the source locally, cd into the repository root instead.
Using the MySQL command line client:
mysql -u root -pRun:
CREATE DATABASE spareai CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
USE spareai;
SOURCE spareai/db/schema.sql;Optional sample data:
SOURCE spareai/spareai_real_data.sql;Existing databases (created before Stock Parameters): apply the column migration once:
SOURCE spareai/db/add-material-parameters.sql;Or from Command Prompt:
cd spareai\db
apply-material-parameters.batYou can run the same SQL files from MySQL Workbench if you prefer a GUI.
The backend reads settings from environment variables first, then Java system properties.
In Command Prompt, set these before you start Tomcat:
set SPAREAI_DB_URL=jdbc:mysql://localhost:3306/spareai?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
set SPAREAI_DB_USER=root
set SPAREAI_DB_PASSWORD=YOUR_MYSQL_PASSWORD
set SPAREAI_DB_POOL_SIZE=10
set SPAREAI_FLASK_URL=http://localhost:5001Replace YOUR_MYSQL_PASSWORD with the password you chose during MySQL installation.
Open a first Command Prompt window for the Python service.
cd spareai\flask-service
python -m venv .venv
.venv\Scripts\activate.bat
python -m pip install --upgrade pip
pip install -r requirements.txt
python app.pyThe first Prophet install can take several minutes because it downloads scientific dependencies.
When the service is ready, you should see Flask listening on port 5001.
Health check:
curl http://localhost:5001/healthLeave this Command Prompt window open while you use the application.
Copy spareai\set-local.bat.example to spareai\set-local.bat and set your Tomcat path (CATALINA_HOME) if it differs from the default.
From the repository root, spareai\startup.bat does the following in order:
- Start MySQL (
MySQL80service) - Build
spareai.warwith Maven - Remove the old exploded app and copy the new WAR to Tomcat
webapps\ - Start Tomcat
- Start the Flask forecast service
cd spareai
startup.batTo rebuild and redeploy only (Tomcat already configured):
cd spareai
redeploy.batSet backend environment variables before starting Tomcat if you are not using defaults (same session as Tomcat, or system-wide):
set SPAREAI_DB_URL=jdbc:mysql://localhost:3306/spareai?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
set SPAREAI_DB_USER=root
set SPAREAI_DB_PASSWORD=YOUR_MYSQL_PASSWORD
set SPAREAI_FLASK_URL=http://localhost:5001cd spareai
mvn clean package
copy /Y target\spareai.war C:\apache-tomcat-10.1.44\webapps\
rmdir /S /Q C:\apache-tomcat-10.1.44\webapps\spareai
cd /d C:\apache-tomcat-10.1.44\bin
startup.batAfter a successful build, the WAR file is at spareai\target\spareai.war.
Use these URLs after both services are running:
| Service | URL |
|---|---|
| Dashboard | http://localhost:8080/spareai/ui/dashboard.jsp |
| API base | http://localhost:8080/spareai/api |
| Stock parameters API | http://localhost:8080/spareai/api/parameters/list |
| Flask health | http://localhost:5001/health |
Example API checks:
curl http://localhost:8080/spareai/api/inventory/list
curl http://localhost:8080/spareai/api/parameters/list
curl http://localhost:8080/spareai/api/charts/stock-levels- Apply
db/schema.sqland (if needed)db/add-material-parameters.sql. - Run
spareai\startup.bator start MySQL, Flask, Maven build, deploy WAR, and Tomcat manually. - Open the dashboard and hard-refresh after deploy (
Ctrl+Shift+R). - Use Stock Parameters in the sidebar to edit per-material thresholds or apply preset defaults.
Flask window:
Ctrl+CTomcat:
cd /d C:\apache-tomcat-10.1.44\bin
shutdown.batBSP/
├── README.md
├── SpareAI_PRD.md
├── prophet training data/
└── spareai/
├── pom.xml
├── startup.bat / redeploy.bat
├── db/
│ ├── schema.sql
│ └── add-material-parameters.sql
├── spareai_real_data.sql
├── DOCUMENTATION.md
├── flask-service/
└── src/main/
├── java/
└── webapp/
Another Tomcat instance or another application may already be using port 8080. Stop the other process or change Tomcat's HTTP port in conf/server.xml.
Stop the other Python process or change the port in spareai/flask-service/app.py and set SPAREAI_FLASK_URL to the same URL.
Confirm MySQL is running, the spareai database exists, and SPAREAI_DB_USER / SPAREAI_DB_PASSWORD are set in the same Command Prompt session that starts Tomcat.
Check http://localhost:5001/health first. If Flask is not running, the Java API cannot generate forecasts.
Run db/add-material-parameters.sql, then redeploy.bat or startup.bat, and hard-refresh the browser. If Tomcat still serves an old WAR, delete webapps\spareai before copying the new spareai.war.
Rebuild and redeploy the WAR (redeploy.bat). The UI is packaged inside spareai.war, not served from source folders directly.
Use Python 3.11, upgrade pip, and install dependencies from an activated virtual environment. If compilation fails, install Microsoft C++ Build Tools and run pip install -r requirements.txt again.
- Full technical reference:
spareai/DOCUMENTATION.md(APIs, schema, UI pages, parameters) - Product requirements:
SpareAI_PRD.md - Prophet training data notes:
prophet training data/PROPHET_24M_README.md - Backend quick reference:
spareai/README.md