Files
Jellymove/docs/ARCHITECTURE.md
T
IxianPixel 8ceb3c8be8
CI / test (push) Successful in 5m7s
Initial code commit
2026-11-05 14:19:37 +00:00

100 lines
4.8 KiB
Markdown

# Architecture
## Why this exists
As of November 2026 nothing published moves media between two Jellyfin
servers while understanding their libraries. Adjacent tools each cover one part:
| Need | Closest existing tool | Gap |
|---|---|---|
| Show two servers as one | Jellyswarrm (v0.3.1 deduplicates across servers) | Presentation only; media management not implemented |
| Move bytes hot ↔ cold | mergerfs cache movers, rclone union, rsync, Syncthing | Path- and size-based, single host or blind to Jellyfin; no rescans, no watch state |
| Carry watch state | JellySync, JellyPlex-Watched | No file movement |
| Policy-driven cleanup | Janitorr / Maintainerr | Deletes rather than demotes |
jellymove joins these into one flow that knows about libraries.
## Topology
One binary, run as an agent next to each Jellyfin. Each agent has:
- local filesystem access at the same paths Jellyfin uses
- an admin API key for its own Jellyfin
- the other agent's URL and a shared token
Jobs always run on the **destination**, which pulls. Whichever UI the user
starts from, the job ends up there: `POST /api/moves {from: "local"}` asks the
peer to create the job, and `{from: "peer"}` creates it locally. This keeps the
code that copies, verifies, promotes and deletes next to the disk it touches,
and lets a NATed home server pull from a public cloud server with no port
forwarding.
## Peer protocol (`/peer/v1`, Bearer token)
| Route | Purpose |
|---|---|
| `GET /info` | Node name, version, Jellyfin version |
| `GET /libraries`, `GET /items?library=&search=` | Browse the peer's Jellyfin |
| `POST /exports {item_id}` | Source: start checking, hashing and capturing user data. Idempotent per item. |
| `GET /exports/{id}` | Poll: `Preparing` → `Ready` (with `ExportInfo`) or `Failed` |
| `GET /exports/{id}/files/{idx}` | Range-capable download of manifest entry `idx` |
| `POST /exports/{id}/complete` | Source: move folder to trash and rescan. Idempotent. |
| `POST /jobs`, `GET /jobs` | Create or list jobs on the peer (destination) |
## Job stages
`Job.stage` is the last *completed* milestone. The runner performs the next step:
```
Created ──plan──▶ ExportReady ──copy──▶ Copied ──promote──▶ Promoted
──wait for scan──▶ TargetScanned ──apply user data──▶ UserDataApplied
──clean source──▶ SourceCleaned ──hook──▶ Done
```
`JobStatus` is orthogonal: Queued / Running / Planned (dry run) / Failed / Done.
Retrying a failed job re-runs from its stage. Interrupted jobs resume on start.
## Transfer
- HTTP `Range` pull into `<dest library>/.jellymove-partial/<job>/<idx>.part`.
The `.part` length is the resume offset, so no extra state is needed.
- BLAKE3 hash computed by the source (memory-mapped, multithreaded) and checked
by the destination after the last byte. A mismatch discards the part.
- Exponential backoff, 20 attempts by default; 4xx errors are permanent.
- Token-bucket bandwidth cap (`governor`) shared across transfers.
- Delta sync is deliberately absent: media is written once, so whole-file
transfer with resume beats rolling checksums.
- Alternatives kept open behind the pull/serve split: iroh (QUIC, NAT
traversal) once iroh-blobs reaches 1.0; rclone as a pluggable transport.
## Jellyfin integration
- Browse: `GET /Items?parentId=<library>&includeItemTypes=Movie,Series&recursive=true&fields=Path,…`
- Folder: a movie's parent folder, or a series' own folder. It must sit strictly
inside a library location. A movie folder must contain no other main videos.
- Rescan: `POST /Library/Media/Updated` for the exact folder, then poll. The
first update can be lost, so it is re-sent halfway through the timeout.
- Finding the new item: by **path**, since we know exactly where we put it.
This is more reliable than provider IDs, which may be missing or differ.
Episodes are matched by (season, episode).
- User data: captured per user from `GET /Items?userId=…`, written with
`POST /UserItems/{id}/UserData?userId=…`, users matched by name.
## Why Svelte rather than Slint
Slint is a native GUI toolkit. A headless daemon needs a browser UI, so the UI
is a Svelte 5 SPA compiled into the binary with `rust-embed`, the same
single-binary model Jellyswarrm uses. Live progress uses Server-Sent Events
for jobs on this node, and polling for jobs on the peer.
## Known risks
1. New item IDs after a move break anything keyed by ID: playlists,
collections, Jellyseerr links, Jellyswarrm's cache (#216).
2. Jellyswarrm's merge key for movies and series isn't documented upstream,
and its pipeline is being rewritten.
3. PUID/PGID and mount mismatches. The Status tab probes every location for
existence and write access.
4. Large scans: some Jellyfin versions re-save thousands of items on a full
scan, so jellymove only ever requests path-scoped updates.