# 2abet/predictive-maintenance architecture

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

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

## Overview

##### Project type and purpose
- This is a **single-page Streamlit application** (“Predictive Maintenance Dashboard – AI vs Threshold”) for demonstrating real-time comparison between:
- Rule-based threshold alerts
- AI-powered Random Forest predictions
- Its goal is to simulate sensor data, inject borderline failures, display live risk sliders and confusion-matrix metrics, and showcase AI’s advantage in industrial predictive maintenance scenarios.

##### File structure
- Top-level files:
- `.devcontainer/` – Development container configuration
- `README.md` – Project overview, setup, tech stack
- `predictive_dashboard.py` – Main Streamlit app entrypoint
- `requirements.txt` – Python dependencies
- No separate frontend/back-end folders; everything is in one Streamlit script.
- External services: none. Data is simulated in-app.

##### Key insights from the README
- Tech stack: Python, Streamlit, Pandas, NumPy, scikit-learn
- Architecture is simple:
1. Data generation
2. Rule-based logic
3. AI model inference
4. UI rendering & interaction
5. Performance comparison

##### Main components
a. **Streamlit UI Layer**
- Interactive sliders & display panels
- Trigger for (re)running the pipeline on user input
b. **Data Simulator**
- Generates synthetic sensor streams (vibration, temperature, current)
- Injects borderline/failure cases
c. **Rule-Based Engine**
- Applies fixed thresholds to simulated data
- Outputs boolean alerts
d. **AI Prediction Engine**
- Pre-trained Random Forest model (loaded at startup)
- Consumes same simulated data, outputs failure probability
e. **Comparison & Metrics Module**
- Builds confusion matrices for both approaches
- Calculates precision, recall, F1-score
f. **Environment Configuration**
- `.devcontainer` for reproducible dev setup
- `requirements.txt` lists Pandas, NumPy, scikit-learn, Streamlit

##### Relationships and data flow
- User adjusts sliders in **UI Layer** → triggers data regeneration.
- **Data Simulator** emits data → feeds into **Rule-Based Engine** and **AI Prediction Engine** in parallel.
- Both outputs go to **Comparison Module** → metrics computed.
- UI Layer renders sensor charts, alert flags, risk scores, and confusion matrices side by side.

##### Architectural patterns & design principles
- **Separation of concerns**:
- UI vs data generation vs logic vs metrics
- **Parallel processing** of two pipelines (threshold vs AI) for comparison
- **Modularity**: each logical unit resides in a function/block within the script
- **Containerized dev environment** via `.devcontainer`

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Predictive Maintenance Dashboard"
        UI["Streamlit UI Layer\n(Streamlit)"]:::ui
        DS["Data Simulator\n(Pandas, NumPy)"]:::process
        RE["Rule-Based Engine\n(Fixed Thresholds)"]:::process
        AI["AI Prediction Engine\n(Random Forest)"]:::process
        CM["Comparison & Metrics Module\n(Precision, Recall, F1-Score)"]:::metrics
    end

    subgraph "Environment Configuration"
        DC["Dev Container"]:::env
        REQ["Dependencies"]:::env
    end

    UI -->|"user input triggers"| DS
    DS -->|"sensor_data"| RE
    DS -->|"sensor_data"| AI
    RE -->|"alerts"| CM
    AI -->|"failure_probability"| CM
    CM -->|"metrics update"| UI

    DC --> UI
    DC --> DS
    DC --> RE
    DC --> AI
    DC --> CM
    REQ --> UI
    REQ --> DS
    REQ --> RE
    REQ --> AI
    REQ --> CM

    %% Click Events
    click UI "https://github.com/2abet/predictive-maintenance/blob/main/dashboard.py"
    click DS "https://github.com/2abet/predictive-maintenance/blob/main/dashboard.py"
    click RE "https://github.com/2abet/predictive-maintenance/blob/main/dashboard.py"
    click AI "https://github.com/2abet/predictive-maintenance/blob/main/dashboard.py"
    click CM "https://github.com/2abet/predictive-maintenance/blob/main/dashboard.py"
    click DC "https://github.com/2abet/predictive-maintenance/blob/main/.devcontainer/devcontainer.json"
    click REQ "https://github.com/2abet/predictive-maintenance/blob/main/requirements.txt"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,stroke-width:2px
    classDef process fill:#DFFFE0,stroke:#228B22,stroke-width:2px
    classDef metrics fill:#FFE8A1,stroke:#FFA500,stroke-width:2px
    classDef env fill:#F0F0F0,stroke:#CCCCCC,stroke-dasharray:5 5,stroke-width:2px
```
