How harpreet012/ai-predictive-maintainence- works
1. Overall shape
- This is a three-part system: a React/Vite client, a Node/Express API server, and a separate Python ML service.
- The main production data store is MongoDB.
- Real-time behavior is handled through Socket.io/WebSockets on top of the Node backend.
2. Frontend boundary
- The client/ app is a single-page industrial monitoring UI built around route-level pages such as Dashboard, Equipment, Alerts, Analytics, Maintenance, Anomaly, DigitalTwin, DataImport, Users, Calendar.
- Reusable visual widgets live in components/ and include gauges, charts, equipment cards, live graphs, a factory-floor view, chatbot, sidebar, and top bar.
- context/AuthContext.jsx manages user session state; context/SocketContext.jsx manages live updates.
- services/api.js is the HTTP client boundary to the backend.
3. Backend API boundary
- The server/ app is an Express REST API organized by domain routes: auth, users, equipment, sensors, alerts, maintenance, analytics, anomalies, dataImport, and chatbot.
- middleware/auth.js indicates protected endpoints and role/session enforcement.
- server.js is the API entrypoint; config/db.js handles MongoDB connectivity.
4. Domain model in MongoDB
- The server persists four core operational entities: Equipment, SensorReading, Alert, and MaintenanceLog, plus User.
- These models define the system’s main lifecycle: equipment registration, continuous sensor history, anomaly/alert records, and maintenance actions tied back to assets.
5. Operational data flow
- Sensor data enters the backend through sensor-related routes and/or the simulator, is stored in MongoDB, then drives dashboards, alerts, analytics, and maintenance views.
- The UI reads aggregated state from the API for historical pages and subscribes to live socket events for the “now” experience.
- The same underlying equipment and reading records appear across monitoring, anomaly detection, and maintenance workflows.
6. Real-time subsystem
- services/dataSimulator.js generates streaming telemetry and injects faults such as wear, overheating, or leaks.
- The backend broadcasts updates to clients over sockets, enabling live charts, health meters, and toast-style alerting without page refresh.
- This real-time path is separate from the standard REST path: REST serves durable records; sockets carry transient updates.
7. ML/anomaly detection layer
- server/services/mlEngine.js is the core decision layer in the Node backend and implements:
- z-score anomaly detection,
- weighted health scoring,
- exponential degradation / failure projection,
- sigmoid failure probability,
- equipment-type-specific rules.
- This means prediction is not just a black-box model call; it is a rule-and-statistics engine embedded in the API flow.
8. Python ML microservice
- ml-service/ is a distinct Python/Flask-style service with app.py, train.py, test_predictions.py, and a saved model.pkl.
- Architecturally, it acts as a separate ML boundary from the Express app, likely for experimentation, training, or inference support.
- The repository therefore contains both an embedded Node ML engine and a standalone Python ML artifact/service.
9. Authentication and user management
- Login and registration are handled by dedicated frontend pages and the backend auth routes.
- User model plus users routes suggest role-based access for operators, maintenance users, or admins.
- Protected areas such as equipment management, imports, and administration are likely gated through the auth middleware.
10. Analytics and maintenance workflows
- analytics and anomalies routes provide computed summaries rather than raw sensor rows.
- Maintenance is a first-class domain: MaintenanceLog stores work history, and the Maintenance page is part of the main navigation, not a side feature.
- This makes the system a closed loop: detect issues, surface them, and track remediation.
11. Data onboarding and environment setup
- config/seed.js seeds the database with starter equipment and 7-day history, which suggests the app is designed to boot with realistic operational data.
- dataImport routes and a DataImportPage imply the system can ingest external datasets as well as simulator-generated telemetry.
12. Deployment and runtime notes
- The stack is optimized for local development with npm run dev on both client and server, and the client uses Vite SPA routing support (public/_redirects).
- render.yaml indicates deployment is expected on Render or a similar platform with separate service/process definitions.
13. Architecture diagram takeaway
- Draw the system as: Users → React SPA → Express API / Socket.io → MongoDB, with a side path from Data Simulator into the same backend, and a separate Python ML service adjacent to the Node backend.
- The key boundaries are: presentation, API/auth, persistence, real-time telemetry, and predictive analytics.
Main entry points: App.jsx React SPA · server.js Express API · routes Domain Routes · dataSimulator.js Telemetry Simulator
Components 18
Client
React/Vite single-page monitoring UI
- React SPA · Vite-based industrial monitoring client
client/src/App.jsx - Pages · Dashboard, equipment, alerts, analytics, maintenance, import, users
client/src/pages - Widgets · Charts, gauges, factory floor, chatbot, navigation
client/src/components - Auth State · Session and login state management
client/src/context/AuthContext.jsx - Socket State · Live update subscription state
client/src/context/SocketContext.jsx - API Client · Frontend HTTP boundary to backend
client/src/services/api.js
API Server
Express REST API with realtime sockets and MongoDB persistence
- Express API · Main Node backend entrypoint
server/server.js - Auth Middleware · Protected routes and role enforcement
server/middleware/auth.js - MongoDB · Primary persistent data store
server/config/db.js - Domain Routes · Auth, users, equipment, sensors, alerts, maintenance, analytics, anomalies, import, chatbot
server/routes - Data Models · User, Equipment, SensorReading, Alert, MaintenanceLog
server/models - Telemetry Simulator · Generates readings and fault scenarios
server/services/dataSimulator.js - ML Engine · Z-score detection, health scoring, degradation and failure projection
server/services/mlEngine.js - Socket.IO · Broadcasts live telemetry and alerts
- Seed Data · Starter equipment and history population
server/config/seed.js
ML Services
Embedded Node anomaly engine plus standalone Python service
- Python ML Service · Standalone inference/training boundary
ml-service/app.py - Model Artifact · Saved Python model for predictions
ml-service/model.pkl
Other components
- Users · Operators, maintenance staff, admins
Connections 19
- Users → React SPA: uses · Operators interact through the SPA
- React SPA → Pages: navigates · Route-level pages drive the UI
- React SPA → Widgets: renders · Pages compose shared monitoring widgets
- React SPA → Auth State: session · Client auth state
- React SPA → Socket State: live state · Client subscribes to live updates
- React SPA → API Client: requests · REST calls to backend
- API Client → Express API: http · API boundary
- Express API → Auth Middleware: guards · Protects sensitive endpoints
- Express API → Domain Routes: routes · Domain REST APIs
- Domain Routes → Data Models: reads/writes · CRUD and workflow persistence
- Data Models → MongoDB: stored in · MongoDB-backed persistence
- Express API → Socket.IO: publishes · Realtime events and alerts
- Socket State → Socket.IO: subscribes · Client listens for live updates
- Telemetry Simulator → Express API: injects telemetry · Streaming sensor data enters backend
- Telemetry Simulator → ML Engine: faults · Simulator feeds anomaly logic
- ML Engine → Domain Routes: enriches · Predictive results surface through API
- Seed Data → MongoDB: bootstraps · Loads starter operational data
- Express API → Python ML Service: ml boundary · Separate Python service adjacent to Node backend
- Python ML Service → Model Artifact: loads · Uses saved model artifact