# udayk01/ids_using_cnn architecture

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

- Interactive diagram: https://gitdiagram.com/udayk01/ids_using_cnn
- Repository: https://github.com/udayk01/ids_using_cnn

## Overview

##### Project type and purpose (based on file tree + README)
This repository is a **research / prototype ML project** implemented as a **single Jupyter notebook** (`main.ipynb`). The README (`# IDS_Using_CNN`) implies the notebook builds a **CNN-based Intrusion Detection System (IDS)** model—likely training/evaluating a convolutional neural network on network traffic / IDS datasets.

Because there’s no `src/`, no packaged module, no API server, and no deployment config, the “system” here is best represented as an **ML pipeline** running inside a notebook environment, rather than a multi-service application.

##### What the file structure implies architecturally
Top-level:
- `main.ipynb`: contains *everything*—data loading, preprocessing, model definition, training, evaluation, maybe inference and plots.
- `README.md`: minimal.

- **Data source**: local CSV? Kaggle dataset? PCAP-derived features? Where does it load from?
- **Preprocessing**: normalization/scaling, encoding labels, train/test split, reshaping to CNN-friendly tensors.
- **Model**: framework (TensorFlow/Keras, PyTorch), CNN layers, loss, optimizer.
- **Training loop**: epochs, batch size, callbacks (early stopping, checkpoints).
- **Evaluation**: metrics (accuracy, precision/recall, F1, confusion matrix, ROC).
- **Outputs**: saved model file? figures? metrics printed only? any exported artifacts?

##### Execution Environment
- Jupyter Notebook Kernel (Python)
- Local machine / Colab runtime (depending on how it’s intended to run)

##### Dependencies / Libraries
- Data: `pandas`, `numpy`
- ML: `tensorflow.keras` or `torch` (whichever is used)
- Preprocessing/metrics: `scikit-learn`
- Visualization: `matplotlib` / `seaborn`

##### Data Layer
- Raw dataset source (e.g., CSV files on disk, downloaded dataset)
- Optional: any intermediate cleaned dataset (in-memory DataFrame)

##### Preprocessing Pipeline
- Cleaning / missing value handling
- Feature engineering (if any)
- Encoding labels
- Scaling/normalization
- Reshaping into CNN input format
- Train/validation/test split

##### Modeling Component
- CNN architecture definition
- Compile step (loss, optimizer)
- Training procedure (fit)
- Hyperparameters

##### Evaluation & Reporting
- Predictions on validation/test
- Metrics calculation
- Confusion matrix / ROC
- Plots/tables

##### Artifacts / Outputs
- Saved model (e.g., `.h5`, SavedModel, `.pt`) if present
- Saved scalers/encoders if present (critical for real inference)
- Exported charts or results

##### (Optional, if notebook includes it) Inference / IDS Usage Mode
- “New traffic feature vector” input
- Apply same preprocessing
- CNN inference
- Output class (benign/attack + type)

##### 4b) Determine relationships and interactions

Typical flows:
- Raw Dataset → Preprocessing → (X_train, y_train) → Training → Trained Model
- Trained Model + X_test → Evaluation → Metrics/Plots
- (Optional) New Data → Preprocessing (same fitted scaler/encoder) → Trained Model → Prediction

##### 4c) Highlight architectural patterns/design principles used
For this project, the relevant “architecture” is an **ML pipeline**:
- **Batch training** on historical labeled data
- **Separation of concerns (logical)** inside the notebook: preprocessing vs modeling vs evaluation
- **Artifact lineage**: dataset → features → model → metrics

##### 4d) Include key technologies/frameworks
- Python
- Jupyter
- TensorFlow/Keras or PyTorch
- scikit-learn
- pandas/numpy

##### High-level architecture (Context / Container-level)
- Jupyter Notebook (contains pipeline)
- Dataset (external input)
- Outputs (model/metrics)
- Optional: “Future deployment target” (not implemented)

- Break notebook into steps listed above
- Intermediate artifacts and reuse of preprocessing in inference

##### Don’t overthink it: maximize component separation
Even though it’s only one notebook file, for “best and most accurate” architecture, represent:
- each major pipeline stage as a distinct component,
- each key artifact (dataset, fitted scaler, trained model, metrics report),
- and explicitly separate **training-time** vs **inference-time** concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =========================
    %% Context / Container View
    %% =========================
    subgraph "Repository (Research Prototype)"
        Readme["Project Documentation (README)"]:::doc
        Notebook["ML Pipeline Orchestrator (Jupyter Notebook)"]:::notebook
    end

    subgraph "Execution Environment"
        Runtime["Python Runtime + Jupyter Kernel"]:::runtime
        Deps["Dependencies / Libraries\npandas,numpy\nTensorFlow/Keras|PyTorch\nscikit-learn\nmatplotlib|seaborn"]:::deps
    end

    Dataset[("Raw IDS Dataset (CSV/Files)\nExternal input")]:::data

    subgraph "Notebook Logical Pipeline (implemented as cell sequence)"
        direction TB

        subgraph "Training-Time Path (Batch)"
            direction TB
            Load["Data Loading (pandas read)\nDataFrame in-memory"]:::process
            Preprocess["Preprocessing\nclean/encode/scale/split/reshape"]:::process
            Split["Train/Val/Test Sets\n(X_train,y_train,...)\nTensors/arrays"]:::artifact
            ModelDef["CNN Model Definition\nlayers + compile (loss/optimizer)"]:::process
            Train["Training Procedure\nfit/epochs/batch/callbacks"]:::process
            TrainedModel[("Trained Model\n(in-memory / optional saved)")]:::model
            Transformers[("Fitted Preprocessors\nencoder/scaler\n(in-memory / optional saved)")]:::artifact
            Eval["Evaluation & Reporting\nmetrics,confusion-matrix,ROC\nplots/tables"]:::process
            Results[("Results / Plots / Metrics\n(optional exports)")]:::artifact
        end

        subgraph "Inference-Time Path (Optional / Future Usage)"
            direction TB
            NewTraffic[/"New Network Traffic Features"/]:::io
            InferPre["Preprocess (reuse fitted scaler/encoder)\nscale/encode/reshape"]:::process
            Predict["CNN Inference\npredict()"]:::process
            Output[/"Prediction\nNormal vs Attack (+ type)"/]:::io
        end

        subgraph "Future Deployment Boundary (Not Implemented)"
            direction TB
            Deploy["Deployment Target\n(API/Service/Edge agent)\n(dashed: not in repo)"]:::future
        end
    end

    %% =========================
    %% Flows
    %% =========================
    Readme -.->|"documents"| Notebook

    Notebook -->|"runs_on"| Runtime
    Notebook -->|"imports"| Deps

    Dataset -->|"loaded_into"| Load
    Load -->|"raw_df"| Preprocess
    Preprocess -->|"creates"| Split
    Preprocess -->|"fits"| Transformers

    Split -->|"X_train,y_train"| Train
    ModelDef -->|"builds"| Train
    Train -->|"produces"| TrainedModel

    Split -->|"X_test,y_test"| Eval
    TrainedModel -->|"used_by"| Eval
    Eval -->|"generates"| Results

    %% Inference (optional)
    NewTraffic -->|"input"| InferPre
    Transformers -.->|"reused_transformers"| InferPre
    InferPre -->|"features_tensor"| Predict
    TrainedModel -->|"loaded_or_in_memory"| Predict
    Predict -->|"outputs"| Output

    %% Future deployment boundary links
    TrainedModel -.->|"would_package"| Deploy
    Transformers -.->|"would_package"| Deploy

    %% =========================
    %% Click Events (from mapping)
    %% =========================
    click Readme "https://github.com/udayk01/ids_using_cnn/blob/main/README.md"
    click Notebook "https://github.com/udayk01/ids_using_cnn/blob/main/main.ipynb"
    click Runtime "https://github.com/udayk01/ids_using_cnn/blob/main/main.ipynb"
    click Deps "https://github.com/udayk01/ids_using_cnn/blob/main/main.ipynb"
    click Load "https://github.com/udayk01/ids_using_cnn/blob/main/main.ipynb"
    click Preprocess "https://github.com/udayk01/ids_using_cnn/blob/main/main.ipynb"
    click ModelDef "https://github.com/udayk01/ids_using_cnn/blob/main/main.ipynb"
    click Train "https://github.com/udayk01/ids_using_cnn/blob/main/main.ipynb"
    click Eval "https://github.com/udayk01/ids_using_cnn/blob/main/main.ipynb"
    click Predict "https://github.com/udayk01/ids_using_cnn/blob/main/main.ipynb"
    click Results "https://github.com/udayk01/ids_using_cnn/blob/main/main.ipynb"

    %% =========================
    %% Styles
    %% =========================
    classDef doc fill:#FFF7D6,stroke:#B58B00,color:#2B2000,stroke-width:1px
    classDef notebook fill:#E9D8FF,stroke:#6B46C1,color:#1A103D,stroke-width:1px
    classDef runtime fill:#D7F1FF,stroke:#1E88A8,color:#06242D,stroke-width:1px
    classDef deps fill:#DFF7E8,stroke:#2E7D32,color:#0B2A12,stroke-width:1px
    classDef data fill:#FFE0E0,stroke:#C62828,color:#3A0B0B,stroke-width:1px
    classDef process fill:#E3F2FD,stroke:#1565C0,color:#08233F,stroke-width:1px
    classDef artifact fill:#F3E5F5,stroke:#7B1FA2,color:#2A0B33,stroke-width:1px
    classDef model fill:#E8F5E9,stroke:#1B5E20,color:#0A1F0D,stroke-width:1px
    classDef io fill:#FFF3E0,stroke:#EF6C00,color:#3A1A00,stroke-width:1px
    classDef future fill:#FFFFFF,stroke:#616161,color:#212121,stroke-width:1px,stroke-dasharray: 6 4
```
