# mkdir700/uniclipboard-desktop architecture

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

- Interactive diagram: https://gitdiagram.com/mkdir700/uniclipboard-desktop
- Repository: https://github.com/mkdir700/uniclipboard-desktop

## Overview

##### Main Components
- Frontend UI: Represented by the React-based user interface components (pages, layouts, components for clipboard, device, settings, etc.) in the “src” folder. This layer handles the user interaction with pages like Dashboard, Devices, and Settings.
- Tauri Backend (Native Rust): Found in the “src-tauri” folder. This layer is subdivided using a layered, domain-driven design structure:
- API Layer: Contains API endpoints (e.g., in “src-tauri/src/api”) that provide access to functionalities such as clipboard items, events, onboarding, and settings.
- Application Layer: Implements business logic (e.g., clipboard service, device service, file service, sync service in “src-tauri/src/application”).
- Domain Layer: Contains domain models and core business entities (e.g., device and event definitions in “src-tauri/src/domain”).
- Core & Infrastructure Layers:
▪ “Core” provides utilities, context, event bus, and helper modules.
▪ “Infrastructure” includes storage (using Diesel with migrations, DAOs, and database manager), network (WebDAV, WebSocket for sync), security (authentication, encryption, security manager), connection management, and web server constructs.
- Interface Layer: Declares traits and contracts (e.g., for local clipboard access and remote sync) used for abstraction between the backend services and external integrations.
- Database: Although not a separate service, the persistence layer is managed in “src-tauri” with Diesel migrations and models representing clipboard records and device entities.
- Prototypes and Static Assets: HTML prototypes (in “prototypes”) and assets in “public” may be used for development, demonstration, or fallback views.

##### Relationships and Interactions
- The frontend communicates with the backend via Tauri’s bridge (invoking Rust APIs from JavaScript) for operations such as fetching or syncing clipboard data.
- Within the backend, the API layer routes requests and delegates them to application services, which in turn interact with the domain logic and infrastructure components. For instance:
- A clipboard sync request is sent from the frontend to the backend API, handled by the clipboard service (application layer), which then accesses the storage (infrastructure) and uses encryption (security) before propagating events (via the core’s event bus).
- Device management utilizes both application and domain layers to ensure proper registration and authorization using underlying security modules.
- The network sub-modules (WebDAV & WebSocket) handle external synchronization, while the local database (managed using Diesel and its migrations) stores the persistent state.

##### Architectural Patterns & Design Principles
- Layered Architecture / Domain-Driven Design: The clear separation into API, application, domain, core, and infrastructure ensures maintainability and separation of concerns.
- Client-Server Communication within a Desktop App: Tauri provides an abstraction that unites the React frontend and the native Rust backend.
- Security and Networking Modules: Emphasis on secure data transfer (AES-GCM encryption) and flexible network sync options (LAN, WebDAV, and WebSocket).

##### Technologies & Frameworks
- Frontend: React, TypeScript, Vite (as seen in configuration files such as vite.config.ts and tsconfig.json).
- Backend: Rust (cargo files, Rust source in “src-tauri”), Diesel for database management, and Tauri as the desktop framework.
- Additional Tools: TailwindCSS for styling (tailwind.config.js), various Rust libraries for encryption, authentication, and event handling.

- “Frontend (React UI)”
- “API Layer (Tauri/Rust)”
- “Application Services (Clipboard, Device, Sync)”
- “Domain Models (Device, Event, Clipboard Record)”
- “Core Utilities (Event Bus, Context, Helpers)”
- “Infrastructure (Storage/DB, Network/WebDAV, Security, Connections)”
- “Interface Layer (Traits for Clipboard, Sync, Storage)”
- Data flow from the Frontend to the API layer via the Tauri bridge.
- Subsequent internal flows from the API layer to the Application, Domain, and Infrastructure layers.
- Bidirectional communication for synchronization (UI ↔ Backend; Backend ↔ External networks).
- Annotations for modules that interact with external systems (like web servers or network services).

## Diagram (Mermaid)

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

    %% Backend Layer (Tauri/Rust)
    subgraph "Backend (Tauri/Rust)"
        A["API Layer (Tauri/Rust)"]:::backend
        APP["Application Services (Clipboard, Device, Sync)"]:::backend
        DM["Domain Models (Device, Event, Clipboard Record)"]:::backend
        CORE["Core Utilities (Event Bus, Context, Helpers)"]:::backend
        
        subgraph "Infrastructure"
            DB["Storage/Database"]:::infra
            NET["Networking"]:::infra
            SEC["Security"]:::infra
            CONN["Connection Management"]:::infra
            SYNC["Synchronization"]:::infra
            WEB["Web Server"]:::infra
        end
        
        INT["Interface Layer (Traits for Clipboard, Sync, Storage)"]:::backend
    end

    %% Static Assets
    subgraph "Static Assets"
        PROT["Prototypes"]:::assets
        PUB["Public"]:::assets
    end

    %% Relationships
    FE -->|"TauriBridge"| A
    A -->|"routesTo"| APP
    APP -->|"uses"| DM
    APP -->|"invokes"| CORE
    APP -->|"accesses"| DB
    APP -->|"calls"| SEC
    APP -->|"syncsWith"| NET
    APP -->|"manages"| CONN
    NET -->|"communicates"| SYNC
    SYNC -->|"servedBy"| WEB
    CORE -->|"abstracts"| INT

    %% Optional interaction: Frontend may utilize static prototypes/assets
    FE ---|"fallbackViews"| PROT
    FE ---|"staticAssets"| PUB

    %% Click Events
    click FE "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src"
    click A "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/api"
    click APP "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/application"
    click DM "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/domain"
    click CORE "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/core"
    click DB "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/infrastructure/storage"
    click NET "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/infrastructure/network"
    click SEC "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/infrastructure/security"
    click CONN "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/infrastructure/connection"
    click SYNC "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/infrastructure/sync"
    click WEB "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/infrastructure/web"
    click INT "https://github.com/mkdir700/uniclipboard-desktop/tree/main/src-tauri/src/interface"
    click PROT "https://github.com/mkdir700/uniclipboard-desktop/tree/main/prototypes"
    click PUB "https://github.com/mkdir700/uniclipboard-desktop/tree/main/public"

    %% Styles
    classDef frontend fill:#ffa,stroke:#333,stroke-width:2px;
    classDef backend fill:#aaf,stroke:#333,stroke-width:2px;
    classDef infra fill:#afa,stroke:#333,stroke-width:2px;
    classDef assets fill:#fda,stroke:#333,stroke-width:2px;
```
