# standardagents/ssh-clipboard architecture

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

- Interactive diagram: https://gitdiagram.com/standardagents/ssh-clipboard
- Repository: https://github.com/standardagents/ssh-clipboard

## Overview

#### Purpose and entry points
`ssh-clipboard` is a Rust CLI and per-user daemon that synchronizes native clipboard content directly between machines over persistent SSH connections. The user entry point is the npm-installed launcher at `bin/ssh-clipboard.js`, which selects a platform binary; Rust starts in `src/main.rs` and exposes shared functionality through `src/lib.rs`.

#### CLI, setup, and TUI
The interactive CLI coordinates first-run setup, peer repair, monitoring, status, and updates. `src/tui/setup.rs` drives peer selection and provisioning; `src/tui/monitor.rs` presents live peer/version health and update actions. Tailscale is optional discovery support, while arbitrary passwordless SSH peers remain supported.
- `src/main.rs`
- `src/tui/setup.rs`
- `src/tui/monitor.rs`

#### Peer configuration and domain model
Persistent local state describes this node, configured peers, service state, and synchronization metadata. `src/config.rs` owns configuration persistence, while `src/model.rs` defines shared domain structures used across setup, protocol, service, and UI boundaries.
- `src/config.rs`
- `src/model.rs`
- `src/protocol.rs`

#### SSH transport and synchronization protocol
`src/ssh.rs` establishes and maintains encrypted SSH connectivity to peers. `src/protocol.rs` defines peer messages for clipboard transfer, health/status, and update gossip. The protocol carries raw clipboard representations rather than terminal encodings, allowing native content fidelity and peer-to-peer operation without a relay or separate account system.
- `src/ssh.rs`
- `src/protocol.rs`
- `src/filebundle.rs`

#### Native clipboard capture and application
The clipboard subsystem bridges OS-native clipboard APIs to transferable payloads. `src/clipboard.rs` is the platform-neutral boundary; macOS support is isolated in `src/clipboard/macos.rs`. File bundles are handled separately so native file paste behavior can be preserved alongside text, images, and rich formats.
- `src/clipboard.rs`
- `src/clipboard/macos.rs`
- `src/filebundle.rs`

#### Background daemon and service lifecycle
The daemon owns continuous clipboard observation, deduplication/newest-value queueing, active peer sessions, periodic update checks, and inbound payload application. `src/daemon.rs` is the long-running control loop; `src/service.rs` manages per-user OS service installation/reconciliation, targeting launchd on macOS and systemd on Linux.
- `src/daemon.rs`
- `src/service.rs`
- `src/deploy.rs`

#### Deployment and verified updates
Remote setup/deployment transfers or installs the correct target binary without replacing a peer’s identity or peer configuration. `src/update.rs` independently checks npm’s stable release, verifies package integrity and bundled manifests, atomically swaps binaries, and requests service restart. Nodes gossip verified target versions, avoiding a permanent update coordinator.
- `src/deploy.rs`
- `src/update.rs`
- `scripts/stage-npm-binaries.mjs`

#### Distribution and runtimes
The core runtime is Rust on macOS/Linux, arm64/x64, with Ratatui for terminal UI. npm distributes platform binaries and the JavaScript launcher. Optional Tailscale integration supplies machine discovery; SSH is the required transport. The documentation site is a separate Vue/Vite application with a Cloudflare Worker deployment target.
- `Cargo.toml`
- `package.json`
- `docs/worker/index.js`

Main entry points: [`src/daemon.rs`](https://github.com/standardagents/ssh-clipboard/blob/main/src/daemon.rs) (Background daemon), [`src/main.rs`](https://github.com/standardagents/ssh-clipboard/blob/main/src/main.rs) (Rust entry point), [`src/protocol.rs`](https://github.com/standardagents/ssh-clipboard/blob/main/src/protocol.rs) (Peer protocol), [`src/tui/setup.rs`](https://github.com/standardagents/ssh-clipboard/blob/main/src/tui/setup.rs) (Setup flow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["CLI &amp; UI"]
  node_rust_entry["Rust entry point<br/>CLI entry<br/>[main.rs]"]
  node_setup_tui["Setup flow<br/>interactive TUI<br/>[setup.rs]"]
  node_monitor_tui["Monitor flow<br/>interactive TUI<br/>[monitor.rs]"]
end

subgraph group_runtime["Sync Runtime"]
  node_config[("Local configuration<br/>state persistence<br/>[config.rs]")]
  node_model["Domain model<br/>shared types<br/>[model.rs]"]
  node_daemon{{"Background daemon<br/>control loop<br/>[daemon.rs]"}}
  node_clipboard["Clipboard boundary<br/>native clipboard API<br/>[clipboard.rs]"]
  node_macos_clipboard["macOS clipboard<br/>platform adapter<br/>[macos.rs]"]
  node_filebundle["File bundles<br/>clipboard payloads<br/>[filebundle.rs]"]
  node_protocol["Peer protocol<br/>wire messages<br/>[protocol.rs]"]
  node_ssh["SSH transport<br/>encrypted peer transport<br/>[ssh.rs]"]
  node_service["Service lifecycle<br/>OS service manager<br/>[service.rs]"]
  node_deploy["Peer deployment<br/>remote provisioning<br/>[deploy.rs]"]
  node_update["Verified updates<br/>update manager<br/>[update.rs]"]
end

subgraph group_distribution["Distribution"]
  node_npm_launcher["npm launcher<br/>JavaScript launcher<br/>[ssh-clipboard.js]"]
  node_npm_package["npm package<br/>package distribution<br/>[package.json]"]
  node_binary_staging["Binary staging<br/>release pipeline"]
  node_docs_worker["Documentation deployment<br/>Cloudflare Worker<br/>[index.js]"]
  node_rust_manifest["Rust runtime<br/>Cargo package<br/>[Cargo.toml]"]
end

node_npm_launcher -->|"launches platform binary"| node_rust_entry
node_npm_package -->|"ships"| node_npm_launcher
node_binary_staging -->|"stages binaries"| node_npm_package
node_rust_manifest -->|"builds"| node_rust_entry
node_rust_entry -->|"runs setup"| node_setup_tui
node_rust_entry -->|"runs monitor"| node_monitor_tui
node_rust_entry -->|"starts daemon"| node_daemon
node_setup_tui -->|"configures peers"| node_config
node_setup_tui -->|"provisions peers"| node_deploy
node_monitor_tui -->|"reads live health"| node_daemon
node_monitor_tui -->|"triggers update"| node_update
node_daemon -->|"observes and applies"| node_clipboard
node_clipboard -->|"uses on macOS"| node_macos_clipboard
node_clipboard -->|"preserves files"| node_filebundle
node_daemon -->|"encodes peer events"| node_protocol
node_protocol -->|"travels over"| node_ssh
node_ssh -->|"supports remote install"| node_deploy
node_daemon -->|"uses persistent state"| node_config
node_config -->|"stores"| node_model
node_protocol -->|"shares types"| node_model
node_service -->|"installs and restarts"| node_daemon
node_update -->|"requests restart"| node_service
node_update -.->|"gossips target versions"| node_protocol

click node_npm_launcher "https://github.com/standardagents/ssh-clipboard/blob/main/bin/ssh-clipboard.js"
click node_rust_entry "https://github.com/standardagents/ssh-clipboard/blob/main/src/main.rs"
click node_setup_tui "https://github.com/standardagents/ssh-clipboard/blob/main/src/tui/setup.rs"
click node_monitor_tui "https://github.com/standardagents/ssh-clipboard/blob/main/src/tui/monitor.rs"
click node_config "https://github.com/standardagents/ssh-clipboard/blob/main/src/config.rs"
click node_model "https://github.com/standardagents/ssh-clipboard/blob/main/src/model.rs"
click node_daemon "https://github.com/standardagents/ssh-clipboard/blob/main/src/daemon.rs"
click node_clipboard "https://github.com/standardagents/ssh-clipboard/blob/main/src/clipboard.rs"
click node_macos_clipboard "https://github.com/standardagents/ssh-clipboard/blob/main/src/clipboard/macos.rs"
click node_filebundle "https://github.com/standardagents/ssh-clipboard/blob/main/src/filebundle.rs"
click node_protocol "https://github.com/standardagents/ssh-clipboard/blob/main/src/protocol.rs"
click node_ssh "https://github.com/standardagents/ssh-clipboard/blob/main/src/ssh.rs"
click node_service "https://github.com/standardagents/ssh-clipboard/blob/main/src/service.rs"
click node_deploy "https://github.com/standardagents/ssh-clipboard/blob/main/src/deploy.rs"
click node_update "https://github.com/standardagents/ssh-clipboard/blob/main/src/update.rs"
click node_npm_package "https://github.com/standardagents/ssh-clipboard/blob/main/package.json"
click node_binary_staging "https://github.com/standardagents/ssh-clipboard/blob/main/scripts/stage-npm-binaries.mjs"
click node_docs_worker "https://github.com/standardagents/ssh-clipboard/blob/main/docs/worker/index.js"
click node_rust_manifest "https://github.com/standardagents/ssh-clipboard/blob/main/Cargo.toml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_rust_entry,node_setup_tui,node_monitor_tui toneBlue
class node_config,node_model,node_daemon,node_clipboard,node_macos_clipboard,node_filebundle,node_protocol,node_ssh,node_service,node_deploy,node_update toneAmber
class node_npm_launcher,node_npm_package,node_binary_staging,node_docs_worker,node_rust_manifest toneMint
```

## Components

### CLI & UI

- [Rust entry point](https://github.com/standardagents/ssh-clipboard/blob/main/src/main.rs): CLI entry · `src/main.rs`
- [Setup flow](https://github.com/standardagents/ssh-clipboard/blob/main/src/tui/setup.rs): interactive TUI · Selects and provisions peers. · `src/tui/setup.rs`
- [Monitor flow](https://github.com/standardagents/ssh-clipboard/blob/main/src/tui/monitor.rs): interactive TUI · Shows peer health and update actions. · `src/tui/monitor.rs`

### Sync Runtime

- [Local configuration](https://github.com/standardagents/ssh-clipboard/blob/main/src/config.rs): state persistence · Persists node, peers, service state, and sync metadata. · `src/config.rs`
- [Domain model](https://github.com/standardagents/ssh-clipboard/blob/main/src/model.rs): shared types · `src/model.rs`
- [Background daemon](https://github.com/standardagents/ssh-clipboard/blob/main/src/daemon.rs): control loop · Observes, deduplicates, queues, and applies clipboard changes. · `src/daemon.rs`
- [Clipboard boundary](https://github.com/standardagents/ssh-clipboard/blob/main/src/clipboard.rs): native clipboard API · `src/clipboard.rs`
- [macOS clipboard](https://github.com/standardagents/ssh-clipboard/blob/main/src/clipboard/macos.rs): platform adapter · `src/clipboard/macos.rs`
- [File bundles](https://github.com/standardagents/ssh-clipboard/blob/main/src/filebundle.rs): clipboard payloads · Preserves native file paste behavior. · `src/filebundle.rs`
- [Peer protocol](https://github.com/standardagents/ssh-clipboard/blob/main/src/protocol.rs): wire messages · Carries clipboard, health, and update gossip messages. · `src/protocol.rs`
- [SSH transport](https://github.com/standardagents/ssh-clipboard/blob/main/src/ssh.rs): encrypted peer transport · Maintains persistent direct peer connections. · `src/ssh.rs`
- [Service lifecycle](https://github.com/standardagents/ssh-clipboard/blob/main/src/service.rs): OS service manager · Reconciles launchd or systemd per-user services. · `src/service.rs`
- [Peer deployment](https://github.com/standardagents/ssh-clipboard/blob/main/src/deploy.rs): remote provisioning · Installs target binaries without replacing peer identity or configuration. · `src/deploy.rs`
- [Verified updates](https://github.com/standardagents/ssh-clipboard/blob/main/src/update.rs): update manager · Verifies npm release artifacts and atomically swaps binaries. · `src/update.rs`

### Distribution

- [npm launcher](https://github.com/standardagents/ssh-clipboard/blob/main/bin/ssh-clipboard.js): JavaScript launcher · Selects the platform binary. · `bin/ssh-clipboard.js`
- [npm package](https://github.com/standardagents/ssh-clipboard/blob/main/package.json): package distribution · Distributes launcher and platform binaries. · `package.json`
- [Binary staging](https://github.com/standardagents/ssh-clipboard/blob/main/scripts/stage-npm-binaries.mjs): release pipeline · `scripts/stage-npm-binaries.mjs`
- [Documentation deployment](https://github.com/standardagents/ssh-clipboard/blob/main/docs/worker/index.js): Cloudflare Worker · Separate Vue/Vite documentation deployment target. · `docs/worker/index.js`
- [Rust runtime](https://github.com/standardagents/ssh-clipboard/blob/main/Cargo.toml): Cargo package · macOS/Linux arm64/x64 CLI runtime. · `Cargo.toml`

## Connections

- npm launcher → Rust entry point: launches platform binary
- npm package → npm launcher: ships
- Binary staging → npm package: stages binaries
- Rust runtime → Rust entry point: builds
- Rust entry point → Setup flow: runs setup
- Rust entry point → Monitor flow: runs monitor
- Rust entry point → Background daemon: starts daemon
- Setup flow → Local configuration: configures peers
- Setup flow → Peer deployment: provisions peers
- Monitor flow → Background daemon: reads live health
- Monitor flow → Verified updates: triggers update
- Background daemon → Clipboard boundary: observes and applies
- Clipboard boundary → macOS clipboard: uses on macOS
- Clipboard boundary → File bundles: preserves files
- Background daemon → Peer protocol: encodes peer events
- Peer protocol → SSH transport: travels over
- SSH transport → Peer deployment: supports remote install
- Background daemon → Local configuration: uses persistent state
- Local configuration → Domain model: stores
- Peer protocol → Domain model: shares types
- Service lifecycle → Background daemon: installs and restarts
- Verified updates → Service lifecycle: requests restart
- Verified updates → Peer protocol: gossips target versions
