# jayunewal/device-handoff architecture

> Architecture diagram of the GitHub repository jayunewal/device-handoff, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jayunewal/device-handoff
- Repository: https://github.com/jayunewal/device-handoff

## Overview

Baton moves portable work between paired devices: users pair devices, send links, text or files, and receive them into an inbox. Its Rust core owns device and session behavior, protocol types, transfer, and planned window streaming; CLI and Flutter/FFI expose those capabilities. The README also documents relay fallback and end-to-end encryption, while the sampled files do not establish detailed runtime call paths across most core subsystems, so those links are documented at subsystem level rather than expanded into guessed pipelines.

Main entry points: [`crates/baton-app/src/app.rs`](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-app/src/app.rs) (App API), [`crates/baton-core/src/pairing.rs`](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/pairing.rs) (Identity and pairing), [`crates/baton-core/src/session.rs`](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/session.rs) (Secure sessions), [`crates/baton-core/src/transfer/incoming.rs`](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/transfer/incoming.rs) (File transfer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User clients"]
  node_cli["CLI commands<br/>[mod.rs]"]
  node_cli_context["CLI context<br/>[context.rs]"]
end

subgraph group_bridge["App bridge"]
  node_app_api["App API<br/>[app.rs]"]
  node_app_models["App values<br/>[model.rs]"]
  node_ffi["Dart bridge<br/>[baton.rs]"]
  node_ffi_models["Dart values<br/>[model.rs]"]
end

subgraph group_core["Device core"]
  node_identity_pairing["Identity and pairing<br/>[pairing.rs]"]
  node_trust[("Device trust<br/>[trust.rs]")]
  node_session["Secure sessions<br/>[session.rs]"]
  node_protocol["Wire protocol<br/>[message.rs]"]
end

subgraph group_exchange["Exchange features"]
  node_inbox[("Received inbox<br/>[inbox.rs]")]
  node_transfer["File transfer<br/>[incoming.rs]"]
  node_transfer_wire["Transfer messages<br/>[mod.rs]"]
  node_filesystem["File operations<br/>[lib.rs]"]
end

subgraph group_stream["Window streaming"]
  node_stream_core["Stream sessions<br/>[mod.rs]"]
  node_stream_rules["Frame and input rules<br/>[gate.rs]"]
end

node_person(("Person"))
node_peer(("Paired device"))
node_relay{{"Internet relay"}}

node_person -->|"runs commands"| node_cli
node_person -->|"uses app"| node_app_api
node_cli -->|"opens state"| node_cli_context
node_cli_context -->|"loads identity"| node_identity_pairing
node_app_api -->|"returns values"| node_app_models
node_ffi -->|"bridges calls"| node_app_api
node_ffi -->|"exposes values"| node_ffi_models
node_ffi_models -->|"mirrors values"| node_app_models
node_app_api -->|"pairs devices"| node_identity_pairing
node_identity_pairing -.->|"establishes trust"| node_trust
node_app_api -->|"reads inbox"| node_inbox
node_app_api -->|"sends files"| node_transfer
node_transfer -.->|"exchanges messages"| node_transfer_wire
node_transfer -.->|"places received files"| node_filesystem
node_peer -->|"exchanges data"| node_session
node_identity_pairing -.->|"authenticates sessions"| node_session
node_session -.->|"carries messages"| node_protocol
node_session -->|"falls back to relay"| node_relay
node_app_api -->|"offers windows"| node_stream_core
node_stream_core -->|"applies frame rules"| node_stream_rules

click node_cli "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-cli/src/commands/mod.rs"
click node_cli_context "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-cli/src/context.rs"
click node_app_api "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-app/src/app.rs"
click node_app_models "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-app/src/model.rs"
click node_ffi "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-ffi/src/api/baton.rs"
click node_ffi_models "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-ffi/src/api/model.rs"
click node_identity_pairing "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/pairing.rs"
click node_trust "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/trust.rs"
click node_session "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/session.rs"
click node_protocol "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-proto/src/message.rs"
click node_inbox "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/inbox.rs"
click node_transfer "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/transfer/incoming.rs"
click node_transfer_wire "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-proto/src/transfer/mod.rs"
click node_filesystem "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-fs/src/lib.rs"
click node_stream_core "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/streaming/mod.rs"
click node_stream_rules "https://github.com/jayunewal/device-handoff/blob/main/crates/baton-stream/src/gate.rs"

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_cli,node_cli_context toneBlue
class node_app_api,node_app_models,node_ffi,node_ffi_models toneAmber
class node_identity_pairing,node_trust,node_session,node_protocol toneMint
class node_inbox,node_transfer,node_transfer_wire,node_filesystem toneRose
class node_stream_core,node_stream_rules,node_person,node_peer,node_relay toneIndigo
```

## Components

### User clients

- [CLI commands](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-cli/src/commands/mod.rs): `crates/baton-cli/src/commands/mod.rs`
- [CLI context](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-cli/src/context.rs): `crates/baton-cli/src/context.rs`

### App bridge

- [App API](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-app/src/app.rs): `crates/baton-app/src/app.rs`
- [App values](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-app/src/model.rs): `crates/baton-app/src/model.rs`
- [Dart bridge](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-ffi/src/api/baton.rs): `crates/baton-ffi/src/api/baton.rs`
- [Dart values](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-ffi/src/api/model.rs): `crates/baton-ffi/src/api/model.rs`

### Device core

- [Identity and pairing](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/pairing.rs): `crates/baton-core/src/pairing.rs`
- [Device trust](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/trust.rs): `crates/baton-core/src/trust.rs`
- [Secure sessions](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/session.rs): `crates/baton-core/src/session.rs`
- [Wire protocol](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-proto/src/message.rs): `crates/baton-proto/src/message.rs`

### Exchange features

- [Received inbox](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/inbox.rs): `crates/baton-core/src/inbox.rs`
- [File transfer](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/transfer/incoming.rs): `crates/baton-core/src/transfer/incoming.rs`
- [Transfer messages](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-proto/src/transfer/mod.rs): `crates/baton-proto/src/transfer/mod.rs`
- [File operations](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-fs/src/lib.rs): `crates/baton-fs/src/lib.rs`

### Window streaming

- [Stream sessions](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-core/src/streaming/mod.rs): `crates/baton-core/src/streaming/mod.rs`
- [Frame and input rules](https://github.com/jayunewal/device-handoff/blob/main/crates/baton-stream/src/gate.rs): `crates/baton-stream/src/gate.rs`

### Other components

- **Person**
- **Paired device**
- **Internet relay**

## Connections

- Person → CLI commands: runs commands (evidence: `README.md`)
- Person → App API: uses app (evidence: `README.md`)
- CLI commands → CLI context: opens state (evidence: `crates/baton-cli/src/commands/mod.rs`)
- CLI context → Identity and pairing: loads identity (evidence: `crates/baton-cli/src/context.rs`)
- App API → App values: returns values (evidence: `crates/baton-app/src/app.rs`)
- Dart bridge → App API: bridges calls (evidence: `README.md`)
- Dart bridge → Dart values: exposes values (evidence: `crates/baton-ffi/src/api/model.rs`)
- Dart values → App values: mirrors values (evidence: `crates/baton-ffi/src/api/model.rs`)
- App API → Identity and pairing: pairs devices (evidence: `README.md`)
- Identity and pairing → Device trust: establishes trust
- App API → Received inbox: reads inbox (evidence: `README.md`)
- App API → File transfer: sends files (evidence: `README.md`)
- File transfer → Transfer messages: exchanges messages
- File transfer → File operations: places received files
- Paired device → Secure sessions: exchanges data (evidence: `README.md`)
- Identity and pairing → Secure sessions: authenticates sessions
- Secure sessions → Wire protocol: carries messages
- Secure sessions → Internet relay: falls back to relay (evidence: `README.md`)
- App API → Stream sessions: offers windows (evidence: `README.md`)
- Stream sessions → Frame and input rules: applies frame rules (evidence: `crates/baton-core/src/streaming/mod.rs`)
