# adityapotdar23/predictive-maintenance architecture

> Architecture diagram of the GitHub repository adityapotdar23/predictive-maintenance, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adityapotdar23/predictive-maintenance
- Repository: https://github.com/adityapotdar23/predictive-maintenance

## Overview

##### Project type and purpose
- This is a full-stack predictive-maintenance web application (“AI Kavach”) that combines:
- A React.js frontend
- A Python Flask microservice (app.py) hosting the ML model (XGBoost, Random Forest, etc.)
- A Node.js/Express backend for authentication, user/feedback data handling, and alerts
- A MongoDB database
- External integration with the Telegram API

##### File structure
- Top-level:
- app.py, merged.csv, xgb.pkl → Flask service + serialized ML model + raw dataset
- backend/ (Node.js microservice)
- app.js, auth.js, index.js → Express routes for login/register, feedback, scheduling
- db/ → connection logic (dbConnect.js) and Mongoose models (userModel.js, questionModel.js)
- frontend/ (React SPA)
- public/ → static assets and index.html
- src/ → React components (Login, Register, Dashboard, Charts, Calendar, Feedback, Reports, Sidebar, etc.)
- Uses Tailwind CSS + Chart.js for styling and data visualization

##### README
- Confirms architecture: React frontend, Flask API, Node.js API, MongoDB, Telegram notifications
- Key features: real-time sensor data visualization, RUL (Remaining Useful Life) prediction, calendar scheduling, alerts

##### Main components & interactions
a. Components:
1. React Frontend (frontend/src)
2. Flask ML Service (app.py + xgb.pkl)
3. Node.js/Express Service (backend/app.js, auth.js, index.js)
4. MongoDB (backend/db)
5. Telegram API (external)
b. Relationships:
- Frontend ↔ Node.js API: user authentication, profile, feedback, scheduling (HTTP/REST)
- Frontend ↔ Flask API: sensor data push & RUL prediction (HTTP/REST)
- Node.js API ↔ MongoDB: persistent storage of users, feedback, reports, schedule entries
- Node.js API ↔ Telegram API: send alerts/notifications
- Flask API reads merged.csv if needed for batch jobs, loads xgb.pkl for predictions
c. Architectural patterns & principles:
- Microservices: separate ML logic (Flask) from business/auth logic (Node.js)
- SPA (Single-Page Application) for responsive UI
- RESTful APIs for clear separation of concerns
- MVC pattern in Node.js (models in backend/db, controllers in auth.js/app.js)
d. Key technologies/libraries:
- Frontend: React.js, Tailwind CSS, React Chart.js
- Flask: pandas (for merged.csv), scikit-learn / xgboost
- Node.js: Express, Mongoose, dotenv
- Database: MongoDB
- External: Telegram Bot API

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Frontend["React Frontend"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        NodeService["Node.js Service\n(Express)"]:::service
        FlaskService["Flask ML Service\n(Python)"]:::service

        subgraph "Node.js Service Files"
            AppJS["app.js"]:::service
            AuthJS["auth.js"]:::service
            IndexJS["index.js"]:::service
            PKG["package.json"]:::service
        end

        subgraph "Flask ML Service Files"
            AppPy["app.py"]:::service
            XGB["xgb.pkl"]:::service
            CSV["merged.csv"]:::service
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        MongoDB["MongoDB"]:::data
        MLAssets["ML Assets\n(Model & Dataset)"]:::data

        subgraph "MongoDB Files"
            DBConnect["dbConnect.js"]:::data
            UserModel["userModel.js"]:::data
            QuestionModel["questionModel.js"]:::data
        end
    end

    %% External
    Telegram["Telegram API"]:::external

    %% Connections
    Frontend -->|"HTTP REST /login,/register,/feedback,/schedule"| NodeService
    Frontend -->|"HTTP REST /predict"| FlaskService
    NodeService -->|"read/write"| MongoDB
    NodeService -->|"HTTP webhook"| Telegram
    FlaskService -->|"loads model/dataset"| MLAssets

    %% Click Events
    click Frontend "https://github.com/adityapotdar23/predictive-maintenance/tree/main/frontend/"
    click AppPy "https://github.com/adityapotdar23/predictive-maintenance/blob/main/app.py"
    click XGB "https://github.com/adityapotdar23/predictive-maintenance/blob/main/xgb.pkl"
    click CSV "https://github.com/adityapotdar23/predictive-maintenance/blob/main/merged.csv"
    click AppJS "https://github.com/adityapotdar23/predictive-maintenance/blob/main/backend/app.js"
    click AuthJS "https://github.com/adityapotdar23/predictive-maintenance/blob/main/backend/auth.js"
    click IndexJS "https://github.com/adityapotdar23/predictive-maintenance/blob/main/backend/index.js"
    click PKG "https://github.com/adityapotdar23/predictive-maintenance/blob/main/backend/package.json"
    click DBConnect "https://github.com/adityapotdar23/predictive-maintenance/blob/main/backend/db/dbConnect.js"
    click UserModel "https://github.com/adityapotdar23/predictive-maintenance/blob/main/backend/db/userModel.js"
    click QuestionModel "https://github.com/adityapotdar23/predictive-maintenance/blob/main/backend/db/questionModel.js"

    %% Styles
    classDef frontend fill:#CCE5FF,stroke:#333,stroke-width:1px
    classDef service fill:#CCFFCC,stroke:#333,stroke-width:1px
    classDef data fill:#FFEB99,stroke:#333,stroke-width:1px
    classDef external fill:#FFCC99,stroke:#333,stroke-width:1px
```
