# me-intenzo/phm_project architecture

> Architecture diagram of the GitHub repository me-intenzo/phm_project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/me-intenzo/phm_project
- Repository: https://github.com/me-intenzo/phm_project

## Overview

#### Purpose and Entry Points
PHM-XAI is a Python predictive-maintenance pipeline for NASA C-MAPSS turbofan Remaining Useful Life (RUL) prediction. Raw FD001–FD004 dataset files are expected under `data/raw/`; subset-specific execution parameters live in `configs/fd001.yaml` through `configs/fd004.yaml`. `main.py` is the EDA entry point; stage-specific CLI entry points are `scripts/preprocess.py`, `scripts/train.py`, `scripts/evaluate.py`, `scripts/explain.py`, `scripts/uncertainty.py`, and `scripts/decision.py`.

#### Configuration and Pipeline Coordination
Configuration, deterministic execution, logging, and artifact I/O form the cross-cutting runtime boundary. Dataset, windowing, training, device, and seed choices are supplied by YAML configs and consumed by the scripts and model pipeline. Central utilities are in `src/utils/config.py`, `src/utils/seed.py`, and `src/utils/io.py`.

#### Data Preparation and RUL Supervision
The preprocessing layer converts C-MAPSS trajectory text data into validated, model-ready temporal samples. It loads train/test/RUL inputs, validates schema/content, creates RUL labels, selects features, scales sensors, and produces sliding windows. This is the primary boundary between raw engine-cycle data and tensors/model inputs, implemented across `src/preprocessing/loader.py`, `src/preprocessing/labeling.py`, and `src/preprocessing/windowing.py`; scaling and validation are in `src/preprocessing/scaling.py` and `src/preprocessing/validator.py`.

#### Predictive Models and Training
PyTorch-based sequence regressors estimate RUL from sensor windows. The model family includes LSTM, GRU, Transformer, and hybrid/attention-degradation variants, allowing training runs to select or compare architectural approaches. Training and model evaluation are centralized in `src/models/trainer.py` and `src/models/evaluator.py`; representative architectures are `src/models/lstm.py`, `src/models/gru.py`, `src/models/transformer.py`, and `src/models/hybrid.py`. Custom objectives reside in `src/models/losses.py`.

#### Evaluation and Robustness
Offline assessment measures predictive quality and experimental resilience, rather than serving predictions directly. The evaluation layer owns metrics, benchmarks, ablations, and robustness studies through `src/evaluation/metrics.py`, `src/evaluation/benchmark.py`, `src/evaluation/ablation.py`, and `src/evaluation/robustness.py`. `scripts/evaluate.py` is the evaluation orchestration boundary after training.

#### Explainability and Trust Signals
The explainability subsystem interprets model predictions using SHAP, Captum Integrated Gradients, and model attention, and provides degradation-oriented visualizations. It also computes an Explainability Reliability Index (ERI), making explanation reliability a first-class signal. Core modules are `src/explainability/shap_explainer.py`, `src/explainability/integrated_gradients.py`, `src/explainability/attention.py`, and `src/explainability/eri.py`; `scripts/explain.py` runs this stage. External explainability runtimes include SHAP and Captum.

#### Uncertainty, Decisions, and Human Feedback
Prediction uncertainty is quantified with calibration, conformal intervals, and coverage analysis before maintenance guidance is issued. This boundary is implemented in `src/uncertainty/calibration.py`, `src/uncertainty/conformal.py`, and `src/uncertainty/coverage.py`. The decision engine turns predicted RUL and operational constraints into rule-based maintenance recommendations via `src/decision_engine/rules.py`, `src/decision_engine/constraints.py`, and `src/decision_engine/recommender.py`. Human feedback is logged and can drive updates through `src/hitl/feedback.py`, `src/hitl/logger.py`, and `src/hitl/updater.py`.

Main entry points: [`src/models/trainer.py`](https://github.com/me-intenzo/phm_project/blob/main/src/models/trainer.py) (Training), [`src/decision_engine/recommender.py`](https://github.com/me-intenzo/phm_project/blob/main/src/decision_engine/recommender.py) (Maintenance recommender), [`src/utils/config.py`](https://github.com/me-intenzo/phm_project/blob/main/src/utils/config.py) (Runtime utilities), [`src/preprocessing/loader.py`](https://github.com/me-intenzo/phm_project/blob/main/src/preprocessing/loader.py) (Trajectory loading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_configs["Subset configs<br/>YAML configuration<br/>[fd001.yaml]"]
  node_utilities["Runtime utilities<br/>config, seed, I/O<br/>[config.py]"]
end

subgraph group_data["Data preparation"]
  node_raw_data[("C-MAPSS raw data<br/>trajectory files")]
  node_preprocess_cli["Preprocess CLI<br/>stage entry point<br/>[preprocess.py]"]
  node_loader["Trajectory loading<br/>data ingestion<br/>[loader.py]"]
  node_rul_labeling["RUL labeling<br/>supervision builder<br/>[labeling.py]"]
  node_windowing["Scaling and windows<br/>temporal sample builder<br/>[windowing.py]"]
  node_temporal_samples[("Model-ready samples<br/>windowed tensors")]
end

subgraph group_modeling["Modeling"]
  node_train_cli["Train CLI<br/>stage entry point<br/>[train.py]"]
  node_model_family["Sequence model family<br/>LSTM, GRU, Transformer, hybrid<br/>[lstm.py]"]
  node_trainer["Training<br/>[trainer.py]"]
  node_trained_model{{"Trained model<br/>model artifact"}}
  node_evaluate_cli["Evaluate CLI<br/>stage entry point<br/>[evaluate.py]"]
  node_offline_evaluation["Offline evaluation<br/>metrics and studies<br/>[metrics.py]"]
end

subgraph group_trust["Trust and action"]
  node_explainability["Explainability and ERI<br/>SHAP, Captum, attention<br/>[shap_explainer.py]"]
  node_uncertainty["Uncertainty analysis<br/>calibration and conformal<br/>[calibration.py]"]
  node_decision_engine["Maintenance recommender<br/>rule-based decision engine<br/>[recommender.py]"]
  node_human_feedback["Human feedback loop<br/>feedback and updates<br/>[feedback.py]"]
end

node_configs -->|"loaded by"| node_utilities
node_utilities -.->|"configures"| node_preprocess_cli
node_utilities -.->|"configures"| node_train_cli
node_raw_data -->|"ingested as"| node_loader
node_preprocess_cli -->|"runs"| node_loader
node_loader -->|"validated trajectories"| node_rul_labeling
node_rul_labeling -->|"labeled series"| node_windowing
node_windowing -->|"produces"| node_temporal_samples
node_train_cli -->|"runs"| node_trainer
node_temporal_samples -->|"training inputs"| node_trainer
node_model_family -->|"selected architecture"| node_trainer
node_trainer -->|"writes"| node_trained_model
node_evaluate_cli -->|"runs"| node_offline_evaluation
node_trained_model -->|"assessed by"| node_offline_evaluation
node_temporal_samples -->|"evaluation data"| node_offline_evaluation
node_trained_model -->|"predictions and internals"| node_explainability
node_temporal_samples -->|"sensor windows"| node_explainability
node_trained_model -->|"predictions"| node_uncertainty
node_uncertainty -->|"intervals and coverage"| node_decision_engine
node_trained_model -->|"RUL predictions"| node_decision_engine
node_explainability -.->|"trust signals"| node_decision_engine
node_decision_engine -->|"recommendations reviewed"| node_human_feedback
node_human_feedback -.->|"updates inform retraining"| node_trainer

click node_configs "https://github.com/me-intenzo/phm_project/blob/main/configs/fd001.yaml"
click node_utilities "https://github.com/me-intenzo/phm_project/blob/main/src/utils/config.py"
click node_preprocess_cli "https://github.com/me-intenzo/phm_project/blob/main/scripts/preprocess.py"
click node_loader "https://github.com/me-intenzo/phm_project/blob/main/src/preprocessing/loader.py"
click node_rul_labeling "https://github.com/me-intenzo/phm_project/blob/main/src/preprocessing/labeling.py"
click node_windowing "https://github.com/me-intenzo/phm_project/blob/main/src/preprocessing/windowing.py"
click node_train_cli "https://github.com/me-intenzo/phm_project/blob/main/scripts/train.py"
click node_model_family "https://github.com/me-intenzo/phm_project/blob/main/src/models/lstm.py"
click node_trainer "https://github.com/me-intenzo/phm_project/blob/main/src/models/trainer.py"
click node_evaluate_cli "https://github.com/me-intenzo/phm_project/blob/main/scripts/evaluate.py"
click node_offline_evaluation "https://github.com/me-intenzo/phm_project/blob/main/src/evaluation/metrics.py"
click node_explainability "https://github.com/me-intenzo/phm_project/blob/main/src/explainability/shap_explainer.py"
click node_uncertainty "https://github.com/me-intenzo/phm_project/blob/main/src/uncertainty/calibration.py"
click node_decision_engine "https://github.com/me-intenzo/phm_project/blob/main/src/decision_engine/recommender.py"
click node_human_feedback "https://github.com/me-intenzo/phm_project/blob/main/src/hitl/feedback.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_configs,node_utilities toneBlue
class node_raw_data,node_preprocess_cli,node_loader,node_rul_labeling,node_windowing,node_temporal_samples toneAmber
class node_train_cli,node_model_family,node_trainer,node_trained_model,node_evaluate_cli,node_offline_evaluation toneMint
class node_explainability,node_uncertainty,node_decision_engine,node_human_feedback toneRose
```

## Components

### Runtime

Shared configuration and artifact boundary.

- [Subset configs](https://github.com/me-intenzo/phm_project/blob/main/configs/fd001.yaml): YAML configuration · FD001–FD004 execution parameters. · `configs/fd001.yaml`
- [Runtime utilities](https://github.com/me-intenzo/phm_project/blob/main/src/utils/config.py): config, seed, I/O · Loads settings, enforces deterministic runs, and manages artifacts. · `src/utils/config.py`

### Data preparation

Converts C-MAPSS files into temporal training samples.

- **C-MAPSS raw data**: trajectory files · Train, test, and RUL inputs for FD001–FD004.
- [Preprocess CLI](https://github.com/me-intenzo/phm_project/blob/main/scripts/preprocess.py): stage entry point · `scripts/preprocess.py`
- [Trajectory loading](https://github.com/me-intenzo/phm_project/blob/main/src/preprocessing/loader.py): data ingestion · Loads inputs and validates their schema and content. · `src/preprocessing/loader.py`
- [RUL labeling](https://github.com/me-intenzo/phm_project/blob/main/src/preprocessing/labeling.py): supervision builder · Creates remaining-useful-life targets. · `src/preprocessing/labeling.py`
- [Scaling and windows](https://github.com/me-intenzo/phm_project/blob/main/src/preprocessing/windowing.py): temporal sample builder · Selects and scales sensors, then creates sliding windows. · `src/preprocessing/windowing.py`
- **Model-ready samples**: windowed tensors

### Modeling

Sequence regression training and evaluation.

- [Train CLI](https://github.com/me-intenzo/phm_project/blob/main/scripts/train.py): stage entry point · `scripts/train.py`
- [Sequence model family](https://github.com/me-intenzo/phm_project/blob/main/src/models/lstm.py): LSTM, GRU, Transformer, hybrid · Selectable RUL regressor architectures. · `src/models/lstm.py`
- [Training](https://github.com/me-intenzo/phm_project/blob/main/src/models/trainer.py): PyTorch training loop · Optimizes selected regressors with custom objectives. · `src/models/trainer.py`
- **Trained model**: model artifact
- [Evaluate CLI](https://github.com/me-intenzo/phm_project/blob/main/scripts/evaluate.py): stage entry point · `scripts/evaluate.py`
- [Offline evaluation](https://github.com/me-intenzo/phm_project/blob/main/src/evaluation/metrics.py): metrics and studies · Measures quality, benchmarks, ablations, and robustness. · `src/evaluation/metrics.py`

### Trust and action

Post-prediction analysis, guidance, and feedback.

- [Explainability and ERI](https://github.com/me-intenzo/phm_project/blob/main/src/explainability/shap_explainer.py): SHAP, Captum, attention · Generates attribution and explanation-reliability signals. · `src/explainability/shap_explainer.py`
- [Uncertainty analysis](https://github.com/me-intenzo/phm_project/blob/main/src/uncertainty/calibration.py): calibration and conformal · Produces calibrated intervals and coverage analysis. · `src/uncertainty/calibration.py`
- [Maintenance recommender](https://github.com/me-intenzo/phm_project/blob/main/src/decision_engine/recommender.py): rule-based decision engine · Combines predicted RUL with operational constraints. · `src/decision_engine/recommender.py`
- [Human feedback loop](https://github.com/me-intenzo/phm_project/blob/main/src/hitl/feedback.py): feedback and updates · Logs feedback and drives model updates. · `src/hitl/feedback.py`

## Connections

- Subset configs → Runtime utilities: loaded by
- Runtime utilities → Preprocess CLI: configures
- Runtime utilities → Train CLI: configures
- C-MAPSS raw data → Trajectory loading: ingested as
- Preprocess CLI → Trajectory loading: runs
- Trajectory loading → RUL labeling: validated trajectories
- RUL labeling → Scaling and windows: labeled series
- Scaling and windows → Model-ready samples: produces
- Train CLI → Training: runs
- Model-ready samples → Training: training inputs
- Sequence model family → Training: selected architecture
- Training → Trained model: writes
- Evaluate CLI → Offline evaluation: runs
- Trained model → Offline evaluation: assessed by
- Model-ready samples → Offline evaluation: evaluation data
- Trained model → Explainability and ERI: predictions and internals
- Model-ready samples → Explainability and ERI: sensor windows
- Trained model → Uncertainty analysis: predictions
- Uncertainty analysis → Maintenance recommender: intervals and coverage
- Trained model → Maintenance recommender: RUL predictions
- Explainability and ERI → Maintenance recommender: trust signals
- Maintenance recommender → Human feedback loop: recommendations reviewed
- Human feedback loop → Training: updates inform retraining
