# mmrmagno/rustguard architecture

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

- Interactive diagram: https://gitdiagram.com/mmrmagno/rustguard
- Repository: https://github.com/mmrmagno/rustguard

## Overview

##### Project Type and Purpose
- Type: A Command Line Interface (CLI) application.
- Purpose: To manage WireGuard VPN profiles (listing, connecting/disconnecting, editing configurations, and displaying logs), acting as a user-friendly front-end for interacting with WireGuard (wg-quick).

##### File Structure
- Top-Level Directories and Files:
- .github: Contains CI/CD workflows (e.g., release.yml).
- Cargo.toml & Cargo.lock: Standard Rust project configuration files.
- src/main.rs: Contains the application’s main logic.

##### Key Components
a. User Interface:

b. Business Logic / VPN Manager:
- Profile Manager: Lists available WireGuard VPN profiles.
- Connection Manager: Starts and stops VPN connections based on the user’s command.
- Status and Logging Module: Records and shows recent actions and VPN status logs.
- Configuration Editor: Enables editing of WireGuard configurations directly from within the app.

c. External Interaction:
- WireGuard Integration: Represents calls to system-level commands (e.g., using “wg-quick”) for managing VPN interfaces.
- Sudo/Privileges Management: Indicates that operations requiring elevated privileges are performed (this could be a note), though it mostly factors into the runtime environment rather than the code structure.

##### Relationships and Interactions
- The CLI Component interacts with the VPN Manager:
- Commands from the CLI (like Connect/Disconnect) are routed to the Connection Manager.
- Navigation commands update and display the list of available profiles.
- The VPN Manager communicates with External Services:
- It invokes system commands (wg-quick) to effect changes on the WireGuard VPN interfaces.
- It manages configuration file reads/writes during edits.
- The Status/Logging Module receives input from all operations and updates the user interface as necessary.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Even though the code is inside a single main.rs, conceptually break out functionality into modules (even if not physically separated). This shows a clear demarcation between the CLI interface, business logic, and system commands.
- Modularity: Represent each logical component (CLI, Profile Manager, Connection Manager, Config Editor, Logging) as separate blocks.
- External Dependency Encapsulation: Clearly show that interactions with the OS (Invoking wg-quick) are isolated from in-app logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "CLI Layer"
        CLI["CLI Interface"]:::ui
    end

    subgraph "VPN Manager Modules"
        PM["Profile Manager"]:::logic
        CM["Connection Manager"]:::logic
        CE["Configuration Editor"]:::logic
        SL["Status/Logging Module"]:::logic
    end

    subgraph "External Services"
        WG["WireGuard (wg-quick integration)"]:::external
    end

    CLI -->|"send_profile_command"| PM
    CLI -->|"send_connect_command"| CM
    CLI -->|"send_config_edit_command"| CE
    CLI -->|"display_logs"| SL

    CM -->|"execute_connection"| WG
    WG -->|"feedback"| SL
    SL -->|"update_UI"| CLI

    click CLI "https://github.com/mmrmagno/rustguard/blob/main/src/main.rs"
    click PM "https://github.com/mmrmagno/rustguard/blob/main/src/main.rs"
    click CM "https://github.com/mmrmagno/rustguard/blob/main/src/main.rs"
    click CE "https://github.com/mmrmagno/rustguard/blob/main/src/main.rs"
    click SL "https://github.com/mmrmagno/rustguard/blob/main/src/main.rs"
    click WG "https://github.com/mmrmagno/rustguard/blob/main/src/main.rs"

    classDef ui fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef logic fill:#87CEEB,stroke:#000,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:2px;
```
