# hetshah1432/intrusion-detection-system architecture

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

- Interactive diagram: https://gitdiagram.com/hetshah1432/intrusion-detection-system
- Repository: https://github.com/hetshah1432/intrusion-detection-system

## Overview

##### Project Type and Purpose
- The project is a network security application that combines network scanning (to detect active devices and open ports) with anomaly detection (using an Isolation Forest model).
- It also integrates external tools (Wireshark, Snort/Suricata) for packet analysis, suggesting that some components interact with external systems to enhance security analysis.

##### Analyzing the File Structure
- At the top level, you have key directories:
– "data": Stores scan results and log files.
– "models": Contains the trained machine learning model (anomaly_detector.pkl).
– "scripts": Contains core scripts such as network_scanner.py, port_scanner.py, and anomaly_detection.py.
– "main.py": Acts as the main entry point that triggers different operations (scanning vs. detection).
- Configuration (requirements.txt) and licensing/documentation files round out the project, but the core architectural components reside in the main script, scripts, data, and models directories.

##### Components
a. Main Application/Controller:
– Represent main.py as the entry point that routes commands (e.g., --scan and --detect) to the appropriate modules.
b. Network Scanning Modules:
– Identify two main scanning components in the scripts folder:
- network_scanner.py: For discovering active devices.
- port_scanner.py: For determining open ports.
– Illustrate how these modules feed raw network data into the system.
c. Anomaly Detection Module:
– Highlight anomaly_detection.py which uses an Isolation Forest model.
– Show the dependency on the saved model (anomaly_detector.pkl in the models directory).
– Indicate that this module processes network scan data to detect suspicious patterns.
d. Data Handling:
– Include the “data” directory that holds CSV files (network_scan_data.csv, port_scan_results.csv) acting as persistent storage for scan results.
– Optionally note where logs may eventually reside (as per README, even if the current file tree doesn’t include a 'logs' directory).
e. External Tools / Integrations:

##### Relationships and Data Flow
- If applicable, include feedback loops for real-time monitoring, where detected anomalies may trigger further scans or alerts.

##### Architectural Patterns and Design Principles
- Modularity by defining separate components for scanning, anomaly detection, and data handling.
- Use of a machine learning pipeline where raw network data is processed and fed into a pre-trained model for anomaly detection.
- That the design follows a clear separation of concerns: scanning responsibilities are isolated from the detection logic and external tool interfacing.
- Although it’s a relatively simple architecture, it demonstrates a layered approach (input → processing → storage → alerting).

## Diagram (Mermaid)

```mermaid
flowchart TD
    U("User/CLI"):::user
    M("Main Controller (main.py)"):::core
    U -->|"invoke"| M

    subgraph "Scanning Modules"
        SCN("Network Scanner (scripts/network_scanner.py)"):::core
        PSCN("Port Scanner (scripts/port_scanner.py)"):::core
    end

    AD("Anomaly Detection (scripts/anomaly_detection.py)"):::core
    DS("Data Storage (data/)"):::data
    MODEL("Isolation Forest Model (models/anomaly_detector.pkl)"):::core

    M -->|"execute"| SCN
    M -->|"execute"| PSCN
    M -->|"execute"| AD

    SCN -->|"store"| DS
    PSCN -->|"store"| DS
    SCN -->|"send"| AD
    PSCN -->|"send"| AD

    AD -->|"load"| MODEL

    subgraph "External Tools"
        W("Wireshark"):::external
        S("Snort/Suricata"):::external
    end

    AD -->|"alert"| W
    AD -->|"alert"| S

    click M "https://github.com/hetshah1432/intrusion-detection-system/blob/main/main.py"
    click SCN "https://github.com/hetshah1432/intrusion-detection-system/blob/main/scripts/network_scanner.py"
    click PSCN "https://github.com/hetshah1432/intrusion-detection-system/blob/main/scripts/port_scanner.py"
    click AD "https://github.com/hetshah1432/intrusion-detection-system/blob/main/scripts/anomaly_detection.py"
    click DS "https://github.com/hetshah1432/intrusion-detection-system/tree/main/data/"
    click MODEL "https://github.com/hetshah1432/intrusion-detection-system/blob/main/models/anomaly_detector.pkl"

    classDef user fill:#B0E0E6,stroke:#333,stroke-width:2px;
    classDef core fill:#DAF7A6,stroke:#333,stroke-width:2px;
    classDef data fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef external fill:#FF5733,stroke:#333,stroke-width:2px;
```
