This repository contains a production-ready, Dockerized template for training and deploying a machine learning micro-model designed to automatically classify/sort warehouse documents (such as invoices, receipts, waybills, and packing lists) for ERP systems.
The template integrates a Python (ML/FastAPI) microservice with a Java (Spring Boot) ERP microservice using REST APIs.
sequenceDiagram
participant User as User/ERP UI
participant Java as Java ERP (8081)
participant Python as Python Classifier (8000)
User->>Java: Upload Document/Trigger Sim
Note over Java: Instantiate Document object
Java->>Python: POST /classify {"text": "..."}
Note over Python: Load ML Model & Vectorizer
Note over Python: Run Inference (TF-IDF + LogReg)
Python-->>Java: Response {"category": "INVOICE", "confidence": 0.95}
Note over Java: Update Document metadata & Category
Java-->>User: Processed Document JSON
- docker-compose.yml - Orchestra configuration to build and run both services together.
- classifier-service/ (Python ML Service)
- train.py - Script containing synthetic warehouse document generation, TF-IDF feature extraction, and Logistic Regression training. Saves model pipeline to a
.joblibfile. - app.py - FastAPI application serving model inference via HTTP POST
/classify. Automatically runstrain.pyon startup if no model exists. - Dockerfile - Slim Python container environment configuration.
- train.py - Script containing synthetic warehouse document generation, TF-IDF feature extraction, and Logistic Regression training. Saves model pipeline to a
- erp-service/ (Java ERP Integration Service)
- pom.xml - Maven configurations using Spring Boot 2.7.18 (Java 8 compatible).
- WarehouseController.java - Exposes ERP endpoints to classify documents and trigger simulated document batch runs.
- ClassifierClient.java - Handles REST requests to the Python service using Spring
RestTemplate. - Dockerfile - Multi-stage Java container compiling the app and serving the
.jarpackage.
The easiest way to start both services and test the integration is using Docker Compose:
# Build and run the MLOps pipeline
docker-compose up --buildDocker will:
- Compile the Java code and package the Spring Boot JAR inside the build container.
- Build the Python environment and execute the training script (
train.py) to generatemodels/document_classifier.joblib. - Spin up Python service on port
8000and Java service on port8081.
Once docker-compose is running, you can test the simulated warehouse ERP document classification using curl or Postman:
This endpoint triggers the Java ERP system to create a mock batch of 4 different warehouse documents (Invoice, Waybill, Receipt, Packing List), call the MLOps Classifier, and return the classified metadata:
curl -X GET http://localhost:8081/api/warehouse/simulate-batchExpected JSON Response:
[
{
"id": "DOC-001",
"text": "Order details. Invoice number 44293. Total sum due: $340.00. Payment due immediately.",
"category": "INVOICE",
"confidence": 0.8845
},
{
"id": "DOC-002",
"text": "Logistics waybill TRK-88543. Destination: Berlin, Germany. Carrier: DHL Express.",
"category": "WAYBILL",
"confidence": 0.9412
},
...
]Post a custom document text to the Java service for classification:
curl -X POST http://localhost:8081/api/warehouse/classify \
-H "Content-Type: application/json" \
-d '{"text": "Shipment contains 20 items. 10 keyboards, 10 mice in box 2."}'Expected JSON Response:
{
"id": "some-generated-uuid",
"text": "Shipment contains 20 items. 10 keyboards, 10 mice in box 2.",
"category": "PACKING_LIST",
"confidence": 0.8711
}