# sentry-six/sentry-usb-rusty architecture

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

- Interactive diagram: https://gitdiagram.com/sentry-six/sentry-usb-rusty
- Repository: https://github.com/sentry-six/sentry-usb-rusty

## Overview

Sentry USB turns a Raspberry Pi into a Tesla dashcam USB drive, then exposes captured clips, trip history, telemetry, and device controls through a browser UI. The main flow is Tesla clip writes to the USB gadget, telemetry sampling over BLE, and API access to drive and clip data. The README also documents background archiving, cloud sync, notifications, setup, and a synchronized multi-camera viewer. Several links below are documented capabilities; unsampled implementation details are not asserted.

Main entry points: [`crates/api/src/router.rs`](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/router.rs) (HTTP API router), [`crates/drives/src/db.rs`](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/drives/src/db.rs) (Drive store), [`crates/tesla_telemetry/src/main.rs`](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/tesla_telemetry/src/main.rs) (BLE telemetry sampler), [`crates/sentryusb/src/main.rs`](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/sentryusb/src/main.rs) (Sentry USB server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Vehicle capture"]
  node_gadget["USB dashcam drive<br/>[lib.rs]"]
  node_telemetry["BLE telemetry sampler<br/>[main.rs]"]
  node_ble["Tesla BLE session<br/>[manager.rs]"]
  node_sample_ble["BLE sample decoding<br/>[sample_ble.rs]"]
end

subgraph group_data["Drive data"]
  node_clips["Clip access<br/>[clips.rs]"]
  node_drive_api["Drive API<br/>[drives_handler.rs]"]
  node_drive_store[("Drive store<br/>[db.rs]")]
  node_drive_grouping["Trip grouping<br/>[grouper.rs]"]
end

subgraph group_service["Device services"]
  node_api_router["HTTP API router<br/>[router.rs]"]
  node_server["Sentry USB server<br/>[main.rs]"]
  node_preferences[("Preferences<br/>[preferences.rs]")]
  node_setup_api["Setup API<br/>[setup.rs]"]
  node_setup_runner["Device setup<br/>[runner.rs]"]
  node_notifications["Notification dispatch<br/>[notifications.rs]"]
end

subgraph group_web["Web experience"]
  node_web_app["Web application<br/>[App.tsx]"]
  node_viewer["Multi-camera viewer<br/>[Viewer.tsx]"]
end

subgraph group_sync["Archive and integrations"]
  node_archive["Archive methods<br/>[archive.rs]"]
  node_cloud_sync["Encrypted cloud sync<br/>[sync.rs]"]
  node_notification_providers["Notification providers"]
end

node_tesla(("Tesla vehicle"))
node_web_user(("Browser user"))
node_cloud[("Sentry Cloud")]
node_archive_target[("NAS or cloud archive")]

node_tesla -->|"writes clips"| node_gadget
node_tesla -->|"BLE telemetry"| node_ble
node_telemetry -->|"queries"| node_ble
node_telemetry -->|"samples through"| node_sample_ble
node_telemetry -->|"persists samples"| node_drive_store
node_gadget -->|"signals car awake"| node_telemetry
node_api_router -->|"routes clips"| node_clips
node_api_router -->|"routes drives"| node_drive_api
node_drive_api -->|"reads drive data"| node_drive_store
node_drive_store -->|"groups trips"| node_drive_grouping
node_server -->|"opens store"| node_drive_store
node_server -->|"builds router"| node_api_router
node_web_user -->|"uses"| node_web_app
node_web_app -.->|"requests API"| node_api_router
node_web_app -.->|"opens viewer"| node_viewer
node_api_router -->|"routes setup"| node_setup_api
node_setup_api -.->|"runs setup"| node_setup_runner
node_api_router -.->|"routes preferences"| node_preferences
node_api_router -->|"routes notifications"| node_notifications
node_notifications -->|"dispatches through"| node_notification_providers
node_server -.->|"configures archiving"| node_archive
node_archive -->|"archives clips"| node_archive_target
node_drive_store -.->|"syncs drive data"| node_cloud_sync
node_cloud_sync -->|"encrypted sync"| node_cloud

click node_gadget "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/usb_gadget/src/lib.rs"
click node_telemetry "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/tesla_telemetry/src/main.rs"
click node_ble "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/tesla_ble/src/manager.rs"
click node_sample_ble "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/tesla_telemetry/src/sample_ble.rs"
click node_clips "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/clips.rs"
click node_drive_api "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/drives_handler.rs"
click node_drive_store "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/drives/src/db.rs"
click node_drive_grouping "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/drives/src/grouper.rs"
click node_api_router "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/router.rs"
click node_server "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/sentryusb/src/main.rs"
click node_preferences "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/preferences.rs"
click node_setup_api "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/setup.rs"
click node_setup_runner "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/setup/src/runner.rs"
click node_notifications "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/notifications.rs"
click node_web_app "https://github.com/sentry-six/sentry-usb-rusty/blob/main/web/src/App.tsx"
click node_viewer "https://github.com/sentry-six/sentry-usb-rusty/blob/main/web/src/pages/Viewer.tsx"
click node_archive "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/setup/src/archive.rs"
click node_cloud_sync "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/cloud_uploader/src/sync.rs"
click node_notification_providers "https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/notification_providers.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_gadget,node_telemetry,node_ble,node_sample_ble,node_web_user toneBlue
class node_clips,node_drive_api,node_drive_store,node_drive_grouping,node_cloud,node_archive_target toneAmber
class node_api_router,node_server,node_preferences,node_setup_api,node_setup_runner,node_notifications toneMint
class node_web_app,node_viewer toneRose
class node_archive,node_cloud_sync,node_notification_providers,node_tesla toneIndigo
```

## Components

### Vehicle capture

- [USB dashcam drive](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/usb_gadget/src/lib.rs): `crates/usb_gadget/src/lib.rs`
- [BLE telemetry sampler](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/tesla_telemetry/src/main.rs): `crates/tesla_telemetry/src/main.rs`
- [Tesla BLE session](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/tesla_ble/src/manager.rs): `crates/tesla_ble/src/manager.rs`
- [BLE sample decoding](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/tesla_telemetry/src/sample_ble.rs): `crates/tesla_telemetry/src/sample_ble.rs`

### Drive data

- [Clip access](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/clips.rs): `crates/api/src/clips.rs`
- [Drive API](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/drives_handler.rs): `crates/api/src/drives_handler.rs`
- [Drive store](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/drives/src/db.rs): `crates/drives/src/db.rs`
- [Trip grouping](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/drives/src/grouper.rs): `crates/drives/src/grouper.rs`

### Device services

- [HTTP API router](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/router.rs): `crates/api/src/router.rs`
- [Sentry USB server](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/sentryusb/src/main.rs): `crates/sentryusb/src/main.rs`
- [Preferences](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/preferences.rs): `crates/api/src/preferences.rs`
- [Setup API](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/setup.rs): `crates/api/src/setup.rs`
- [Device setup](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/setup/src/runner.rs): `crates/setup/src/runner.rs`
- [Notification dispatch](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/notifications.rs): `crates/api/src/notifications.rs`

### Web experience

- [Web application](https://github.com/sentry-six/sentry-usb-rusty/blob/main/web/src/App.tsx): `web/src/App.tsx`
- [Multi-camera viewer](https://github.com/sentry-six/sentry-usb-rusty/blob/main/web/src/pages/Viewer.tsx): `web/src/pages/Viewer.tsx`

### Archive and integrations

- [Archive methods](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/setup/src/archive.rs): `crates/setup/src/archive.rs`
- [Encrypted cloud sync](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/cloud_uploader/src/sync.rs): `crates/cloud_uploader/src/sync.rs`
- [Notification providers](https://github.com/sentry-six/sentry-usb-rusty/blob/main/crates/api/src/notification_providers.rs): `crates/api/src/notification_providers.rs`

### Other components

- **Tesla vehicle**
- **Browser user**
- **Sentry Cloud**
- **NAS or cloud archive**

## Connections

- Tesla vehicle → USB dashcam drive: writes clips (evidence: `README.md`)
- Tesla vehicle → Tesla BLE session: BLE telemetry (evidence: `README.md`)
- BLE telemetry sampler → Tesla BLE session: queries (evidence: `crates/tesla_telemetry/src/main.rs`)
- BLE telemetry sampler → BLE sample decoding: samples through (evidence: `crates/tesla_telemetry/src/main.rs`)
- BLE telemetry sampler → Drive store: persists samples (evidence: `crates/tesla_telemetry/src/main.rs`)
- USB dashcam drive → BLE telemetry sampler: signals car awake (evidence: `crates/tesla_telemetry/src/main.rs`)
- HTTP API router → Clip access: routes clips (evidence: `crates/api/src/router.rs`)
- HTTP API router → Drive API: routes drives (evidence: `crates/api/src/router.rs`)
- Drive API → Drive store: reads drive data (evidence: `crates/api/src/drives_handler.rs`)
- Drive store → Trip grouping: groups trips (evidence: `crates/drives/src/grouper.rs`)
- Sentry USB server → Drive store: opens store (evidence: `crates/sentryusb/src/main.rs`)
- Sentry USB server → HTTP API router: builds router (evidence: `crates/sentryusb/src/main.rs`)
- Browser user → Web application: uses (evidence: `README.md`)
- Web application → HTTP API router: requests API
- Web application → Multi-camera viewer: opens viewer
- HTTP API router → Setup API: routes setup (evidence: `crates/api/src/router.rs`)
- Setup API → Device setup: runs setup
- HTTP API router → Preferences: routes preferences (evidence: `crates/api/src/router.rs`)
- HTTP API router → Notification dispatch: routes notifications (evidence: `crates/api/src/router.rs`)
- Notification dispatch → Notification providers: dispatches through (evidence: `crates/api/src/notifications.rs`)
- Sentry USB server → Archive methods: configures archiving
- Archive methods → NAS or cloud archive: archives clips (evidence: `README.md`)
- Drive store → Encrypted cloud sync: syncs drive data
- Encrypted cloud sync → Sentry Cloud: encrypted sync (evidence: `README.md`)
