# must0mar/network-traffic-anomaly-detection architecture

> Architecture diagram of the GitHub repository must0mar/network-traffic-anomaly-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/must0mar/network-traffic-anomaly-detection
- Repository: https://github.com/must0mar/network-traffic-anomaly-detection

## Overview

##### Main Components
- Data Collection & Preprocessing:
- Component: Capture_Detection.py
- Role: Captures network traffic data (normal and potentially malicious) using tools like tshark (as mentioned in the README). It also handles initial preprocessing and feature extraction from the raw packet data.
- Machine Learning Model:
- Component: AnomalyDetectionModel.joblib
- Role: Represents the trained model that classifies packets as normal or anomalous. This is the core of the AI-based detection.
- Notification/Guidance Module:
- Component: Email.py and associated configuration (emails.json, alert.json)
- Role: After detection, this module sends alerts or recommendations to the user via email. This aligns with the “User Guidance” objective in the README.
- API/Endpoint:
- Component: Endpoint.go (with go.mod and go.sum for dependency management)
- Role: Likely provides a backend API that interfaces with the detection service and serves results to the front-end, enabling integration and real-time communication.
- User Interface:
- Components: Files in the “Front-End” directory – index.html, email.html, Script.js, Styles.css.
- Role: Provides a user-friendly interface where users can view real-time monitoring data, alerts, and recommendations. It acts as the dashboard layer of the system.
- Supplementary/Logging:
- Files such as network_traffic_summary.json and packet_errors.log help track system outputs and errors, contributing to logging, monitoring, and offline analyses.

##### Interactions and Relationships
- Data Flow:
- Real-time network data (normal and anomalous) is captured by Capture_Detection.py.
- Preprocessed data is then fed into the ML module (AnomalyDetectionModel.joblib) for analysis.
- The ML module outputs classification results, which are then passed to an alert/notification system.
- Notification Flow:
- Email.py takes the detection result and triggers appropriate user notifications (using preconfigured details from alert.json or emails.json).
- API & UI Integration:
- The Endpoint.go component functions as the bridge between the backend processing and the front-end dashboard.
- The Front-End communicates with Endpoint.go via HTTP calls (or similar protocols) to display real-time results, alerts, network summaries, etc.
- Logging & Monitoring:
- Files like packet_errors.log and network_traffic_summary.json are updated continuously to provide logs and summaries, helping both in debugging and in performance monitoring of the system.

##### Architectural Patterns & Design Principles
- Layered Architecture:
- The design clearly separates data collection and processing, model inference, and user interaction which is a common pattern in full-stack systems.
- Real-Time Processing:
- Microservice/Modular Approach:
- Use of External Data and Communication:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        DS("Network Data Sources"):::external
    end

    %% Processing Layer
    subgraph "Processing Layer"
        CD("Data Capture & Preprocessing (Capture_Detection.py)"):::python
        AD("Anomaly Detection (ML Model - AnomalyDetectionModel.joblib)"):::python
    end

    %% Notification & API Layer
    subgraph "Notification & API Layer"
        subgraph "Notification Module"
            E1("Email.py"):::notification
            E2("alert.json"):::notification
            E3("emails.json"):::notification
        end
        EP("API/Endpoint (Endpoint.go)"):::go
    end

    %% Presentation/UI Layer
    subgraph "Presentation/UI Layer"
        subgraph "User Interface (Front-End)"
            UI1("index.html"):::frontend
            UI2("email.html"):::frontend
            UI3("Script.js"):::frontend
            UI4("Styles.css"):::frontend
        end
    end

    %% Supplementary/Logging Layer
    subgraph "Supplementary/Logging"
        LOG1("network_traffic_summary.json"):::logging
        LOG2("packet_errors.log"):::logging
    end

    %% Data Flow Connections
    DS -->|"captures"| CD
    CD -->|"preprocesses"| AD
    AD -->|"sends alert to"| E1
    AD -->|"sends alert to"| E2
    AD -->|"sends alert to"| E3
    AD -->|"updates"| LOG1
    CD -->|"logs"| LOG2
    AD -->|"provides data"| EP
    EP -->|"serves data"| UI1
    EP -->|"serves data"| UI2
    EP -->|"serves data"| UI3
    EP -->|"serves data"| UI4

    %% Click Events for Component Mapping
    click CD "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/Capture_Detection.py"
    click AD "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/AnomalyDetectionModel.joblib"
    click E1 "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/Email.py"
    click E2 "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/alert.json"
    click E3 "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/emails.json"
    click EP "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/Endpoint.go"
    click UI1 "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/Front-End/index.html"
    click UI2 "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/Front-End/email.html"
    click UI3 "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/Front-End/Script.js"
    click UI4 "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/Front-End/Styles.css"
    click LOG1 "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/network_traffic_summary.json"
    click LOG2 "https://github.com/must0mar/network-traffic-anomaly-detection/blob/main/packet_errors.log"

    %% Styles
    classDef external fill:#E2E3E5,stroke:#333,stroke-width:2px;
    classDef python fill:#D1E8FF,stroke:#333,stroke-width:2px;
    classDef notification fill:#FFD8B1,stroke:#333,stroke-width:2px;
    classDef go fill:#D4FFC8,stroke:#333,stroke-width:2px;
    classDef frontend fill:#FFF7BC,stroke:#333,stroke-width:2px;
    classDef logging fill:#F8D7DA,stroke:#333,stroke-width:2px;
```
