# nilsirl/mozwire architecture

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

- Interactive diagram: https://gitdiagram.com/nilsirl/mozwire
- Repository: https://github.com/nilsirl/mozwire

## Overview

##### Main Components

a. Core Components:
- CLI Interface (represented by src/cli.rs)
- Device Management System (represented by src/device.rs)
- Relay Management System (represented by src/relay.rs)
- Configuration Manager (part of the main system)

b. External Components:
- Mozilla VPN API
- WireGuard Protocol Interface
- Browser Interface (for authentication)
- Operating System Network Interface

##### Component Relationships

**User Interface Layer:**
- [CLI Interface]

**Core Logic Layer:**
- [Device Manager] --- [Relay Manager]

- [Configuration Manager] [Constants]

- [Authentication Handler]

**External Services Layer:**
- [Mozilla VPN API] [Browser] [WireGuard]

**OS Integration Layer:**
- [Network Interface]

##### Key Elements to Highlight

a. Data Flow Paths:
- User → CLI → Authentication → Mozilla VPN API
- CLI → Relay Manager → WireGuard Configuration
- Device Manager → Mozilla VPN API
- Configuration Manager → OS Network Interface

- Blue: User-facing components (CLI)
- Green: Core logic components
- Yellow: External services
- Gray: System interfaces

##### Implementation Details

- Token management flow
- Configuration generation process
- Device registration flow
- Relay selection mechanism

##### Technical Notes

Annotations for:
- Supported platforms (Linux, macOS, FreeBSD, OpenBSD, Windows)
- WireGuard protocol integration points
- Authentication flow with Mozilla's API
- Configuration file handling

##### Key Processes to Highlight

- Authentication flow
- Configuration generation
- Relay selection
- Device management

Remember to emphasize:
- The separation between the CLI interface and core logic
- The interaction with external services (Mozilla VPN API)
- The configuration generation and management system
- The platform-agnostic nature of the implementation

This will provide a comprehensive view of how MozWire interfaces with both the Mozilla VPN infrastructure and local WireGuard implementations across different operating systems.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef system fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef config fill:#e74c3c,stroke:#c0392b,color:white

    %% User Interface Layer
    subgraph UI
        CLI["CLI Interface"]
    end
    class CLI ui

    %% Core Logic Layer
    subgraph Core
        DM["Device Manager"]
        RM["Relay Manager"]
        CM["Configuration Manager"]
        CN["Constants"]
        AH["Authentication Handler"]
        ML["Main Logic"]
    end
    class DM,RM,CM,CN,AH,ML core

    %% External Services Layer
    subgraph External
        API["Mozilla VPN API"]
        BR["Browser"]
        WG["WireGuard"]
    end
    class API,BR,WG external

    %% OS Integration Layer
    subgraph System
        NI["Network Interface"]
    end
    class NI system

    %% Relationships
    CLI --> AH
    CLI --> DM
    CLI --> RM
    DM --> API
    RM --> API
    RM --> WG
    CM --> NI
    AH --> API
    AH --> BR
    DM --> CM
    RM --> CM
    ML --> DM
    ML --> RM
    ML --> CM
    CN --> CM

    %% Features
    MH["Multihop"]:::core
    KS["Kill Switch"]:::core
    RM --> MH
    CM --> KS
    KS --> NI

    %% Click events
    click CLI "https://github.com/NilsIrl/MozWire/blob/trunk/src/cli.rs"
    click DM "https://github.com/NilsIrl/MozWire/blob/trunk/src/device.rs"
    click RM "https://github.com/NilsIrl/MozWire/blob/trunk/src/relay.rs"
    click CN "https://github.com/NilsIrl/MozWire/blob/trunk/src/constants.rs"
    click ML "https://github.com/NilsIrl/MozWire/blob/trunk/src/main.rs"

    %% Legend
    subgraph Legend
        UI_L["User Interface"]:::ui
        CORE_L["Core Components"]:::core
        EXT_L["External Services"]:::external
        SYS_L["System Interface"]:::system
    end
```
