# vnt-dev/vnt architecture

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

- Interactive diagram: https://gitdiagram.com/vnt-dev/vnt
- Repository: https://github.com/vnt-dev/vnt

## Overview

##### Project Overview & Main Components
- VNT is a VPN tool that creates a virtual LAN using virtual IPs, NAT traversal, and multiple encryption/compression strategies. Its key purpose is to provide a secure and efficient way to connect devices across different networks.
- The project is structured as a multi-crate workspace with several distinct components:
- vnt-cli & vnt-cli/README.md: The command‐line interface for interacting with the VPN. It handles parameter parsing and user commands (like “info” and “list”).
- vnt: The core VPN library/application that implements the networking, encryption, packet handling, NAT traversal, and protocol logic.
- vn-link and vn-link-cli: These likely serve as additional linking modules or configuration helpers for network mapping (for TCP/UDP protocols).
- common: A shared library containing common utilities – CLI argument parsing, command processing, configuration, console output, etc.
- Other directories (like documents and proto) provide supporting assets such as images for documentation and protocol definitions (e.g., protocol buffers in message.proto).

##### Analyzing the File Structure for Architectural Clues
- Multiple sub-crates (each with its own Cargo.toml) point to a modular design where different functionalities are separated into distinct libraries:
- The separation of “in_mapping” and “out_mapping” in vn-link clearly suggests handling of incoming and outgoing network data transformations over TCP/UDP connections.
- The structure clearly reflects a layered design: a CLI frontend that uses common utilities and then calls into the core VNT library, which in turn orchestrates packet handling, encryption/decryption, network channel management, and protocol processing.

##### Final Steps
- Detailed labeling of each identified module.
- Differentiation between internal modules and external dependencies (e.g., TUN/TAP interfaces, relay servers).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Layer
    subgraph "CLI Layer"
        VNT_CLI["vnt-cli (CLI)"]:::cli
        VN_LINK_CLI["vn-link-cli (CLI)"]:::cli
    end

    %% Core VPN Engine
    subgraph "Core VPN Engine"
        %% Packet & Core Modules
        subgraph "Packet & Core Modules"
            PACKET["Packet Processing"]:::core
            CIPHER["Cryptography (cipher)"]:::core
            COMP["Compression"]:::core
            CHANNEL["Network Channels"]:::core
            PROTOCOL["Protocol Handling"]:::core
            NAT["NAT"]:::core
            PORT["Port Mapping"]:::core
            IP_PROXY["IP Proxy"]:::core
        end
        %% TUN/TAP Management
        subgraph "TUN/TAP Management"
            TUN_TAP["TUN/TAP Device Interface"]:::core
            TUN_HANDLE["Additional TUN/TAP Handling"]:::core
        end
        UTIL["Utility Services"]:::core
    end

    %% Common Library and Linking Modules
    subgraph "Common & Linking Modules"
        COMMON["Common Library"]:::common
        IN_MAP["vn-link In Mapping"]:::link
        OUT_MAP["vn-link Out Mapping"]:::link
        PROTO["Protocol Definitions"]:::asset
        DOCS["Documentation"]:::asset
    end

    %% Connections from CLI to Common
    VNT_CLI -->|"uses"| COMMON
    VN_LINK_CLI -->|"uses"| COMMON

    %% Common to Core (command/config flow)
    COMMON -->|"configures"| PROTOCOL

    %% TUN/TAP feeding into Packet Processing
    TUN_TAP -->|"injects traffic"| PACKET
    TUN_HANDLE -->|"injects traffic"| PACKET

    %% Internal processing flow in Core VPN Engine
    PACKET -->|"parsed by"| CIPHER
    CIPHER -->|"prepares"| COMP
    COMP -->|"feeds"| CHANNEL
    CHANNEL -->|"routes to"| PROTOCOL

    %% Protocol distributes to various network handling modules
    PROTOCOL -->|"handles"| NAT
    PROTOCOL -->|"handles"| PORT
    PROTOCOL -->|"handles"| IP_PROXY

    %% Protocol directs traffic to linking modules
    PROTOCOL -->|"maps in"| IN_MAP
    PROTOCOL -->|"maps out"| OUT_MAP

    %% Utility Services supporting core modules
    UTIL ---|"supports"| CHANNEL
    UTIL ---|"supports"| PROTOCOL

    %% Click Events
    click VNT_CLI "https://github.com/vnt-dev/vnt/blob/main/vnt-cli/src/main.rs"
    click VN_LINK_CLI "https://github.com/vnt-dev/vnt/blob/main/vn-link-cli/src/main.rs"
    click PACKET "https://github.com/vnt-dev/vnt/tree/main/vnt/packet"
    click CIPHER "https://github.com/vnt-dev/vnt/tree/main/vnt/src/cipher"
    click COMP "https://github.com/vnt-dev/vnt/tree/main/vnt/src/compression"
    click CHANNEL "https://github.com/vnt-dev/vnt/tree/main/vnt/src/channel"
    click PROTOCOL "https://github.com/vnt-dev/vnt/tree/main/vnt/src/protocol"
    click NAT "https://github.com/vnt-dev/vnt/tree/main/vnt/src/nat"
    click PORT "https://github.com/vnt-dev/vnt/tree/main/vnt/src/port_mapping"
    click IP_PROXY "https://github.com/vnt-dev/vnt/tree/main/vnt/src/ip_proxy"
    click TUN_TAP "https://github.com/vnt-dev/vnt/tree/main/vnt/src/tun_tap_device"
    click TUN_HANDLE "https://github.com/vnt-dev/vnt/tree/main/vnt/src/handle/tun_tap"
    click UTIL "https://github.com/vnt-dev/vnt/tree/main/vnt/src/util"
    click COMMON "https://github.com/vnt-dev/vnt/tree/main/common/src"
    click IN_MAP "https://github.com/vnt-dev/vnt/tree/main/vn-link/src/in_mapping"
    click OUT_MAP "https://github.com/vnt-dev/vnt/tree/main/vn-link/src/out_mapping"
    click PROTO "https://github.com/vnt-dev/vnt/blob/main/vnt/proto/message.proto"
    click DOCS "https://github.com/vnt-dev/vnt/tree/main/documents"

    %% Styles
    classDef cli fill:#f2b0b0,stroke:#333,stroke-width:2px;
    classDef core fill:#b0d0f2,stroke:#333,stroke-width:2px;
    classDef common fill:#b0f2b0,stroke:#333,stroke-width:2px;
    classDef link fill:#f2e2b0,stroke:#333,stroke-width:2px;
    classDef asset fill:#e2b0f2,stroke:#333,stroke-width:2px;
```
