> For the complete documentation index, see [llms.txt](https://docs.r2drop.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.r2drop.com/reference/architecture.md). Agents can also search and read this documentation through its [MCP server](https://docs.r2drop.com/~gitbook/mcp).

# Architecture

A brief overview of how R2Drop is built — useful for contributors and anyone curious about what happens under the hood.

***

## Components

```
R2Drop
├── macOS App (Swift/SwiftUI)
│   ├── Menu bar icon + window (5 tabs)
│   ├── Finder Sync Extension (right-click menu)
│   └── App Groups (shared SQLite with extension)
│
├── Upload Engine (Rust)
│   ├── r2-core — S3 client, multipart logic, queue, history
│   ├── r2-ffi  — C FFI bridge (Swift calls into Rust)
│   └── r2-cli  — Standalone CLI binary
│
└── Local Data (~/.r2drop/)
    ├── config.toml — accounts + preferences
    ├── queue.db    — upload queue (SQLite)
    ├── history.db  — upload history (SQLite)
    └── r2drop.sock — IPC socket (CLI ↔ app)
```

***

## Upload Flow

1. User triggers an upload (Finder, drag-drop, CLI, deep link)
2. Upload is added to `queue.db` with status `pending`
3. The Rust engine picks it up and begins a multipart S3 upload directly to Cloudflare R2
4. Progress is written back to `queue.db` in real time
5. On completion, the entry moves to `history.db` and the public URL is returned
6. The app copies the URL to the clipboard and fires a macOS notification

Files go **directly from your Mac to Cloudflare R2**. R2Drop's servers are never in the data path.

***

## Tech Stack

| Layer         | Technology                                                 |
| ------------- | ---------------------------------------------------------- |
| UI            | Swift + SwiftUI (macOS 13+)                                |
| Upload engine | Rust (tokio async, aws-sdk-s3)                             |
| FFI           | Rust `staticlib` + `cbindgen` → C header → Swift           |
| Database      | SQLite via `rusqlite`                                      |
| Config        | TOML (`~/.r2drop/config.toml`)                             |
| Credentials   | macOS Keychain (`Security.framework`)                      |
| IPC           | Unix socket (`r2drop.sock`) + shared SQLite via App Groups |
| Auto-updates  | Sparkle framework                                          |
| Distribution  | `.dmg` from GitHub Releases                                |
| CI/CD         | GitHub Actions                                             |

***

## S3 Credential Derivation

Cloudflare R2 uses S3-compatible authentication. R2Drop derives S3 credentials from the user's Cloudflare API token:

* **Access Key ID** = the API token's UUID (stored as `token_id` in config.toml, retrieved from `/user/tokens/verify`)
* **Secret Access Key** = SHA-256 hex hash of the full API token string

This is a Cloudflare R2 convention — the same derivation is used by Wrangler and other R2 tools.

***

## Security Model

* **No R2Drop servers in the data path** — files go directly to Cloudflare R2
* **Keychain-only credentials** — API tokens never written to disk or config files
* **Least-privilege token design** — users are guided to create tokens scoped to specific R2 buckets
* **Open source** — every network call the app makes is auditable at [github.com/superhumancorp/r2drop](https://github.com/superhumancorp/r2drop)

***

## Finder Sync Extension

The right-click *Send to R2* menu item is implemented as a macOS Finder Sync Extension.

The extension communicates with the main app via **App Groups shared SQLite** (not XPC). This approach is simpler and avoids XPC permission complexities.

App Group identifier: `group.com.superhumancorp.r2drop`

***

## CI/CD Pipelines

| Workflow          | Trigger            | What it does                                      |
| ----------------- | ------------------ | ------------------------------------------------- |
| `ci.yml`          | Push/PR to `main`  | Build + lint                                      |
| `release.yml`     | Tag `v*`           | Sign, notarize, publish `.dmg`, bump Homebrew tap |
| `cli-release.yml` | Tag `cli-v*`       | Build CLI (macOS arm64 + x86\_64)                 |
| `deploy-www.yml`  | Push to `src/www/` | Deploy website to Cloudflare Pages                |
