# as-fe/ml4iot architecture

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

- Interactive diagram: https://gitdiagram.com/as-fe/ml4iot
- Repository: https://github.com/as-fe/ml4iot

## Overview

This repository is an IoT network intrusion-detection demo: users upload a CSV, choose CatBoost or CNN, and receive predicted traffic labels. The Flask handler owns CSV loading, model selection, preprocessing, inference, and result formatting. Saved models and preprocessing assets support that runtime; training notebooks document model and data-splitting work. The referenced HTML template and upload directory are absent from the supplied tree, so they are not represented as repository components.

Main entry points: [`app/app.py`](https://github.com/as-fe/ml4iot/blob/main/app/app.py) (Flask upload and results), [`app/models/catboost_model.cbm`](https://github.com/as-fe/ml4iot/blob/main/app/models/catboost_model.cbm) (CatBoost classifier), [`app/models/cnn_model.keras`](https://github.com/as-fe/ml4iot/blob/main/app/models/cnn_model.keras) (CNN model), [`app/preprocessing/label_encoders.pkl`](https://github.com/as-fe/ml4iot/blob/main/app/preprocessing/label_encoders.pkl) (Label encoders)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Flask prediction app"]
  node_web["Flask upload and results<br/>[app.py]"]
  node_catprep["CatBoost preprocessing<br/>[app.py]"]
  node_cnnprep["CNN preprocessing<br/>[app.py]"]
end

subgraph group_assets["Models and preprocessing"]
  node_catmodel["CatBoost classifier<br/>[catboost_model.cbm]"]
  node_cnnmodel["CNN model<br/>[cnn_model.keras]"]
  node_encoders["Label encoders<br/>[label_encoders.pkl]"]
  node_scaler["Feature scaler<br/>[scaler.pkl]"]
  node_target["Target encoder<br/>[target_encoder.pkl]"]
  node_catfeatures["CatBoost feature indices"]
end

subgraph group_training["Model development"]
  node_cnntrain["CNN training<br/>[CNN.ipynb]"]
  node_cattrain["CatBoost training"]
  node_split["Data splitting"]
end

node_user(("CSV uploader"))

node_user -->|"uploads CSV"| node_web
node_web -->|"preprocesses for"| node_catprep
node_web -->|"preprocesses for"| node_cnnprep
node_web -->|"loads and predicts"| node_catmodel
node_web -->|"loads and predicts"| node_cnnmodel
node_web -->|"loads"| node_encoders
node_web -->|"loads"| node_scaler
node_web -->|"loads"| node_target
node_web -->|"loads"| node_catfeatures
node_cnnprep -->|"transforms categories"| node_encoders
node_cnnprep -->|"scales features"| node_scaler
node_web -->|"decodes CNN labels"| node_target
node_web -->|"returns predictions"| node_user
node_cnntrain -.->|"trains model"| node_cnnmodel
node_cattrain -.->|"trains model"| node_catmodel

click node_web "https://github.com/as-fe/ml4iot/blob/main/app/app.py"
click node_catprep "https://github.com/as-fe/ml4iot/blob/main/app/app.py"
click node_cnnprep "https://github.com/as-fe/ml4iot/blob/main/app/app.py"
click node_catmodel "https://github.com/as-fe/ml4iot/blob/main/app/models/catboost_model.cbm"
click node_cnnmodel "https://github.com/as-fe/ml4iot/blob/main/app/models/cnn_model.keras"
click node_encoders "https://github.com/as-fe/ml4iot/blob/main/app/preprocessing/label_encoders.pkl"
click node_scaler "https://github.com/as-fe/ml4iot/blob/main/app/preprocessing/scaler.pkl"
click node_target "https://github.com/as-fe/ml4iot/blob/main/app/preprocessing/target_encoder.pkl"
click node_catfeatures "https://github.com/as-fe/ml4iot/blob/main/app/preprocessing/catboost_categorical_features.pkl"
click node_cnntrain "https://github.com/as-fe/ml4iot/blob/main/training_files/CNN.ipynb"
click node_cattrain "https://github.com/as-fe/ml4iot/blob/main/training_files/CatBoostClassifier.ipynb"
click node_split "https://github.com/as-fe/ml4iot/blob/main/training_files/Data_splitting.ipynb"

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_web,node_catprep,node_cnnprep toneBlue
class node_catmodel,node_cnnmodel,node_encoders,node_scaler,node_target,node_catfeatures toneAmber
class node_cnntrain,node_cattrain,node_split toneMint
class node_user toneIndigo
```

## Components

### Flask prediction app

- [Flask upload and results](https://github.com/as-fe/ml4iot/blob/main/app/app.py): `app/app.py`
- [CatBoost preprocessing](https://github.com/as-fe/ml4iot/blob/main/app/app.py): `app/app.py`
- [CNN preprocessing](https://github.com/as-fe/ml4iot/blob/main/app/app.py): `app/app.py`

### Models and preprocessing

- [CatBoost classifier](https://github.com/as-fe/ml4iot/blob/main/app/models/catboost_model.cbm): `app/models/catboost_model.cbm`
- [CNN model](https://github.com/as-fe/ml4iot/blob/main/app/models/cnn_model.keras): `app/models/cnn_model.keras`
- [Label encoders](https://github.com/as-fe/ml4iot/blob/main/app/preprocessing/label_encoders.pkl): `app/preprocessing/label_encoders.pkl`
- [Feature scaler](https://github.com/as-fe/ml4iot/blob/main/app/preprocessing/scaler.pkl): `app/preprocessing/scaler.pkl`
- [Target encoder](https://github.com/as-fe/ml4iot/blob/main/app/preprocessing/target_encoder.pkl): `app/preprocessing/target_encoder.pkl`
- [CatBoost feature indices](https://github.com/as-fe/ml4iot/blob/main/app/preprocessing/catboost_categorical_features.pkl): `app/preprocessing/catboost_categorical_features.pkl`

### Model development

- [CNN training](https://github.com/as-fe/ml4iot/blob/main/training_files/CNN.ipynb): `training_files/CNN.ipynb`
- [CatBoost training](https://github.com/as-fe/ml4iot/blob/main/training_files/CatBoostClassifier.ipynb): `training_files/CatBoostClassifier.ipynb`
- [Data splitting](https://github.com/as-fe/ml4iot/blob/main/training_files/Data_splitting.ipynb): `training_files/Data_splitting.ipynb`

### Other components

- **CSV uploader**

## Connections

- CSV uploader → Flask upload and results: uploads CSV (evidence: `README.md`)
- Flask upload and results → CatBoost preprocessing: preprocesses for (evidence: `app/app.py`)
- Flask upload and results → CNN preprocessing: preprocesses for (evidence: `app/app.py`)
- Flask upload and results → CatBoost classifier: loads and predicts (evidence: `app/app.py`)
- Flask upload and results → CNN model: loads and predicts (evidence: `app/app.py`)
- Flask upload and results → Label encoders: loads (evidence: `app/app.py`)
- Flask upload and results → Feature scaler: loads (evidence: `app/app.py`)
- Flask upload and results → Target encoder: loads (evidence: `app/app.py`)
- Flask upload and results → CatBoost feature indices: loads (evidence: `app/app.py`)
- CNN preprocessing → Label encoders: transforms categories (evidence: `app/app.py`)
- CNN preprocessing → Feature scaler: scales features (evidence: `app/app.py`)
- Flask upload and results → Target encoder: decodes CNN labels (evidence: `app/app.py`)
- Flask upload and results → CSV uploader: returns predictions (evidence: `README.md`)
- CNN training → CNN model: trains model
- CatBoost training → CatBoost classifier: trains model
