# tanish-sarkar/network-intrusion-detection-system architecture

> Architecture diagram of the GitHub repository tanish-sarkar/network-intrusion-detection-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tanish-sarkar/network-intrusion-detection-system
- Repository: https://github.com/tanish-sarkar/network-intrusion-detection-system

## Overview

##### Project type and purpose
- This is a data‐science/ML pipeline project for unsupervised learning on high-dimensional data.
- It implements clustering (K-Means, DBSCAN, Agglomerative), dimensionality reduction (PCA, t-SNE, UMAP), and anomaly detection (Isolation Forest, LOF).

##### File structure
- Top level:
- data/ (raw and processed CSVs)
- src/ (modular code: data_loader.py, preprocessing.py, dimensionality.py, clustering.py, anomaly.py, utils.py)
- notebooks/ (Jupyter notebooks for EDA, clustering, dimensionality reduction, anomaly detection)
- outputs/ (saved models in joblib, plots)
- main.py (pipeline orchestrator)
- requirements.txt lists dependencies (Pandas, NumPy, scikit-learn, Matplotlib/Seaborn/Plotly).
- README.rst describes project goals, techniques, dataset, and outcome.

##### README for architecture insights
- Modular Python codebase with clear separation: data processing, dimensionality reduction, clustering, anomaly detection.
- Emphasis on reproducibility and scalability.

1. Data Sources
- Raw files (Train_data.csv, Test_data.csv)
2. Data Loader (src/data_loader.py)
3. Preprocessing (src/preprocessing.py)
- Cleaning, scaling, encoding
4. Dimensionality Reduction (src/dimensionality.py)
- PCA, t-SNE, UMAP
5. Clustering Module (src/clustering.py)
- KMeans, DBSCAN, Agglomerative
6. Anomaly Detection Module (src/anomaly.py)
- Isolation Forest, LOF
7. Model Persistence (joblib via src/utils.py)
8. Visualization / Reporting
- Matplotlib/Seaborn/Plotly & notebooks
9. Notebooks Layer (notebooks/*.ipynb) for EDA and interactive analysis
10. Outputs (models/, plots/)

- Raw Data → Data Loader → Preprocessing →
→ [branch] → Dimensionality Reduction → Clustering → Model Persistence → Outputs/models
→ Anomaly Detection → Model Persistence → Outputs/models
- Preprocessed & Reduced data → Visualization → Outputs/plots
- Notebooks import modules from src to reproduce each step interactively.
- main.py orchestrates end-to-end pipeline by calling each component sequentially.

c. Architectural patterns & principles:
- Pipeline pattern: each stage is a standalone module; data flows in a linear sequence with branches for clustering vs. anomaly detection.
- Separation of concerns: data I/O, preprocessing, feature transformation, modeling, persistence, and visualization are decoupled.
- Reproducibility: main.py + modular code + notebooks + outputs directory.

d. Key technologies & frameworks:
- Python modules in src/
- Pandas, NumPy for data manipulation
- Scikit-learn for algorithms
- Joblib (via src/utils.py) for model persistence
- Matplotlib/Seaborn/Plotly for plotting
- Jupyter Notebooks for exploration

##### Key points to capture
- Both batch pipeline (main.py) and interactive notebooks.
- Model training vs. model saving vs. visualization.
- Keep it detailed but focused on the true flow of data and responsibilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Orchestrator
    main["main.py (Pipeline Orchestrator)"]:::orchestrator
    click main "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/main.py"

    %% Data Sources
    subgraph "Data Sources" 
        direction TB
        RawTrain(("Train_data.csv")):::data
        RawTest(("Test_data.csv")):::data
    end
    click RawTrain "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/data/raw/Train_data.csv"
    click RawTest "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/data/raw/Test_data.csv"

    %% Batch Pipeline
    subgraph "Batch Pipeline"
        direction TB
        DL["Data Loader"]:::processing
        click DL "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/src/data_loader.py"
        PP["Preprocessing Module"]:::processing
        click PP "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/src/preprocessing.py"
        DR["Dimensionality Reduction"]:::processing
        click DR "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/src/dimensionality.py"
        CL["Clustering Module"]:::modeling
        click CL "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/src/clustering.py"
        AD["Anomaly Detection Module"]:::modeling
        click AD "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/src/anomaly.py"
        MP["Model Persistence"]:::persistence
        click MP "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/src/utils.py"
        ProcData[("Processed Data Store")]:::data
        click ProcData "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/data/processed/processed_data.csv"
        subgraph "Model Outputs"
            direction TB
            KMeans["KMeansModel.joblib"]:::persistence
            click KMeans "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/outputs/models/KMeansModel.joblib"
            DBSCAN["DBSCANModel.joblib"]:::persistence
            click DBSCAN "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/outputs/models/DBSCANModel.joblib"
            Agglo["AgglomerativeModel.joblib"]:::persistence
            click Agglo "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/outputs/models/AgglomerativeModel.joblib"
        end
        subgraph "Plots Output"
            direction TB
            Plots[/Plots Directory/]:::visual
            click Plots "https://github.com/tanish-sarkar/network-intrusion-detection-system/tree/main/outputs/plots"
        end
    end

    %% Visualization & Reporting
    subgraph "Notebooks Layer" 
        direction TB
        NB1["01_eda.ipynb"]:::notebook
        click NB1 "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/notebooks/01_eda.ipynb"
        NB2["02_clustering.ipynb"]:::notebook
        click NB2 "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/notebooks/02_clustering.ipynb"
        NB3["03_dim_reduction.ipynb"]:::notebook
        click NB3 "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/notebooks/03_dim_reduction.ipynb"
        NB4["04_anomaly_detection.ipynb"]:::notebook
        click NB4 "https://github.com/tanish-sarkar/network-intrusion-detection-system/blob/main/notebooks/04_anomaly_detection.ipynb"
    end

    %% Data Flow
    main --> DL
    RawTrain --> DL
    RawTest --> DL
    DL --> PP
    PP --> ProcData
    ProcData --> DR
    ProcData --> AD
    DR --> CL
    CL --> MP
    AD --> MP
    MP --> KMeans
    MP --> DBSCAN
    MP --> Agglo
    DR --> Plots
    PP --> Plots
    Plots --> Plots

    %% Notebooks dependencies
    NB1 --> DL
    NB1 --> PP
    NB1 --> ProcData
    NB2 --> CL
    NB3 --> DR
    NB4 --> AD

    %% Styles
    classDef data fill:#bfdbfe,stroke:#3b82f6,color:#1e40af
    classDef processing fill:#bbf7d0,stroke:#22c55e,color:#166534
    classDef modeling fill:#fed7aa,stroke:#f97316,color:#7c2d12
    classDef persistence fill:#e9d5ff,stroke:#a855f7,color:#581c87
    classDef visual fill:#cffafe,stroke:#06b6d4,color:#075985
    classDef notebook fill:#f3f4f6,stroke:#9ca3af,color:#374151
    classDef orchestrator fill:#fce7f3,stroke:#ec4899,color:#9d174d
```
