# luodeb/fluttervpnproxy architecture

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

- Interactive diagram: https://gitdiagram.com/luodeb/fluttervpnproxy
- Repository: https://github.com/luodeb/fluttervpnproxy

## Overview

##### Project Type and Purpose
- This is a Flutter mobile application that integrates deep native code on Android. Its primary purpose is to implement a basic VPN service that utilizes an HTTP proxy – achieved by leveraging Android’s VpnService.
- The README indicates that it’s inspired by an existing VpnProxy project but has been simplified for learning purposes. The focus is on the HTTP proxy functionality using VpnService.

##### Analyzing the File Structure
- Top-level Directories:
- Android: Contains the native Android project code with Java and Kotlin files.
- lib: Contains Flutter/Dart code, including the main application entry point and the method channel for native communication.
- test: Contains testing code for Flutter widgets.
- In the Android directory:
- The Java packages (under android/app/src/main/java/com/example/my_vpn_plugin) are highly modularized. They separate functionalities into:
- Core components: (e.g., LocalVpnService.java, TcpProxyServer.java, NatSessionManager.java) handling the initialization of the VPN service and the main engine for traffic interception.
- DNS modules: (e.g., DnsProxy.java, DnsPacket.java) dealing with DNS packet manipulation.
- TCP/IP handling: (e.g., TCPHeader.java, UDPHeader.java, IPHeader.java) responsible for processing low-level network protocols.
- Tunnel modules: (e.g., Tunnel.java, RawTunnel.java, TunnelFactory.java, and specifically the HTTP Connect tunnel classes) which provide the mechanism for establishing the VPN tunnel.
- The Kotlin folder (MainActivity.kt) likely provides the bridge with Flutter and hooks into the Android components.
- In the lib folder:
- The Dart files (main.dart, my_vpn_method_channel.dart) suggest that the Flutter layer communicates with the native Android plugin via method channels.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Flutter Layer
    subgraph "Flutter Layer"
        FUI("Flutter UI"):::flutter
        MC("Method Channel Interface"):::channel
        FUI -->|"activates"| MC
    end

    %% Native Android Layer
    subgraph "Native Android Layer"
        MAct("Android-Platform Bridge"):::native
        LVPN("VpnService Entry Point"):::native
        MC -->|"invokes"| MAct
        MAct -->|"bridges"| LVPN

        %% Core Proxy Engine
        subgraph "Core Proxy Engine"
            TCP("TCP Proxy Server"):::engine
            NAT("NAT Session Manager"):::engine
            LVPN -->|"starts"| TCP
            LVPN -->|"starts"| NAT
        end

        %% Network Processing Modules
        subgraph "Network Processing Modules"
            DNS("DNS Module"):::engine
            TCPIP("TCP/IP Processing Module"):::engine
            LVPN -->|"processes"| DNS
            LVPN -->|"processes"| TCPIP
        end

        %% Tunnel Management
        subgraph "Tunnel Management"
            TGen("Tunnel Management (General)"):::native
            TCore("Tunnel Core"):::native
            TRaw("Raw Tunnel"):::native
            TFactory("Tunnel Factory"):::native
            HTTP("HTTP Connect Tunnel"):::native
            HConfig("HTTP Connect Config"):::config
            LVPN -->|"establishes"| TGen
            TGen -->|"initializes"| TCore
            TCore -->|"uses"| TRaw
            TCore -->|"uses"| TFactory
            TGen -->|"supports"| HTTP
            HTTP -->|"configured_by"| HConfig
        end

        %% Configuration Modules
        subgraph "Configuration Modules"
            PC("Proxy Config"):::config
            TC("Tunnel Config"):::config
            LVPN -->|"uses"| PC
            TCP -->|"uses"| PC
            TGen -->|"uses"| TC
        end
    end

    %% Click Events
    click FUI "https://github.com/luodeb/fluttervpnproxy/blob/main/lib/main.dart"
    click MC "https://github.com/luodeb/fluttervpnproxy/blob/main/lib/my_vpn_method_channel.dart"
    click MAct "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/kotlin/com/example/my_vpn/MainActivity.kt"
    click LVPN "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/core/LocalVpnService.java"
    click TCP "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/core/TcpProxyServer.java"
    click NAT "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/core/NatSessionManager.java"
    click DNS "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/core/DnsProxy.java"
    click TCPIP "https://github.com/luodeb/fluttervpnproxy/tree/main/android/app/src/main/java/com/example/my_vpn_plugin/tcpip"
    click TCore "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/tunnel/Tunnel.java"
    click TRaw "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/tunnel/RawTunnel.java"
    click TFactory "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/tunnel/TunnelFactory.java"
    click HTTP "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/tunnel/httpconnect/HttpConnectTunnel.java"
    click HConfig "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/tunnel/httpconnect/HttpConnectConfig.java"
    click PC "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/core/ProxyConfig.java"
    click TC "https://github.com/luodeb/fluttervpnproxy/blob/main/android/app/src/main/java/com/example/my_vpn_plugin/tunnel/Config.java"

    %% Styles
    classDef flutter fill:#FFCC99,stroke:#333,stroke-width:1px;
    classDef channel fill:#FFD700,stroke:#333,stroke-width:1px;
    classDef native fill:#99CCFF,stroke:#333,stroke-width:1px;
    classDef engine fill:#C8E6C9,stroke:#333,stroke-width:1px;
    classDef config fill:#FFB6C1,stroke:#333,stroke-width:1px;
```
