# zehome/mlvpn architecture

> Architecture diagram of the GitHub repository zehome/mlvpn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zehome/mlvpn
- Repository: https://github.com/zehome/mlvpn

## Overview

##### Main Components

a) Core Components:
- Privilege Separation Layer
- Cryptography Module
- Link Aggregation Engine
- Network Interface Management
- Control System
- Monitoring System

b) Platform-Specific Components:
- TUN/TAP Implementations (Linux/BSD/Darwin)
- System Integration Components

**┌─ User Space ──────────────────────────────────────┐**

- ┌─ Unprivileged Process ───────────────────┐    │

- ┌─ Core Components ─────────────────┐   │    │
- Link Aggregation Engine         │   │    │
- Reordering System              │   │    │
- Buffer Management              │   │    │
- Monitoring & Statistics        │   │    │
- ┘   │    │

- ┌─ Security Layer ─────────────────┐   │    │
- Salsa20 Encryption            │   │    │
- Poly1305 Authentication       │   │    │
- ┘   │    │
- ┘    │

- ┌─ Privileged Process ────────────────────┐     │
- TUN/TAP Interface Management          │     │
- System Configuration                  │     │
- Privilege Separation Handler          │     │
- ┘    │

- ┘

**┌─ Kernel Space ────────────────────────────────────┐**
- TUN/TAP Devices                                │
- Network Stack Integration                      │
- ┘

##### Key Relationships to Highlight

a) Vertical Relationships:
- Privilege separation between root and unprivileged processes
- Communication between user space and kernel space through TUN/TAP
- System call boundaries

b) Horizontal Relationships:
- Data flow between components
- Control flow between modules
- Security layer integration

##### Important Implementation Details

- Privilege separation architecture clearly
- Platform-specific implementations (Linux/BSD/Darwin)
- Cryptographic boundaries
- Monitoring and control paths

##### External Interfaces

- Network interfaces (physical)
- Virtual interfaces (TUN/TAP)
- Configuration interface
- Monitoring interface

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph User_Space
        subgraph Unprivileged_Process
            subgraph Core_Components
                LAE["Link Aggregation Engine"]:::core
                click LAE "https://github.com/zehome/MLVPN/blob/master/src/wrr.c"
                RS["Reordering System"]:::core
                click RS "https://github.com/zehome/MLVPN/blob/master/src/reorder.c"
                BM["Buffer Management"]:::core
                click BM "https://github.com/zehome/MLVPN/blob/master/src/buffer.c"
                MS["Monitoring & Statistics"]:::core
            end

            subgraph Security_Layer
                SE["Salsa20 Encryption"]:::security
                PA["Poly1305 Authentication"]:::security
                CM["Cryptography Module"]:::security
                click CM "https://github.com/zehome/MLVPN/blob/master/src/crypto.c"
            end

            CS["Control System"]:::control
            click CS "https://github.com/zehome/MLVPN/blob/master/src/control.c"
            TS["Timestamp Management"]:::util
            click TS "https://github.com/zehome/MLVPN/blob/master/src/timestamp.c"
            LS["Logging System"]:::util
            click LS "https://github.com/zehome/MLVPN/blob/master/src/log.c"
        end

        subgraph Privileged_Process
            PS["Privilege Separation Handler"]:::priv
            click PS "https://github.com/zehome/MLVPN/blob/master/src/privsep.c"
            TM["TUN/TAP Management"]:::system
            SC["System Configuration"]:::system
            click SC "https://github.com/zehome/MLVPN/blob/master/src/config.c"
            SI["System Integration"]:::system
            click SI "https://github.com/zehome/MLVPN/blob/master/src/systemd.c"
        end

        subgraph Platform_Specific
            TL["Linux TUN/TAP"]:::platform
            click TL "https://github.com/zehome/MLVPN/blob/master/src/tuntap_linux.c"
            TB["BSD TUN/TAP"]:::platform
            click TB "https://github.com/zehome/MLVPN/blob/master/src/tuntap_bsd.c"
            TD["Darwin TUN/TAP"]:::platform
            click TD "https://github.com/zehome/MLVPN/blob/master/src/tuntap_darwin.c"
            TG["Generic TUN/TAP Interface"]:::platform
            click TG "https://github.com/zehome/MLVPN/blob/master/src/tuntap_generic.c"
        end
    end

    subgraph Kernel_Space
        TD_DEV["TUN/TAP Devices"]:::kernel
        NS["Network Stack"]:::kernel
    end

    %% Core Program
    CP["Core Program"]:::core
    click CP "https://github.com/zehome/MLVPN/blob/master/src/mlvpn.c"

    %% Relationships
    CP --> LAE
    CP --> PS
    LAE --> RS
    RS --> BM
    BM --> CM
    CM --> SE
    CM --> PA
    PS --> TM
    TM --> TL & TB & TD
    TL & TB & TD --> TG
    TG --> TD_DEV
    TD_DEV --> NS
    CS --> MS
    TS --> MS
    LS --> MS
    SC --> SI

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef system fill:#2ecc71,stroke:#27ae60,color:white
    classDef priv fill:#f1c40f,stroke:#f39c12,color:black
    classDef platform fill:#9b59b6,stroke:#8e44ad,color:white
    classDef kernel fill:#34495e,stroke:#2c3e50,color:white
    classDef util fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef control fill:#e67e22,stroke:#d35400,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Security Components"]:::security
        L3["System Components"]:::system
        L4["Privileged Operations"]:::priv
        L5["Platform-Specific"]:::platform
        L6["Kernel Space"]:::kernel
        L7["Utility Components"]:::util
        L8["Control Components"]:::control
    end
```
