# thevindu-w/clip_share_server architecture

> Architecture diagram of the GitHub repository thevindu-w/clip_share_server, 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/thevindu-w/clip_share_server
- Repository: https://github.com/thevindu-w/clip_share_server

## Overview

##### Project Type & Purpose
- This is a cross‐platform, lightweight server written in C focused on clipboard and file sharing between devices. It is designed to run as a background service and communicates with client applications via TCP (both unencrypted and TLS-encrypted) and UDP (for network scanning).
- Its primary function is to receive clipboard data (text, files, images) from one device and deliver them to another, while also optionally providing web interface capabilities (if enabled).

##### Key Components
a. Core Server Application:
– The main executable (clip_share) as the central process.
– It is built from source using the Makefile (and GCC), thus the build process and platform-specific behaviors should be referenced only briefly.
b. Protocol and Server Modules:
– The “src/proto” module handles protocol methods (negotiation, version handling, and method dispatching).
– “src/servers” contains implementations for different services: e.g., clip_share.c (likely the core server loop), clip_share_web.c (web mode handlers), udp_serve.c (UDP service) and even an assembly page_blob.S.
c. Utilities and Helpers:
– “src/utils” supply support routines (configuration, network utilities, list management, platform-specific functions such as for macOS menus or Windows image handling).
– Separate modules exist for X-specific integration (src/xclip) and screenshot functionality (src/xscreenshot).
d. Configuration & TLS Security:
– The server reads its configuration from clipshare.conf (searched in several directories) which drives its behavior including port settings and enabling/disabling features (e.g., secure_mode_enabled, web_mode_enabled).
– TLS handling (server_cert, ca_cert) is essential when secure mode is enabled. Helper scripts in “helper_tools” (keygen.sh/keygen.ps1) are used to generate keys and certificates.
e. External Dependencies and Environment:
– External libraries like libunistring, libssl, and libpng are key parts of the technical stack.
– The docker/ directory indicates containerized deployment options for the ClipShare server.

##### Relationships and Interactions
– External Clients (the mobile app, or any other client adhering to the protocol) initiate connections either over:
- TCP port 4337 (for unencrypted traffic),
- TCP port 4338 (for TLS-encrypted traffic),
- UDP (Port 4337 for broadcast-based discovery),
- TCP port 4339 (for web-based service if enabled).
– The server listens on these ports and routes the incoming requests to the protocol handler (in src/proto), which then dispatches to the relevant server module (in src/servers) based on the method (e.g., get_text, send_file, etc.).
– Utility modules (in src/utils) provide support functions such as configuration parsing and network operations.
– The configuration management component loads "clipshare.conf", influencing server behavior (ports, TLS certificate paths, allowed clients, etc.).
– OS-specific integration (via src/xclip and src/xscreenshot) handles tasks such as interfacing with the clipboard or capturing screenshots.
– The build automation (Makefile, integration tests in tests/) and continuous integration (GitHub workflows) ensure quality and consistency of the build.

##### Architectural Patterns & Design Principles
– Modular Design: The project separates concerns through distinct modules for networking, protocol handling, server logic, configuration, and utilities.
– Layered Architecture: Presentation (network APIs and OS integration) is clearly separated from business logic (protocol processing and server operations).
– Cross-Platform Considerations: The use of platform-specific directories and resources (e.g., src/res for Windows and Mac) shows an emphasis on platform abstraction.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["External Clients"]:::external
    B["ClipShare Server (Main Executable)"]:::core
    C["Protocol Handler (src/proto)"]:::core
    D["Server Modules (src/servers)"]:::core
    E["Utility Layer (src/utils)"]:::utility
    G["Configuration Manager (clipshare.conf)"]:::config
    H["TLS & Security Component (helper_tools)"]:::security
    I["External Libraries (libssl, libpng, libunistring)"]:::libraries
    J["Docker Environment (docker)"]:::deployment

    subgraph "OS/Platform Specific Modules"
        F1["Clipboard Integration (src/xclip)"]:::os
        F2["Screenshot Functionality (src/xscreenshot)"]:::os
    end

    A -->|"TCP4337_TCP4338_UDP4337_TCP4339"| B
    B -->|"uses"| C
    C -->|"dispatches_to"| D
    E -->|"provides_utilities"| D
    E -->|"supports"| B
    G -->|"configures"| B
    G -->|"configures"| C
    G -->|"configures"| D
    F1 -->|"integrates"| B
    F2 -->|"integrates"| B
    H -->|"handles_TLS"| B
    I -->|"provides_deps"| B
    J -->|"deployment"| B

    click B "https://github.com/thevindu-w/clip_share_server/blob/master/src/main.c"
    click C "https://github.com/thevindu-w/clip_share_server/tree/master/src/proto"
    click D "https://github.com/thevindu-w/clip_share_server/tree/master/src/servers"
    click E "https://github.com/thevindu-w/clip_share_server/tree/master/src/utils"
    click F1 "https://github.com/thevindu-w/clip_share_server/tree/master/src/xclip"
    click F2 "https://github.com/thevindu-w/clip_share_server/tree/master/src/xscreenshot"
    click G "https://github.com/thevindu-w/clip_share_server/blob/master/tests/config/clipshare.conf"
    click H "https://github.com/thevindu-w/clip_share_server/tree/master/helper_tools"
    click J "https://github.com/thevindu-w/clip_share_server/tree/master/docker"

    classDef core fill:#FFEB99,stroke:#333,stroke-width:2px;
    classDef utility fill:#B3E5FC,stroke:#333,stroke-width:2px;
    classDef config fill:#F8BBD0,stroke:#333,stroke-width:2px;
    classDef security fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#333,stroke-width:2px;
    classDef os fill:#C5E1A5,stroke:#333,stroke-width:2px;
    classDef deployment fill:#D1C4E9,stroke:#333,stroke-width:2px;
    classDef libraries fill:#FFE0B2,stroke:#333,stroke-width:2px;
```
