# kde/kdeconnect-kde architecture

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

- Interactive diagram: https://gitdiagram.com/kde/kdeconnect-kde
- Repository: https://github.com/kde/kdeconnect-kde

## Overview

##### Main system type and purpose
- Type: A modular desktop application built on top of a “core” C++ library exposing DBus interfaces, with multiple UI front‑ends and plugins.
- Purpose: Allow devices (e.g. phone↔computer) to communicate over TLS, sharing clipboard, notifications, files, multimedia controls, SMS, etc.

##### Break down the top‑level components
- Core Library (“core/”):
– LinkProviders (bluetooth, lan, loopback)
– Device abstraction & NetworkPacket handling
– Plugin loader & SSL helper
– Exposes DBus interfaces (core/dbushelper.cpp)
- Daemon (“daemon/”):
– desktop_daemon (kdeconnectd) that runs headless, registers with system DBus
- UI & Integration Layers:
– app/ (QtQuick QML desktop UI)
– cli/ (kdeconnect‑cli tool)
– settings/ (Settings QML + desktop KCM)
– indicator/ (system tray indicator for Plasma, Windows, macOS)
– kcmplugin/ (KDE System Settings module)
– nautilus‑extension/, kio/ (File‑manager integration)
– plasmoid/ (Plasma widget)
– smsapp/ (standalone SMS QML app)
– urlhandler/ (URL share handler)
– declarativeplugin/ (common QML/DBus glue for various front‑ends)
- Plugins (“plugins/*”):
– Individual feature plugins (battery, clipboard, ping, sftp, …)
– Defined by JSON metadata + C++/QML code
– Loaded at runtime by core PluginLoader
- Tests (“tests/”):
– Unit and integration tests against core and plugins

##### Relationships and data flows
- DBus Bus (system and session) sits in the middle:
– UI front‑ends ⟷ Core Library (DBus method calls & signals)
- Core Library ⟷ PluginLoader (dynamic load at startup)
- Core Library ⟷ LinkProviders: discovers & maintains Device links
- Core Library ⟷ Remote Device (over TLS via LinkProvider) using NetworkPackets
- Plugins register handlers with Core Library; they exchange JSON packets + optional binary payload over the Device link
- Daemon registers core on system DBus so multiple front‑ends can connect

##### Architectural patterns & principles
- Modular plugin architecture: plugins loaded dynamically, communicate only through well‑defined Packet types
- Microkernel‑style core: UI‑agnostic, exposes services (device discovery, packet routing) via DBus
- Separation of concerns:
– LinkProviders handle connectivity
– Core handles device and packet management
– Plugins implement features
– UIs consume DBus APIs
- Cross‑platform abstraction: OS‑specific code isolated in small helper classes (indicatorhelper_mac.cpp, win, Linux X11/Wayland, QML, etc.)

##### Technologies & frameworks
- CMake & Craft build system (CMakeLists.txt, KDEConnectMacros.cmake)
- Qt (QtCore, QtDBus, QtNetwork, QtQuick/QML)
- DBus (org.kde.kdeconnect service interfaces in interfaces/ and declarativeplugin/)
- JSON for NetworkPackets, plugin metadata
- TLS via OpenSSL (sslhelper.cpp)
- mDNS (for LAN discovery)
- Bluetooth stack (for Bluetooth discovery/link)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    DBusBus["DBus Bus"]:::external
    RemoteDevice["Remote Device\n(TLS Link)"]:::external
    OpenSSL["OpenSSL"]:::external
    BluetoothStack["Bluetooth Stack"]:::external
    mDNSDaemon["mDNS Daemon"]:::external

    %% Core Library
    subgraph "Core Library" 
        direction TB
        PluginLoader["PluginLoader"]:::core
        Device["Device"]:::core
        NetworkPacket["NetworkPacket"]:::core
        SSLHelper["SSLHelper"]:::core
        DBusHelper["DBusHelper"]:::core
        subgraph "LinkProviders" 
            direction TB
            Bluetooth["bluetooth"]:::connectivity
            LAN["lan"]:::connectivity
            Loopback["loopback"]:::connectivity
        end
    end

    %% Daemon
    subgraph "Daemon"
        direction TB
        DaemonExec["kdeconnectd\n(desktop_daemon)"]:::core
    end

    %% UI & Integration
    subgraph "UI Front-Ends"
        direction TB
        App["QtQuick Desktop UI\n(app)"]:::ui
        CLI["kdeconnect-cli"]:::ui
        SettingsApp["Settings App"]:::ui
        KCMPlugin["KCM Module"]:::ui
        Indicator["System Tray Indicator"]:::ui
        NautilusExt["Nautilus Extension"]:::ui
        KIO["KIO Integration"]:::ui
        Plasmoid["Plasma Widget"]:::ui
        SMSApp["SMS QML App"]:::ui
        URLHandler["URL Share Handler"]:::ui
        DeclarativePlugin["Declarative Plugin"]:::ui
    end

    %% Plugins
    subgraph "Plugins"
        direction TB
        PluginsCluster["Feature Plugins"]:::plugins
    end

    %% Tests
    subgraph "Tests"
        direction TB
        TestsCluster["Unit & Integration Tests"]:::external
    end

    %% Relationships
    App -->|DBus calls/signals| DBusBus
    CLI -->|DBus calls| DBusBus
    SettingsApp -->|DBus calls/signals| DBusBus
    KCMPlugin -->|DBus calls| DBusBus
    Indicator -->|DBus calls/signals| DBusBus
    NautilusExt -->|calls| CoreLibrary
    KIO -->|calls| CoreLibrary
    Plasmoid -->|DBus calls| DBusBus
    SMSApp -->|DBus calls/signals| DBusBus
    URLHandler -->|DBus calls| DBusBus
    DeclarativePlugin -->|DBus glue| DBusBus

    DBusBus -->|registered by| DaemonExec
    DaemonExec -->|loads| PluginLoader
    PluginLoader -->|loads| PluginsCluster
    CoreLibrary---DBusBus
    PluginLoader -->|registers LinkProviders| Bluetooth
    PluginLoader --> LAN
    PluginLoader --> Loopback

    BluetoothStack --> Bluetooth
    mDNSDaemon --> LAN
    OpenSSL --> SSLHelper

    Device <-->|Packet Exchange| RemoteDevice
    Device --> NetworkPacket
    PluginsCluster -->|JSON packets| Device

    DBusBus -->|signals/events| App
    DBusBus -->|signals/events| SMSApp

    %% Click Events - Core Library
    click PluginLoader "https://github.com/kde/kdeconnect-kde/blob/master/core/pluginloader.cpp"
    click Device "https://github.com/kde/kdeconnect-kde/blob/master/core/device.cpp"
    click NetworkPacket "https://github.com/kde/kdeconnect-kde/blob/master/core/networkpacket.cpp"
    click SSLHelper "https://github.com/kde/kdeconnect-kde/blob/master/core/sslhelper.cpp"
    click DBusHelper "https://github.com/kde/kdeconnect-kde/blob/master/core/dbushelper.cpp"
    click Bluetooth "https://github.com/kde/kdeconnect-kde/tree/master/core/backends/bluetooth/"
    click LAN "https://github.com/kde/kdeconnect-kde/tree/master/core/backends/lan/"
    click Loopback "https://github.com/kde/kdeconnect-kde/tree/master/core/backends/loopback/"

    %% Click Events - Daemon
    click DaemonExec "https://github.com/kde/kdeconnect-kde/blob/master/daemon/desktop_daemon.cpp"

    %% Click Events - UI
    click App "https://github.com/kde/kdeconnect-kde/blob/master/app/main.cpp"
    click CLI "https://github.com/kde/kdeconnect-kde/blob/master/cli/kdeconnect-cli.cpp"
    click SettingsApp "https://github.com/kde/kdeconnect-kde/blob/master/settings/main.cpp"
    click KCMPlugin "https://github.com/kde/kdeconnect-kde/blob/master/kcmplugin/kdeconnectpluginkcm.cpp"
    click Indicator "https://github.com/kde/kdeconnect-kde/blob/master/indicator/main.cpp"
    click NautilusExt "https://github.com/kde/kdeconnect-kde/blob/master/nautilus-extension/kdeconnect-share.py"
    click KIO "https://github.com/kde/kdeconnect-kde/blob/master/kio/kiokdeconnect.cpp"
    click Plasmoid "https://github.com/kde/kdeconnect-kde/tree/master/plasmoid/"
    click SMSApp "https://github.com/kde/kdeconnect-kde/blob/master/smsapp/main.cpp"
    click URLHandler "https://github.com/kde/kdeconnect-kde/blob/master/urlhandler/kdeconnect-handler.cpp"
    click DeclarativePlugin "https://github.com/kde/kdeconnect-kde/blob/master/declarativeplugin/kdeconnectdeclarativeplugin.cpp"

    %% Click Events - Plugins & Tests
    click PluginsCluster "https://github.com/kde/kdeconnect-kde/tree/master/plugins/"
    click TestsCluster "https://github.com/kde/kdeconnect-kde/tree/master/tests/"

    %% Styles
    classDef core fill:#cce5ff,stroke:#003366,color:#003366;
    classDef plugins fill:#d4edda,stroke:#155724,color:#155724;
    classDef ui fill:#fff3cd,stroke:#856404,color:#856404;
    classDef connectivity fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef external fill:#f8d7da,stroke:#721c24,color:#721c24;
```
