# quackduck/uniclip architecture

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

- Interactive diagram: https://gitdiagram.com/quackduck/uniclip
- Repository: https://github.com/quackduck/uniclip

## Overview

##### Main Components
- CLI/Entry Point: The main function in uniclip.go parses command-line arguments (like --secure, --debug, the address, or port) and directs execution either to start a new clipboard (i.e. acting as a server) or to join an existing one (i.e. as a client).
- Network Module: Whether running in server or client mode, the tool establishes a TCP connection (or similar socket communication) to either listen for incoming connections or connect to a host.
- Clipboard Manager: This component interacts with the system’s clipboard (using libraries or commands like xsel, xclip, or platform-specific APIs) to copy or paste data across devices.
- Optional Features:
- Security Layer: When the --secure flag is active, an encryption module or logic might be invoked to secure clipboard data.
- Debugging/Logging: Integrated through the command-line flag to print more verbose output.

##### Understand the Interactions
- In server (host) mode: The CLI sets up a listener on a specific port and prints out the connection info. It then waits for incoming connection requests from client devices.
- In client (joining) mode: The CLI connects to the provided host address and port, establishing a communication channel with the server.
- Once connected, both modules interact by sending clipboard updates between the host and its connected peers.
- That since multiple devices can join the same clipboard session, the server component needs to handle multiple peer connections concurrently.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Even within a single file, think of logical separation between CLI processing, network communication, and clipboard management.

- A “Security Module” connected between the network transmission lines and the Clipboard Manager if the secure flag is enabled.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CLI["CLI Interface"]:::cli
    Debug["Debugging/Logging"]:::logging

    subgraph "Modes"
        Server["Clipboard Server (Host Mode)"]:::server
        Client["Clipboard Client (Join Mode)"]:::client
    end

    Network["Network Module"]:::network
    Sec["Security Module"]:::security
    Manager["Clipboard Manager"]:::clipboard

    %% CLI outputs to Modes and Debug
    CLI -->|"if_server_mode"| Server
    CLI -->|"if_client_mode"| Client
    CLI -->|"enableDebug"| Debug

    %% Server and Client use Network Module
    Server -->|"listen/accept"| Network
    Client -->|"connect_to_host"| Network

    %% Optional Security Layer between Network and Clipboard Manager
    Network -->|"if--secure_active"| Sec
    Sec -->|"encrypt/decrypt"| Manager

    %% Data exchange between Server and Client (for multiple peers)
    Server -->|"broadcast_clipboard_data"| Client
    Client -->|"send_clipboard_data"| Server

    %% Styles
    classDef cli fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef server fill:#e6e6fa,stroke:#333,stroke-width:2px;
    classDef client fill:#ffe6e6,stroke:#333,stroke-width:2px;
    classDef network fill:#ccf2ff,stroke:#333,stroke-width:2px;
    classDef security fill:#ffebcc,stroke:#333,stroke-width:2px;
    classDef clipboard fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef logging fill:#ffffcc,stroke:#333,stroke-width:2px;

    %% Click Events
    click CLI "https://github.com/quackduck/uniclip/blob/master/uniclip.go"
    click Debug "https://github.com/quackduck/uniclip/blob/master/uniclip.go"
    click Network "https://github.com/quackduck/uniclip/blob/master/uniclip.go"
    click Sec "https://github.com/quackduck/uniclip/blob/master/uniclip.go"
    click Manager "https://github.com/quackduck/uniclip/blob/master/uniclip.go"
```
