A comprehensive predictive maintenance platform built with Next.js, TypeScript, and machine learning. This system uses XGBoost models to predict machine failures and provides role-based dashboards for operators, maintenance staff, and managers.
- Machine Learning Predictions: Real-time failure predictions using trained XGBoost models
- Dynamic Telemetry: Simulated sensor data that varies by machine, date range, and operational status
- Failure Type Analysis: Predicts specific failure types (TWF, HDF, PWF, OSF, RNF) with probabilities
- Feature Responsibility: Shows which telemetry features contribute to each failure type
- Role-Based Dashboards: Customized views for Operators, Maintenance, and Managers
- Alert System: Automatic and manual alert creation with acknowledgment workflow
- Historical Tracking: Complete audit trail of predictions and alerts with CSV export
- Real XGBoost Model: Trained on AI4I 2020 dataset
- SHAP-like Explanations: Feature importance and impact analysis
- Dynamic Telemetry Generation: Realistic sensor data simulation
- Fallback System: Graceful degradation if ML service unavailable
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Next.js App ββββββΆβ Express API ββββββΆβ Python ML β
β (Port 3000) β β (Port 3001) β β Service β
β β β β β (Port 5000) β
β - Frontend β β - JWT Auth β β - XGBoost β
β - API Routes β β - User Mgmt β β - Predictions β
β - Components β β - Alerts β β - SHAP Values β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Node.js 18+ and npm
- Python 3.8+ and pip
- Git
-
Clone the repository
git clone https://github.com/ByteXBit/predictive-maintanence.git cd predictive-maintanence -
Install Node.js dependencies
npm install
-
Install Python dependencies
cd ml_service pip install -r requirements.txt cd ..
-
Train the ML model (First time only)
cd ml_service python train_model.py cd ..
-
Set up environment variables
Create
.envfile in the root directory:PORT=3001 JWT_SECRET=your-secret-key-change-in-production ML_SERVICE_URL=http://localhost:5000
You need 3 terminals running simultaneously:
Terminal 1 - Next.js Frontend:
npm run devAccess at: http://localhost:3000
Terminal 2 - Express API Server:
npm run dev:apiAccess at: http://localhost:3001
Terminal 3 - Python ML Service:
cd ml_service
python predict_service.pyAccess at: http://localhost:5000
| Role | Password | |
|---|---|---|
| Operator | operator@example.com |
Password123! |
| Maintenance | maintenance@example.com |
Password123! |
| Manager | manager@example.com |
Password123! |
The UI design is available on Figma: Predictive Maintenance Software Design
predictive-maintenance-demo/
βββ api/ # Express API server
β βββ server.ts # Main API server with JWT auth
β βββ tsconfig.json
βββ app/ # Next.js App Router
β βββ api/ # Next.js API routes
β β βββ alerts/ # Alert management
β β βββ auth/ # Authentication
β β βββ machines/ # Machine predictions
β β βββ ml/ # ML prediction proxy
β β βββ predictions/ # Prediction history
β β βββ seed/ # Demo data seeding
β β βββ telemetry/ # Dynamic telemetry generation
β βββ components/ # React components
β β βββ AlertsPanel.tsx
β β βββ DashboardLayout.tsx
β β βββ dashboard/ # Role-specific dashboards
β β βββ machines/ # Machine-related components
β βββ contexts/ # React contexts
β β βββ AuthContext.tsx
β βββ alerts/ # Alerts page
β βββ dashboard/ # Dashboard page
β βββ history/ # History page
β βββ login/ # Login page
β βββ machines/ # Machines list page
βββ ml_service/ # Python ML service
β βββ models/ # Trained models
β β βββ xgb_model.pkl
β β βββ label_encoder.pkl
β β βββ feature_names.txt
β βββ train_model.py # Model training script
β βββ predict_service.py # Flask prediction service
β βββ requirements.txt
βββ docs/ # Documentation
β βββ demo-script.md # Demo walkthrough
βββ scripts/ # Utility scripts
β βββ validate-all.ps1 # PowerShell validation
β βββ test-all.sh # Bash testing
βββ ai4i2020 (1).csv # Training dataset
βββ README.md
- Next.js 16 - React framework with App Router
- TypeScript - Type safety
- TailwindCSS - Utility-first CSS
- React Query - Server state management
- React Context - Authentication state
- Express.js - API server
- JWT - Authentication tokens
- bcryptjs - Password hashing
- cookie-parser - HttpOnly cookies
- XGBoost - Gradient boosting model
- scikit-learn - ML utilities
- Flask - Python API service
- pandas/numpy - Data processing
POST /api/auth/login- User loginPOST /api/auth/logout- User logoutPOST /api/auth/register- User registration
GET /api/machines/[id]/predict?startDate=X&endDate=Y- Get predictionGET /api/telemetry/[id]?startDate=X&endDate=Y- Get telemetry dataPOST /api/ml/predict- ML model prediction
GET /api/alerts- List alerts (filterable)POST /api/alerts- Create alertPATCH /api/alerts/[id]/acknowledge- Acknowledge alert
GET /api/predictions- List predictionsPOST /api/predictions- Save prediction
POST /api/seed- Seed demo dataGET /health- Health check (Express API)GET /health- Health check (ML Service)
- Algorithm: XGBoost Classifier
- Dataset: AI4I 2020 Predictive Maintenance Dataset
- Features: 8 features including:
- Air temperature [K]
- Process temperature [K]
- Rotational speed [rpm]
- Torque [Nm]
- Tool wear [min]
- Type (encoded)
- temperature_difference (derived)
- Mechanical Power [W] (derived)
- TWF (Tool Wear Failure) - High tool wear
- HDF (Heat Dissipation Failure) - High temperature difference
- PWF (Power Failure) - Low torque/power
- OSF (Overstrain Failure) - High rotational speed
- RNF (Random Failure) - Combination of factors
cd ml_service
python train_model.pyThis will:
- Load the dataset from
../ai4i2020 (1).csv - Preprocess and engineer features
- Train XGBoost model
- Save model to
models/xgb_model.pkl - Save preprocessing objects
Telemetry data is generated dynamically based on:
- Machine ID: Each machine has unique characteristics
- Date Range: Different periods produce different values
- Time-based Degradation: Machines degrade over time
- Operational Cycles: Realistic hourly patterns
- Machine Status: Operational/warning/maintenance affects values
- User selects machine and date range
- System generates dynamic telemetry for that period
- Telemetry sent to ML service
- ML model returns prediction with:
- Health score (0-100)
- Risk level (low/medium/high/critical)
- Failure type probabilities
- Feature responsibilities
- Results displayed with gauge visualization
- Operator: View machines, run predictions, see basic alerts
- Maintenance: Acknowledge alerts, view maintenance tasks
- Manager: Full access, KPI dashboards, historical reports
# Test all services
.\scripts\validate-all.ps1-
Health Checks:
curl http://localhost:3000/api/telemetry/1?startDate=2024-01-01&endDate=2024-01-31 curl http://localhost:3001/health curl http://localhost:5000/health
-
Full Prediction Flow:
curl "http://localhost:3000/api/machines/1/predict?startDate=2024-01-01&endDate=2024-01-31"
See QUICK_TEST.md for detailed testing instructions.
- Demo Script - Step-by-step demo walkthrough
- Validation Guide - Comprehensive testing guide
- Quick Test - Quick verification steps
- ML Service README - ML service documentation
- JWT tokens stored in HttpOnly cookies
- Passwords hashed with bcrypt
- Role-based access control
- CORS configured for development
- Change
JWT_SECRETto a strong random string - Use environment variables for all secrets
- Replace in-memory storage with database
- Enable HTTPS
- Add rate limiting
- Implement proper error handling
- Automatic threshold-based alerts
- Email/Slack notifications
- Real-time WebSocket updates
- Database integration (PostgreSQL/MongoDB)
- Advanced analytics dashboard
- Mobile app for on-site maintenance
- Multi-tenant support
- API rate limiting
- Comprehensive logging
- Unit and integration tests
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is for demonstration and educational purposes.
- Dataset: AI4I 2020 Predictive Maintenance Dataset
- Design: Figma design system
- Technologies: Next.js, XGBoost, scikit-learn
For issues and questions:
- Open an issue on GitHub
- Check the documentation in
/docs - Review the demo script for usage examples
Built with β€οΈ for predictive maintenance