# ainilaha/ppl_car_hacking architecture

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

- Interactive diagram: https://gitdiagram.com/ainilaha/ppl_car_hacking
- Repository: https://github.com/ainilaha/ppl_car_hacking

## Overview

##### Main Components
- Data Source & Ingestion:
- A “data” folder (as per the README instructions) where the Car-Hacking Dataset is saved.
- Data Preprocessing & Conversion:
- A preprocessing step where raw textual data (attack-free traffic) is transformed into CSV format (the README details commands with sed).
- Analysis Modules (Notebooks):
- Notebooks for different parts of the analysis:
- bayesian_net.ipynb (focuses on deep Bayesian network modeling),
- int_data_small.ipynb and bin_data_small.ipynb (likely used for exploring and processing the intrusion/attack data),
- int_pyspark.ipynb (shows Spark-based processing, hinting at handling larger-scale data).
- Utility Module:
- ppl_util.py serves as a helper file with utility functions that support the notebooks.
- Environment/Dependencies:
- Two distinct environment setups: one leveraging TensorFlow (tensorflow-gpu and tensorflow-probability) and another using PyTorch (with pyro-ppl and gpytorch).

##### Component Relationships & Interactions
- Data Flow:
- Then pass the data through a preprocessing module (including text-to-CSV conversion).
- Analysis Pipeline:
- The processed data is consumed by various notebooks to perform different processing or modeling tasks. They might be executed sequentially or in parallel, depending on the analysis path.
- The "ppl_util.py" acts as a shared resource that provides common functionality to all notebooks.
- Environment Selection:
- Depending on the analysis pipeline chosen (TensorFlow vs PyTorch), the subsequent machine learning model training will utilize one of the two sets of dependencies.

##### Important Architectural Patterns or Principles
- Modularity:
- Separate processing responsibilities are divided among different notebooks and utility modules.
- Flexibility/Extensibility:
- The design supports multiple ML frameworks with two independent environments, showing extensibility in the choice of backend.
- Data-Centric Flow:
- The architecture follows a straightforward pipeline that begins at data ingestion, continues with preprocessing, and culminates in analytical model building.

##### Relevant Technologies & Libraries
- Data Processing: Use of Python libraries such as pandas, numpy, matplotlib, and sklearn.
- Deep Learning & Bayesian Inference:
- TensorFlow-based approach with tensorflow-gpu and tensorflow-probability.
- PyTorch-based approach with pytorch, pyro-ppl, and gpytorch.
- Distributed Data Processing: Presence of int_pyspark.ipynb suggests the use of Apache Spark for handling larger datasets.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Pipeline
    subgraph "Data Pipeline"
        DS["Raw Car-Hacking Dataset (data folder)"]:::dataStyle
        DP["Preprocessing: Text-to-CSV Conversion"]:::dataStyle
        DS --> DP
        RD["README.md (Project Overview & Environment Setup)"]:::dataStyle
        RD --- DP
    end

    %% Analysis Pipeline
    subgraph "Analysis Pipeline"
        subgraph "Notebooks"
            BN["bayesian_net.ipynb (Bayesian Modeling)"]:::analysisStyle
            ID["int_data_small.ipynb (Intrusion Data EDA)"]:::analysisStyle
            BD["bin_data_small.ipynb (Binary Data EDA)"]:::analysisStyle
            SP["int_pyspark.ipynb (Spark-based Processing)"]:::analysisStyle
        end
        UT["ppl_util.py (Utility Module)"]:::analysisStyle
        %% Data Flow from Preprocessing to Notebooks
        DP --> BN
        DP --> ID
        DP --> BD
        DP --> SP
        %% Utility Module supports all notebooks
        UT -.-> BN
        UT -.-> ID
        UT -.-> BD
        UT -.-> SP

        %% Note on execution flexibility
        NOTE["Note: Notebooks can be executed individually or as an integrated pipeline"]:::analysisStyle

        %% ML Model Training aggregation
        MLT["ML Model Training"]:::analysisStyle

        %% Connect notebooks to model training process
        BN --> MLT
        ID --> MLT
        BD --> MLT
        SP --> MLT

        %% Connect note to model training for clarity
        NOTE --- MLT
    end

    %% ML Frameworks
    subgraph "ML Frameworks"
        TF["TensorFlow Environment"]:::envStyle
        PT["PyTorch Environment"]:::envStyle
        MLT --> TF
        MLT --> PT
    end

    %% Click Events
    click BN "https://github.com/ainilaha/ppl_car_hacking/blob/main/bayesian_net.ipynb"
    click ID "https://github.com/ainilaha/ppl_car_hacking/blob/main/int_data_small.ipynb"
    click BD "https://github.com/ainilaha/ppl_car_hacking/blob/main/bin_data_small.ipynb"
    click SP "https://github.com/ainilaha/ppl_car_hacking/blob/main/int_pyspark.ipynb"
    click UT "https://github.com/ainilaha/ppl_car_hacking/blob/main/ppl_util.py"
    click RD "https://github.com/ainilaha/ppl_car_hacking/blob/main/README.md"

    %% Styling
    classDef dataStyle fill:#ffe6e6,stroke:#8B0000,stroke-width:2px;
    classDef analysisStyle fill:#e6f7ff,stroke:#005073,stroke-width:2px;
    classDef envStyle fill:#e6ffe6,stroke:#228B22,stroke-width:2px;
```
