# codelb5/predictive_sensor_maintenance architecture

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

- Interactive diagram: https://gitdiagram.com/codelb5/predictive_sensor_maintenance
- Repository: https://github.com/codelb5/predictive_sensor_maintenance

## Overview

##### Project Type & Purpose
- This is a standalone machine-learning pipeline application designed for predictive maintenance of APS (Air Pressure Sensor) health on trucks.
- It provides end-to-end capabilities: ingestion of raw sensor data, validation, transformation, model training, evaluation, and pushing the trained model for deployment or consumption.

##### File Structure
- Top-level orchestration & configuration:
- main.py – CLI or entrypoint that triggers the training pipeline
- config/schema.yaml – central schema for validating user config
- Dockerfile / .dockerignore – containerization
- requirements.txt, setup.py – dependency & packaging
- Modular components under sensor/:
- sensor/components – core pipeline stages (data_ingestion, data_transformation, data_validation, model_trainer, model_evaluation, model_pusher)
- sensor/connection – external dependencies (mongodb_connection)
- sensor/data_access – raw data retrieval (sensor_data)
- sensor/constant – configuration constants (application, database, env_variables, training_pipeline)
- sensor/entity – DTOs for artifacts & config
- sensor/logger – centralized logging
- sensor/exceptions – custom error handling
- sensor/ml – modeling infrastructure (metric computation, estimator abstraction)
- sensor/pipeline – glue code for wiring components (training_pipeline.py)
- sensor/utils – shared helper functions

##### Extract Insights from README
- Although brief, the README name confirms the goal: build a predictive-maintenance solution for APS sensors.
- No conflicting architecture notes; the file tree already implies a layered, modular ML pipeline design.

##### Main Components & Their Relationships
a. Data Sources & Connections
- External Service: MongoDB (via sensor/connection/mongodb_connection.py)
- Data Access Layer: sensor/data_access/sensor_data.py
b. Pipeline Stages (in sequence)
1. Data Ingestion
2. Data Validation
3. Data Transformation
4. Model Training
5. Model Evaluation
6. Model Pusher (artifact registry or deployment endpoint)
c. Orchestrator
- training_pipeline (in sensor/pipeline/training_pipeline.py)
- main.py triggers the orchestrator
d. Support Services
- Configuration Manager (config/schema.yaml + sensor/constant)
- Logger (sensor/logger)
- Exception Handler (sensor/exceptions)
- Utilities (sensor/utils)
e. Artifact Storage / Registry
- Local filesystem or remote store (implied by ModelPusher)

##### Architectural Patterns & Design Principles
- Layered Architecture: clear separation between ingestion, validation, transformation, training, evaluation, deployment.
- Modular Components: each stage lives in its own module, making the pipeline extensible and testable.
- Configuration-first: YAML schema and constants drive environment and pipeline behavior.
- Dependency Injection via entities (artifact_entity, config_entity).

##### Technologies & Frameworks to Call Out
- Python 3.x
- PyMongo (for MongoDB integration)
- YAML (for configuration schemas)
- Docker (containerization)
- Any ML frameworks implied (e.g., scikit-learn or custom estimator in sensor/ml/model/estimator.py)
- Logging library (Python’s logging module wrapped by sensor/logger)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Entrypoint
    main["CLI Entrypoint\n(main.py)"]:::cli
    %% Orchestrator
    Orchestrator["Pipeline Orchestrator\n(training_pipeline)"]:::orchestrator
    %% External Services
    MongoDB[(MongoDB)]:::external
    %% Data Access
    DataAccess["Data Access Layer"]:::data
    %% Pipeline Stages
    Ingestion["Data Ingestion"]:::pipeline
    Validation["Data Validation"]:::pipeline
    Transformation["Data Transformation"]:::pipeline
    Training["Model Training"]:::pipeline
    Evaluation["Model Evaluation"]:::pipeline
    Pusher["Model Pusher"]:::pipeline
    %% Artifact Store
    ArtifactStore[(Artifact Store)]:::artifact
    %% Support Services
    subgraph "Support Services"
        ConfigSchema["Configuration Schema"]:::support
        AppConst["Application Constants"]:::support
        DBConst["Database Constants"]:::support
        EnvConst["Environment Constants"]:::support
        PipelineConst["Training Pipeline Constants"]:::support
        ArtifactEntity["Artifact Entity"]:::support
        ConfigEntity["Config Entity"]:::support
        ExceptionHandler["Exception Handler"]:::support
        LoggerService["Logging Service"]:::support
        Utils["Utility Functions"]:::support
        MetricComp["Metric Computation"]:::support
        Estimator["Estimator Abstraction"]:::support
        DockerConfig["Docker Config"]:::support
        Packaging["Dependencies & Packaging"]:::support
    end

    %% Flows
    main -->|"triggers"| Orchestrator
    MongoDB -->|"raw JSON docs"| DataAccess
    DataAccess -->|"raw DataFrame"| Ingestion
    Ingestion -->|"raw data"| Validation
    Validation -->|"validated DataFrame"| Transformation
    Transformation -->|"features"| Training
    Training -->|"trained model"| Evaluation
    Evaluation -->|"evaluation metrics"| Pusher
    Pusher -->|"model artifact"| ArtifactStore

    %% Support injections
    ConfigSchema --> Orchestrator
    AppConst --> Orchestrator
    DBConst --> Orchestrator
    EnvConst --> Orchestrator
    PipelineConst --> Orchestrator
    LoggerService --> Orchestrator
    ExceptionHandler --> Orchestrator
    Utils --> Orchestrator

    ConfigSchema --> Ingestion
    ConfigSchema --> Validation
    ConfigSchema --> Transformation
    ConfigSchema --> Training
    ConfigSchema --> Evaluation
    ConfigSchema --> Pusher

    LoggerService --> Ingestion
    LoggerService --> Validation
    LoggerService --> Transformation
    LoggerService --> Training
    LoggerService --> Evaluation
    LoggerService --> Pusher

    MetricComp --> Evaluation
    Estimator --> Training

    DockerConfig --> main
    Packaging --> main

    %% Click Events
    click main "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/main.py"
    click Orchestrator "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/pipeline/training_pipeline.py"
    click MongoDB "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/connection/mongodb_connection.py"
    click DataAccess "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/data_access/sensor_data.py"
    click Ingestion "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/components/data_ingestion.py"
    click Validation "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/components/data_validation.py"
    click Transformation "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/components/data_transformation.py"
    click Training "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/components/model_trainer.py"
    click Evaluation "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/components/model_evaluation.py"
    click Pusher "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/components/model_pusher.py"
    click ConfigSchema "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/config/schema.yaml"
    click AppConst "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/constant/application.py"
    click DBConst "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/constant/database.py"
    click EnvConst "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/constant/env_variables.py"
    click PipelineConst "https://github.com/codelb5/predictive_sensor_maintenance/tree/main/sensor/constant/training_pipeline/"
    click ArtifactEntity "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/entity/artifact_entity.py"
    click ConfigEntity "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/entity/config_entity.py"
    click ExceptionHandler "https://github.com/codelb5/predictive_sensor_maintenance/tree/main/sensor/exceptions/"
    click LoggerService "https://github.com/codelb5/predictive_sensor_maintenance/tree/main/sensor/logger/"
    click Utils "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/utils/main_utils.py"
    click MetricComp "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/ml/metric/classification_metric.py"
    click Estimator "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/sensor/ml/model/estimator.py"
    click DockerConfig "https://github.com/codelb5/predictive_sensor_maintenance/tree/main/Dockerfile"
    click Packaging "https://github.com/codelb5/predictive_sensor_maintenance/blob/main/requirements.txt"

    %% Styles
    classDef external fill:#F5A623,stroke:#333,stroke-width:1px
    classDef data fill:#4A90E2,stroke:#333,stroke-width:1px
    classDef pipeline fill:#50E3C2,stroke:#333,stroke-width:1px
    classDef orchestrator fill:#7ED321,stroke:#333,stroke-width:1px
    classDef support fill:#9B9B9B,stroke:#333,stroke-width:1px
    classDef cli fill:#BD10E0,stroke:#333,stroke-width:1px
    classDef artifact fill:#9013FE,stroke:#333,stroke-width:1px
```
