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 120-second timeout and builds normalized media metadata.BasicPlannerdecides skip, remux, or transcode 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 freezeDraining: 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 with 120-second timeoutexecutor.rs: FFmpeg execution pathprocessor.rs:Agentloop and engine-state handlingscanner.rs: filesystem scanninghealth.rs: Library Doctor checksffmpeg/: encoder-specific FFmpeg builders
Other core files
src/db.rs: SQLite access layer and projectionssrc/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 |