# defguard/client architecture

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

- Interactive diagram: https://gitdiagram.com/defguard/client
- Repository: https://github.com/defguard/client

## Overview

Based on our analysis of the file tree and README, this project is a desktop client for managing WireGuard VPN connections, built as a full-stack desktop application using Tauri. It combines a React (TypeScript) frontend with a Rust-based backend that leverages Tauri’s capabilities for desktop integration, along with native modules for database access and system services.

##### Main Components
- Frontend (React UI):
- “src” directory where the bulk of the React components, pages, hooks, and shared UI utilities are located.
- Multiple pages (client, enrollment, settings, session timeout etc.) and reusable components, indicating the modular and component-based design.
- That internationalization (i18n) support and style modules (SCSS) are part of the frontend, highlighting UI/UX responsibilities.

- Tauri Backend (Rust):
- Use the “src-tauri” folder to encapsulate the Rust-driven backend. This includes submodules like “cli”, “common”, “enterprise”, and “service” which provide core business logic, CLI functionality, and cross-platform integrations.
- Database integration: migrations (SQL files), SQLx queries (in the .sqlx subdirectory), and database models (in src-tauri/src/database and others). This layer covers data access, business rules, and persistence.
- Additional functionalities such as log watching (src-tauri/src/log_watcher) and periodic tasks (src-tauri/src/periodic) that keep the system’s internal state and monitoring.

- External Dependencies:
- Integration with external WireGuard servers and defguard VPN & SSO instances.
- That although the client supports any WireGuard server, it is tightly coupled with defguard’s ecosystem for multi-factor authentication and multi-instance management.

- System Services & Deployment:
- Components like the CLI (in src-tauri/cli), service configurations for macOS, Windows, and Linux (various resources directories), and deployment scripts.
- That Tauri acts as the bridge connecting the frontend with native window management and system-level features.

##### Relationships and Interactions
- Data Flow from UI to Backend:
- Backend Database Interaction:
- Backend’s connection to a local SQLite database (as evidenced by SQLx, migrations, and the DATABASE_URL configuration). Indicate that the backend retrieves and updates connection history, statistics, logs, and settings.
- External Integration:

##### Important Architectural Patterns / Design Principles
- Separation of Concerns:
- Clearly separate the UI layer (React components, pages) from native functionalities (Rust backend, CLI, database operations).
- Modular Design:
- Modularization in both layers: the frontend is broken down into reusable components and route-based pages, while the backend is divided into different domains such as CLI, common libraries, database models, services, and enterprise enhancements.
- Cross-Platform Strategy:
- That the project is multi-platform (Linux, macOS, Windows) and that there are platform-specific resource directories and deployment scripts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        ReactUI["React UI (src)"]:::frontend
    end

    %% Tauri Backend Layer
    subgraph "Tauri Backend Layer"
        TauriBackend["Rust Backend (src-tauri)"]:::backend
        CLI["CLI Module"]:::backend
        DB["Database Integration (Migrations & Models)"]:::database
        LogWatch["Log Watching Module"]:::backend
        PeriodicTasksTauri["Periodic Tasks (Tauri)"]:::backend
        PeriodicTasksEnterprise["Periodic Tasks (Enterprise)"]:::backend
        Enterprise["Enterprise Enhancements"]:::backend
        SQLiteDB["SQLite Database"]:::database
    end

    %% External Systems
    subgraph "External Systems"
        Ext["WireGuard Servers & Defguard VPN/SSO"]:::external
    end

    %% System Services & Deployment
    subgraph "System Services & Deployment"
        DGService["Deployment: dg.service"]:::deployment
        LinuxRes["Deployment: Linux Resources"]:::deployment
        MacOSRes["Deployment: macOS Resources"]:::deployment
        WindowsRes["Deployment: Windows Resources"]:::deployment
    end

    %% Connections and Data Flow
    ReactUI -->|"Tauri_API_Bridge"| TauriBackend
    TauriBackend -->|"Executes_Commands"| CLI
    TauriBackend -->|"Database_Ops"| DB
    DB -->|"SQLx_Queries"| SQLiteDB
    TauriBackend -->|"Monitors_Logs"| LogWatch
    TauriBackend -->|"Schedules_Tasks"| PeriodicTasksTauri
    TauriBackend -->|"Schedules_Enterprise_Tasks"| PeriodicTasksEnterprise
    TauriBackend -->|"Enterprise_Enhancements"| Enterprise
    TauriBackend -->|"Calls_out"| Ext
    TauriBackend -->|"System_Integration"| DGService
    TauriBackend -->|"System_Integration"| LinuxRes
    TauriBackend -->|"System_Integration"| MacOSRes
    TauriBackend -->|"System_Integration"| WindowsRes

    %% Click Events
    click ReactUI "https://github.com/defguard/client/tree/main/src"
    click TauriBackend "https://github.com/defguard/client/tree/main/src-tauri"
    click CLI "https://github.com/defguard/client/tree/main/src-tauri/cli"
    click DB "https://github.com/defguard/client/tree/main/src-tauri/migrations"
    click DB "https://github.com/defguard/client/tree/main/src-tauri/src/database"
    click LogWatch "https://github.com/defguard/client/tree/main/src-tauri/src/log_watcher"
    click PeriodicTasksTauri "https://github.com/defguard/client/tree/main/src-tauri/src/periodic"
    click PeriodicTasksEnterprise "https://github.com/defguard/client/tree/main/src-tauri/src/enterprise/periodic"
    click Enterprise "https://github.com/defguard/client/tree/main/src-tauri/src/enterprise"
    click DGService "https://github.com/defguard/client/blob/main/dg.service"
    click LinuxRes "https://github.com/defguard/client/tree/main/resources-linux"
    click MacOSRes "https://github.com/defguard/client/tree/main/src-tauri/resources-macos"
    click WindowsRes "https://github.com/defguard/client/tree/main/src-tauri/resources-windows"

    %% Styles
    classDef frontend fill:#A8E6CF,stroke:#004D40,stroke-width:2px;
    classDef backend fill:#FFD3B4,stroke:#E29578,stroke-width:2px;
    classDef external fill:#FFAAA5,stroke:#FF3D3D,stroke-width:2px;
    classDef deployment fill:#B5EAD7,stroke:#59C3C3,stroke-width:2px;
    classDef database fill:#C1DFF0,stroke:#3C91E6,stroke-width:2px;
```
