Architecture
Alchemist is a single Rust application that serves the API, embeds the frontend, runs the scan/plan/encode pipeline, and persists state in SQLite.
Pipeline
Scanner
-> Agent
-> FfmpegAnalyzer
-> BasicPlanner
-> FfmpegExecutor
-> post-encode checks and promotion
-> database update
Practical flow:
Scannerfinds files and enqueues jobs.Agentinsrc/media/processor.rsclaims queued jobs and applies engine-state and concurrency rules.FfmpegAnalyzerrunsffprobewith a 30-second timeout, builds normalized media metadata, and attaches a factual analyzer report with labels and optional metrics for later explanation/intelligence work.BasicPlannerdecides skip, remux, or transcode from the stable metadata fields and selects the best available encoder.FfmpegExecutorruns FFmpeg.- Post-encode logic optionally runs VMAF, promotes the temp output, records decisions and stats, and updates job state.
Engine state machine
States:
RunningPausedDrainingSchedulerPaused
Behavior:
Running: jobs start up to the active concurrency limitPaused: no new jobs start; active jobs continueDraining: active jobs finish; no new jobs startSchedulerPaused: pause state enforced by schedule windows
Engine modes
| Mode | Formula |
|---|---|
| Background | 1 |
| Balanced | floor(cpu_count / 2), minimum 1, maximum 4 |
| Throughput | floor(cpu_count / 2), minimum 1, uncapped |
Manual concurrency overrides can replace the computed limit without changing the mode.
Source layout
src/server/
mod.rs:AppState, router assembly, static asset servingauth.rs: login, logout, session cookiesjobs.rs: queue endpoints, engine control, job detailsscan.rs: manual scan endpointssettings.rs: config and projection handlersstats.rs: stats and savings endpointssystem.rs: health, readiness, resources, hardware, setup FS helperssse.rs: SSE multiplexingmiddleware.rs: auth, security headers, rate limitingwizard.rs: first-run setup flow
src/media/
pipeline.rs: pipeline interfaces and plan typesplanner.rs:BasicPlanner, skip/remux/transcode decisionsanalyzer.rs: FFprobe wrapper, normalized metadata, analyzer labels/metricsexecutor.rs: FFmpeg execution pathprocessor.rs:Agentloop and engine-state handlingscanner.rs: filesystem scanninghealth.rs: Library Doctor checksffmpeg/: encoder-specific FFmpeg builders
src/db/
SQLite access layer, migration runner, and typed projections.
Split into focused submodules — no ORM, direct sqlx usage:
mod.rs: connection pool, migrations, shared setuptypes.rs: row structs shared across modulesjobs.rs: queue mutations, lifecycle, archival, health-check sweepsconversion.rs: Convert-workflow upload/output tracking and cleanup queriesstats.rs: aggregates, savings history, daily rollupsconfig.rs: persisted settings projectionssystem.rs: watch dirs, library profiles, schema/version info, API tokensprobe_cache.rs: FFprobe result cache keyed by path, mtime, size, and probe versionhardware_cache.rs: persisted selected hardware/probe-log cache keyed by runtime fingerprintevents.rs: typed broadcast channel plumbing
Other core files
src/config.rs: TOML config structs, defaults, validationsrc/orchestrator.rs: FFmpeg subprocess control and cancellation
Tech stack
| Layer | Technology |
|---|---|
| Language | Rust 2024 |
| MSRV | Rust 1.85 |
| Async runtime | Tokio |
| HTTP | Axum 0.7 |
| Database | sqlx 0.8 |
| Storage | SQLite WAL |
| Frontend | Astro + React + TypeScript |
| Styling | Tailwind |
| Embedding | rust-embed |