# seladb/toyvpn-pcapplusplus architecture

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

- Interactive diagram: https://gitdiagram.com/seladb/toyvpn-pcapplusplus
- Repository: https://github.com/seladb/toyvpn-pcapplusplus

## Overview

##### Main Components

a) Client-Side (Android App):
- UI Layer (ToyVpnClient Activity)
- VPN Service Layer (ToyVpnService)
- Connection Handler (ToyVpnConnection)
- PcapPlusPlus Integration Layer:
- PcapPlusPlusInterface (Kotlin)
- Native Interface (JNI Layer)
- PcapPlusPlus Libraries

b) Server-Side:
- Linux VPN Server
- TUN Interface
- NAT/Routing Components

c) External Components:
- Internet/Remote Destinations
- DNS Servers
- TLS Endpoints

**[Remote Services (Top)]**
- ↕
**[VPN Server (Middle)]**
- ↕
**[Android App Components (Bottom)]**

##### Component Relationships

Key interactions:

a) Data Flow:
- Device → VpnService → ToyVpnConnection → Server → Internet
- Packet Analysis Flow: ToyVpnConnection → PcapPlusPlusInterface → Native Layer

b) Control Flow:
- UI → VpnService → Connection Management
- PcapPlusPlus Analysis Pipeline

##### Detailed Elements

Specific details:

a) Android App Layer:
**┌─ Android App ─────────────────────┐**
- ┌─ UI Layer ─┐  ┌─ VPN Core ───┐ │
- ToyVpnClient│→│ToyVpnService  │ │
- ┘  │ToyVpnConnection│ │
- ┘ │
- ┌─ PcapPlusPlus Integration ───┐ │
- PcapPlusPlusInterface        │ │
- Native JNI Layer             │ │
- PcapPlusPlus Libraries      │ │
- ┘ │
- ┘

b) Server Layer:
**┌─ Linux Server ────────┐**
- TUN Interface         │
- NAT Configuration    │
- Routing Rules        │
- ┘

##### Technical Details

- API Level (30)
- Supported architectures (arm64-v8a, armeabi-v7a, x86, x86_64)
- Network protocols (IPv4, IPv6, TCP, UDP, DNS, TLS)
- File formats (pcap)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef android fill:#b3e0ff,stroke:#333,stroke-width:2px
    classDef server fill:#90EE90,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef pcap fill:#FFE5B4,stroke:#333,stroke-width:2px
    
    %% External Services Layer
    subgraph ExternalServices
        Internet["Internet/Remote Services"]:::external
        DNS["DNS Servers"]:::external
        TLS["TLS Endpoints"]:::external
    end

    %% Server Layer
    subgraph ServerLayer
        VPNServer["Linux VPN Server"]:::server
        TUNServer["TUN Interface"]:::server
        NAT["NAT/Routing"]:::server
    end
    click VPNServer "https://github.com/seladb/ToyVpn-PcapPlusPlus/blob/master/server/linux/ToyVpnServer.cpp"

    %% Android App Layer
    subgraph AndroidApp
        %% UI Layer
        UI["ToyVpnClient Activity"]:::android
        click UI "https://github.com/seladb/ToyVpn-PcapPlusPlus/blob/master/app/src/main/java/com/example/android/toyvpn/ToyVpnClient.java"
        click UI "https://github.com/seladb/ToyVpn-PcapPlusPlus/blob/master/app/src/main/res/layout/form.xml"

        %% VPN Service Components
        VPNService["ToyVpnService"]:::android
        Connection["ToyVpnConnection"]:::android
        click VPNService "https://github.com/seladb/ToyVpn-PcapPlusPlus/blob/master/app/src/main/java/com/example/android/toyvpn/ToyVpnService.java"
        click Connection "https://github.com/seladb/ToyVpn-PcapPlusPlus/blob/master/app/src/main/java/com/example/android/toyvpn/ToyVpnConnection.java"

        %% PcapPlusPlus Integration
        subgraph PcapIntegration
            PcapInterface["PcapPlusPlusInterface"]:::pcap
            NativeJNI["Native JNI Layer"]:::pcap
            PcapLibs["PcapPlusPlus Libraries"]:::pcap
            NetworkStats["Network Statistics"]:::pcap
        end
        click PcapInterface "https://github.com/seladb/ToyVpn-PcapPlusPlus/blob/master/app/src/main/java/com/example/android/pcapplusplus/PcapPlusPlusInterface.kt"
        click NativeJNI "https://github.com/seladb/ToyVpn-PcapPlusPlus/blob/master/app/src/main/cpp/pcapplusplus_interface.cpp"
        click PcapLibs "https://github.com/seladb/ToyVpn-PcapPlusPlus/tree/master/app/libs/libpcap-android"
        click NetworkStats "https://github.com/seladb/ToyVpn-PcapPlusPlus/blob/master/app/src/main/java/com/example/android/pcapplusplus/NetworkStats.kt"
    end

    %% Relationships
    UI --> VPNService
    VPNService --> Connection
    Connection --> VPNServer
    VPNServer --> TUNServer
    TUNServer --> NAT
    NAT --> Internet
    Internet --> DNS
    Internet --> TLS
    
    %% PcapPlusPlus Integration Flow
    Connection --> PcapInterface
    PcapInterface --> NativeJNI
    NativeJNI --> PcapLibs
    PcapInterface --> NetworkStats

    %% Legend
    subgraph Legend
        AndroidComp["Android Components"]:::android
        ServerComp["Server Components"]:::server
        ExternalComp["External Services"]:::external
        PcapComp["PcapPlusPlus Components"]:::pcap
    end
```
