# virajmote/predictive_maintenance_backend-v2 architecture

> Architecture diagram of the GitHub repository virajmote/predictive_maintenance_backend-v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/virajmote/predictive_maintenance_backend-v2
- Repository: https://github.com/virajmote/predictive_maintenance_backend-v2

## Overview

This backend turns industrial sensor readings into failure-mode probabilities, remaining useful life, health scores, and operator alerts. The runtime path is a client request through FastAPI into model-backed inference and a structured response; batch prediction and model-status endpoints are additional API capabilities. Offline, the training orchestrator validates the AI4I dataset, engineers features and RUL labels, trains baseline or LSTM models, and saves a package consumed by inference. Edges follow the excerpts, SOURCE INDEX references, or README; unsampled internals are not expanded.

Main entry points: [`train.py`](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/train.py) (Training Orchestrator), [`inference.py`](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/inference.py) (Inference Engine), [`config.py`](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/config.py) (Model Configuration), [`api.py`](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/api.py) (FastAPI API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["API Serving"]
  node_api["FastAPI API<br/>[api.py]"]
  node_response["Prediction Response<br/>[api.py]"]
end

subgraph group_inference["Prediction"]
  node_inference_engine["Inference Engine<br/>[inference.py]"]
  node_health_alerts["Health and Alerts<br/>[inference.py]"]
  node_model_package[("Model Package")]
end

subgraph group_training["Model Training"]
  node_trainer["Training Orchestrator<br/>[train.py]"]
  node_features["Feature Engineering"]
  node_baseline["RF and XGBoost<br/>[baseline_model.py]"]
  node_lstm["LSTM Models<br/>[lstm_model.py]"]
end

subgraph group_data["Data and Configuration"]
  node_dataset["AI4I Dataset<br/>[ai4i2020.csv]"]
  node_config["Model Configuration<br/>[config.py]"]
end

node_client(("API Client"))

node_client -->|"submits readings"| node_api
node_api -->|"runs prediction"| node_inference_engine
node_model_package -->|"loads models"| node_inference_engine
node_inference_engine -->|"builds score and alerts"| node_health_alerts
node_inference_engine -->|"uses features"| node_features
node_inference_engine -->|"builds sequences"| node_lstm
node_api -->|"returns predictions"| node_response
node_health_alerts -->|"supplies result fields"| node_response
node_dataset -->|"provides training data"| node_trainer
node_trainer -->|"engineers data"| node_features
node_trainer -->|"trains baselines"| node_baseline
node_trainer -->|"trains sequences"| node_lstm
node_trainer -->|"saves selected model"| node_model_package
node_trainer -->|"reads settings"| node_config
node_features -->|"reads feature settings"| node_config
node_baseline -->|"reads model settings"| node_config
node_lstm -->|"reads sequence settings"| node_config

click node_api "https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/api.py"
click node_response "https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/api.py"
click node_inference_engine "https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/inference.py"
click node_health_alerts "https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/inference.py"
click node_model_package "https://github.com/virajmote/predictive_maintenance_backend-v2/tree/main/models"
click node_trainer "https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/train.py"
click node_features "https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/feature_engineering.py"
click node_baseline "https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/baseline_model.py"
click node_lstm "https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/lstm_model.py"
click node_dataset "https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/data/ai4i2020.csv"
click node_config "https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_response,node_client toneBlue
class node_inference_engine,node_health_alerts,node_model_package toneAmber
class node_trainer,node_features,node_baseline,node_lstm toneMint
class node_dataset,node_config toneRose
```

## Components

### API Serving

- [FastAPI API](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/api.py): `api.py`
- [Prediction Response](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/api.py): `api.py`

### Prediction

- [Inference Engine](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/inference.py): `inference.py`
- [Health and Alerts](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/inference.py): `inference.py`
- [Model Package](https://github.com/virajmote/predictive_maintenance_backend-v2/tree/main/models): `models`

### Model Training

- [Training Orchestrator](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/train.py): `train.py`
- [Feature Engineering](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/feature_engineering.py): `feature_engineering.py`
- [RF and XGBoost](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/baseline_model.py): `baseline_model.py`
- [LSTM Models](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/lstm_model.py): `lstm_model.py`

### Data and Configuration

- [AI4I Dataset](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/data/ai4i2020.csv): `data/ai4i2020.csv`
- [Model Configuration](https://github.com/virajmote/predictive_maintenance_backend-v2/blob/main/config.py): `config.py`

### Other components

- **API Client**

## Connections

- API Client → FastAPI API: submits readings (evidence: `README.md`)
- FastAPI API → Inference Engine: runs prediction (evidence: `api.py`)
- Model Package → Inference Engine: loads models (evidence: `inference.py`)
- Inference Engine → Health and Alerts: builds score and alerts (evidence: `inference.py`)
- Inference Engine → Feature Engineering: uses features (evidence: `inference.py`)
- Inference Engine → LSTM Models: builds sequences (evidence: `inference.py`)
- FastAPI API → Prediction Response: returns predictions (evidence: `api.py`)
- Health and Alerts → Prediction Response: supplies result fields (evidence: `inference.py`)
- AI4I Dataset → Training Orchestrator: provides training data (evidence: `README.md`)
- Training Orchestrator → Feature Engineering: engineers data (evidence: `train.py`)
- Training Orchestrator → RF and XGBoost: trains baselines (evidence: `train.py`)
- Training Orchestrator → LSTM Models: trains sequences (evidence: `train.py`)
- Training Orchestrator → Model Package: saves selected model (evidence: `README.md`)
- Training Orchestrator → Model Configuration: reads settings (evidence: `train.py`)
- Feature Engineering → Model Configuration: reads feature settings (evidence: `feature_engineering.py`)
- RF and XGBoost → Model Configuration: reads model settings (evidence: `baseline_model.py`)
- LSTM Models → Model Configuration: reads sequence settings (evidence: `lstm_model.py`)
