# hoangnv2001/real-time-ids architecture

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

- Interactive diagram: https://gitdiagram.com/hoangnv2001/real-time-ids
- Repository: https://github.com/hoangnv2001/real-time-ids

## Overview

##### Main Components
- Frontend Web Interface:
- Represented by the “static” and “templates” folders.
- Components include HTML pages (main index and detailed flow view), CSS styling, and JavaScript for client-side interactivity.
- Backend Application Server:
- The “application.py” file is the main entry point that runs the Flask (or similar) web server.
- This component handles HTTP requests, routing, and rendering the web pages.
- Flow Data Handling Module:
- Located in the “flow” directory (e.g., Flow.py, FlowFeature.py, PacketInfo.py); these modules manage real-time flow capture and possibly pre-process the network traffic data.
- Machine Learning Component:
- In the “models” folder you see several model files:
- “autoencoder_39ft.hdf5” & “preprocess_pipeline_AE_39ft.save” for anomaly detection using an autoencoder.
- “model.pkl” and “scaler.pkl” plus the “explainer” subfolder, likely for the supervised learning part (Random Forest and related preprocessing).
- This indicates a dual approach:
◦ Supervised learning (for known attacks) with RF.
◦ Unsupervised learning (AE for anomaly detection).
- Third-Party / External Dependencies:
- External tools such as Npcap (mentioned in README) are used for capturing live network traffic.
- The environment setup and dependency management (requirements.txt) ensure that necessary libraries are included.

##### Relationships and Interactions
- The user interacts with the frontend interface (browser) that displays data and flow details.
- The frontend makes HTTP requests to the backend (application.py), which then processes these requests.
- The backend extracts network flow information, using modules from the “flow” directory.
- The captured flow data is then passed through the machine learning components (loaded ML models and preprocess pipelines from “models”) to determine whether an intrusion is detected.
- Finally, the processed results (detection outcomes) are sent back to the frontend for user display.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Discrete modules for handling the web interface (static and templates), network traffic flow processing (flow/), and machine learning (models/).
- Model Integration:
- Clear boundaries exist where data preprocessing and prediction are decoupled from UI logic.
- Real-Time Processing:
- Real-time nature of flow capture and analysis, likely involving continuous data flow and rapid ML inference.
- Use of Modular, Reusable Components:
- The directory structure supports modularity (code separated by functionality).

##### Relevant Technologies, Frameworks, or Libraries
- Python 3.9 and its associated libraries as defined in requirements.txt.
- Likely a web framework (Flask or similar) for the backend in application.py.
- Machine learning frameworks/libraries – models in HDF5 and pickle suggest use of frameworks like Keras (TensorFlow) and scikit-learn.
- Npcap for network packet capturing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client Browser"]:::frontend
    B["Flask Application (application.py)"]:::backend
    C["Flow Data Handler (flow/)"]:::flow
    D["ML Inference Engine (models/)"]:::ml
    E["Static Assets (static/)"]:::frontend
    F["HTML Templates (templates/)"]:::frontend
    G["Dependency Management (requirements.txt)"]:::dependency
    H["External: Npcap"]:::external

    A -->|"SendsHTTPRequest"| B
    B -->|"ServesTemplates"| F
    B -->|"ServesAssets"| E
    B -->|"CallsFlowProcessing"| C
    H -->|"CapturesTraffic"| C
    C -->|"ProcessesData"| D
    D -->|"ReturnsInference"| B
    B -->|"SendsResponse"| A
    G -->|"Manages"| B

    click B "https://github.com/hoangnv2001/real-time-ids/blob/master/application.py"
    click C "https://github.com/hoangnv2001/real-time-ids/tree/master/flow/"
    click D "https://github.com/hoangnv2001/real-time-ids/tree/master/models/"
    click E "https://github.com/hoangnv2001/real-time-ids/tree/master/static/"
    click F "https://github.com/hoangnv2001/real-time-ids/tree/master/templates/"
    click G "https://github.com/hoangnv2001/real-time-ids/blob/master/requirements.txt"

    classDef frontend fill:#AED6F1,stroke:#2E86C1,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#F5B041,stroke-width:2px;
    classDef flow fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef ml fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef dependency fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef external fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
```
