# caqil/wireguard_flutter architecture

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

- Interactive diagram: https://gitdiagram.com/caqil/wireguard_flutter
- Repository: https://github.com/caqil/wireguard_flutter

## Overview

##### Main Components Identification

a. Flutter Layer:
- Core Plugin Interface
- Platform Interface
- Method Channel Implementation
- Platform-specific Implementations

b. Native Implementations:
- Android (Kotlin)
- iOS/macOS (Swift)
- Windows (C++)
- Linux (Native WireGuard)

**[Component Layout]**
**┌─────────────────────────────────────────┐**
- Flutter Application          │
- ┬─────────────────────┘
- ↓
**┌─────────────────────────────────────────┐**
- WireGuard Flutter Plugin        │
- ┌─────────────────────────────────────┐│
- Platform Interface (Abstract)    ││
- ┘│
- ┌─────────────────────────────────────┐│
- Method Channel Handler         ││
- ┘│
- ┬────────┬────────┬──────────┘
- ↓        ↓        ↓          ↓
**┌──────────────┐ ┌──────┐ ┌──────┐ ┌──────┐**
- Android    │ │ iOS  │ │ Win  │ │Linux │
- Implementation│ │Swift │ │ C++  │ │Native│
- ┘ └──────┘ └──────┘ └──────┘

##### Implementation Details

- Method channel communication
- Platform-specific initialization process
- VPN tunnel creation and management
- Configuration handling
- State monitoring system

##### External Dependencies
- WireGuard native libraries
- Platform-specific VPN services
- System permissions

**Symbols:**
**→ : Data flow**
**⇄ : Bidirectional communication**
**□ : Core components**
**◇ : Platform-specific implementations**
**⚡: Event handlers**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Flutter Application Layer"
        FA[Flutter App]
    end

    subgraph "WireGuard Flutter Plugin Layer"
        direction TB
        CorePlugin["Core Plugin Interface"]
        PlatformInterface["Platform Interface"]
        MethodChannel["Method Channel Handler"]
    end

    subgraph "Platform Implementations"
        direction TB
        subgraph "Android"
            AndroidImpl["Android Implementation"]:::native
            AndroidWG["WireGuard Native Library"]:::external
        end

        subgraph "iOS/macOS"
            iOSImpl["iOS/macOS Implementation"]:::native
            PacketTunnel["Packet Tunnel Provider"]:::native
            iOSWG["WireGuard Native Library"]:::external
        end

        subgraph "Windows"
            WinImpl["Windows Implementation"]:::native
            ServiceControl["Service Control"]:::native
            ConfigWriter["Configuration Writer"]:::native
            WinWG["WireGuard Native Library"]:::external
            WinTunnel["Tunnel Library"]:::external
        end

        subgraph "Linux"
            LinuxImpl["Linux Implementation"]:::native
            LinuxWG["Native WireGuard"]:::external
        end
    end

    %% Connections
    FA --> CorePlugin
    CorePlugin --> PlatformInterface
    PlatformInterface --> MethodChannel
    
    MethodChannel --> AndroidImpl
    MethodChannel --> iOSImpl
    MethodChannel --> WinImpl
    MethodChannel --> LinuxImpl
    
    AndroidImpl --> AndroidWG
    iOSImpl --> PacketTunnel
    PacketTunnel --> iOSWG
    
    WinImpl --> ServiceControl
    WinImpl --> ConfigWriter
    WinImpl --> WinWG
    WinImpl --> WinTunnel
    
    LinuxImpl --> LinuxWG

    %% Styling
    classDef native fill:#90EE90
    classDef external fill:#D3D3D3
    classDef channel fill:#FFD700

    %% Click Events
    click CorePlugin "https://github.com/Caqil/wireguard_flutter/blob/main/lib/wireguard_flutter.dart"
    click PlatformInterface "https://github.com/Caqil/wireguard_flutter/blob/main/lib/wireguard_flutter_platform_interface.dart"
    click MethodChannel "https://github.com/Caqil/wireguard_flutter/blob/main/lib/wireguard_flutter_method_channel.dart"
    click AndroidImpl "https://github.com/Caqil/wireguard_flutter/blob/main/android/src/main/kotlin/billion/group/wireguard_flutter/WireguardFlutterPlugin.kt"
    click iOSImpl "https://github.com/Caqil/wireguard_flutter/blob/main/darwin/Classes/WireguardFlutterPlugin.swift"
    click WinImpl "https://github.com/Caqil/wireguard_flutter/blob/main/windows/wireguard_flutter_plugin.cpp"
    click LinuxImpl "https://github.com/Caqil/wireguard_flutter/blob/main/lib/linux/wireguard_flutter_linux.dart"
    click ServiceControl "https://github.com/Caqil/wireguard_flutter/blob/main/windows/service_control.cpp"
    click ConfigWriter "https://github.com/Caqil/wireguard_flutter/blob/main/windows/config_writer.cpp"
    click WinWG "https://github.com/Caqil/wireguard_flutter/blob/main/windows/lib/wireguard/include/wireguard.h"
    click WinTunnel "https://github.com/Caqil/wireguard_flutter/blob/main/windows/lib/tunnel/include/tunnel.h"
    click PacketTunnel "https://github.com/Caqil/wireguard_flutter/blob/main/example/ios/WGExtension/PacketTunnelProvider.swift"

    %% Legend
    subgraph Legend
        direction TB
        L1["Native Implementation"]:::native
        L2["External Dependency"]:::external
        L3["Communication Channel"]:::channel
    end
```
