# eldrago12/nids architecture

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

- Interactive diagram: https://gitdiagram.com/eldrago12/nids
- Repository: https://github.com/eldrago12/nids

## Overview

##### Project Type and Purpose
- The project is a machine learning–based Network Intrusion Detection System.
- It leverages an optimized deep learning setup – combining both CNN-LSTM for sequence modeling and pretrained transformer models (BERT and a variant labeled “roberta”) – to analyze network traffic. In addition, it integrates SHAP (SHapley Additive exPlanations) for model interpretability.
- The readme title “NIDS - Network Intrusion Detection System using optimized CNN-LSTM and BERT architecture with SHAP” makes its purpose and innovative deep learning approach clear.

##### Analyzing the File Structure
- Top-level files include:
– DGX_Instructions.rtf: Likely contains details about running the project on DGX hardware (a dedicated deep learning cluster), indicating possible hardware-related deployment considerations.
– LICENSE and README.md: Standard documentation.
– Script files: bert_training.py, roberta_training.py, and shap_eval.py, plus corresponding log files (bert_training.log, roberta_training.log).
- There isn’t an explicit “frontend” or “backend” split since the main focus is on model training and evaluation scripts, which points toward a research/ML experimental design rather than a full-stack application.

##### Core Components
a. Data/Preprocessing Module (Implied):
– Although not directly represented in the file tree, a network intrusion detection system typically begins with data pre-processing (ingesting and preparing network traffic data). If this module exists within your codebase (or is external), indicate it.

b. Model Training Modules:
– CNN-LSTM Module: Referenced in the README. This part of the architecture is responsible for capturing sequence dynamics from network data. Although not specifically a separate file, it’s an architectural element likely integrated into one or both training scripts.
– BERT (and potentially Roberta) Module: Represented by bert_training.py and roberta_training.py. These components use transformer-based architectures to learn patterns relevant to network intrusions.
– Note the CNN-LSTM component might be merged with these scripts as an “optimized” architecture, so clarify if these modules work in tandem or if there are alternative training paths available.

c. SHAP Evaluation Module:
– shap_eval.py is dedicated to evaluating the predictions of the models using SHAP for interpretability. This component probably takes the output of the trained model(s) and runs SHAP-based analysis to explain prediction contributions.

d. Infrastructure/Deployment Considerations:
– DGX_Instructions.rtf indicates specific instructions for running or deploying the system on DGX hardware, so include a note or node for the hardware/infrastructure layer.

##### Relationships and Interactions
- Data flows from a (possibly external) data ingestion and preprocessing module into the model training components.
- Both the CNN-LSTM core and transformer-based (BERT/Roberta) modules may either work in parallel or be combined in a sequential pipeline for final detection.
- The outputs (model predictions or learned representations) flow to the SHAP evaluation module for interpretability.
- Logs (bert_training.log, roberta_training.log) can be shown as supplementary output channels that monitor training progress.

##### Key Architectural Patterns and Technologies
- Integration of deep learning architectures (CNN-LSTM for sequential data and transformer models for contextual analysis).
- Modularity: Separate scripts for different model training pathways and evaluation, emphasizing the decoupled nature of training and interpretability.
- Use of advanced evaluation tools (SHAP) to understand model decisions, which is critical in security-sensitive environments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    A["Data/Ingestion & Preprocessing"]:::dat
    
    %% Model Training Modules
    subgraph "Model Training Modules"
        direction TB
        B["CNN-LSTM Module (Optimized Deep Learning)"]:::ml
        subgraph "Transformer Modules"
            direction TB
            C["BERT Training Module"]:::ml
            E["BERT Training Log"]:::log
            D["Roberta Training Module"]:::ml
            F["Roberta Training Log"]:::log
        end
    end
    
    %% Evaluation Module
    G["SHAP Evaluation Module"]:::eval

    %% Infrastructure / Deployment
    H["DGX Hardware/Deployment Instructions"]:::infra

    %% Data Flow Connections
    A -->|"feeds"| B
    A -->|"feeds"| C
    A -->|"feeds"| D
    B -->|"modelOutput"| G
    C -->|"modelOutput"| G
    D -->|"modelOutput"| G

    %% Log connections
    C -->|"logs"| E
    D -->|"logs"| F

    %% Infrastructure connection
    H -->|"guidesDeployment"| A

    %% Click Events for Component Mapping
    click C "https://github.com/eldrago12/nids/blob/main/bert_training.py"
    click D "https://github.com/eldrago12/nids/blob/main/roberta_training.py"
    click E "https://github.com/eldrago12/nids/blob/main/bert_training.log"
    click F "https://github.com/eldrago12/nids/blob/main/roberta_training.log"
    click G "https://github.com/eldrago12/nids/blob/main/shap_eval.py"
    click H "https://github.com/eldrago12/nids/blob/main/DGX_Instructions.rtf"

    %% Styles and Legend
    classDef dat fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef ml  fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef eval fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef infra fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef log  fill:#F5CBA7,stroke:#AF601A,stroke-width:2px;

    %% Legend (Informational Node)
    subgraph "Legend"
        LD1["Data/Ingestion & Preprocessing (Light Blue)"]
        LM1["Model Training Modules (Yellow)"]
        LE1["SHAP Evaluation Module (Green)"]
        LI1["Infrastructure/Deployment (Lavender)"]
        LL1["Log Files (Peach)"]
    end
    style LD1 fill:#AED6F1,stroke:#1B4F72,stroke-width:1px, font-size:10px
    style LM1 fill:#F9E79F,stroke:#B9770E,stroke-width:1px, font-size:10px
    style LE1 fill:#A9DFBF,stroke:#196F3D,stroke-width:1px, font-size:10px
    style LI1 fill:#D7BDE2,stroke:#6C3483,stroke-width:1px, font-size:10px
    style LL1 fill:#F5CBA7,stroke:#AF601A,stroke-width:1px, font-size:10px
```
