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.
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;You 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.
Open a second Command Prompt window.
cd spareai
mvn clean packageAfter a successful build, the WAR file is here:
spareai\target\spareai.war
Copy the WAR into Tomcat:
copy /Y target\spareai.war C:\apache-tomcat-10.1.44\webapps\Set the backend environment variables in the same Command Prompt session if you have not already:
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:5001Start Tomcat:
cd /d C:\apache-tomcat-10.1.44\bin
startup.batWait until Tomcat finishes deploying spareai.war.
Use these URLs after both services are running:
| Service | URL |
|---|---|
| Dashboard | http://localhost:8080/spareai/ |
| API base | http://localhost:8080/spareai/api |
| Flask health | http://localhost:5001/health |
Example API checks:
curl http://localhost:8080/spareai/api/inventory
curl http://localhost:8080/spareai/api/charts/overview- Start MySQL Server.
- Start the Flask service in one Command Prompt window.
- Build the WAR with Maven when Java code changes.
- Deploy
spareai.warto Tomcat. - Start Tomcat in another Command Prompt window with the
SPAREAI_*variables set. - Open the dashboard in your browser.
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
├── db/schema.sql
├── spareai_real_data.sql
├── flask-service/
│ ├── app.py
│ └── requirements.txt
└── src/
├── main/java/
└── main/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.
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.
- Product requirements:
SpareAI_PRD.md - Prophet training data notes:
prophet training data/PROPHET_24M_README.md - Backend-focused notes:
spareai/README.md