mirror of
https://github.com/bybrooklyn/alchemist.git
synced 2026-04-18 01:43:34 -04:00
5.5 KiB
5.5 KiB
Alchemist Project Audit & Findings
This document provides a comprehensive audit of the Alchemist media transcoding project (v0.3.0-rc.3), covering backend architecture, frontend design, database schema, and operational workflows.
1. Project Architecture & Pipeline
Alchemist implements a robust, asynchronous media transcoding pipeline managed by a central Agent. The pipeline follows a strictly ordered lifecycle:
- Scanner (
src/media/scanner.rs): Performs a high-speed traversal of watch folders. It usesmtime_hash(seconds + nanoseconds) to detect changes without full file analysis, efficiently handling re-scans and minimizing DB writes. - Analyzer (
src/media/analyzer.rs): Executesffprobeto extract normalized media metadata (codecs, bit depth, BPP, bitrate). Analysis results are used to populate theDetailedEncodeStatsandDecisiontables. - Planner (
src/media/planner.rs): A complex decision engine that evaluates whether to Skip, Remux, or Transcode a file based on user profiles.- Finding: The planning logic is heavily hardcoded with "magic thresholds" (e.g., Bits-per-pixel thresholds). While effective, these could be more exposed as "Advanced Settings" in the UI.
- Executor (
src/media/executor.rs): Orchestrates theffmpegprocess. It dynamically selects encoders (NVENC, VAAPI, QSV, ProRes, or CPU fallback) based on the target profile and host hardware capabilities detected insrc/system/hardware.rs.
2. Backend & API Design (Rust/Axum)
- Concurrency: Utilizes
tokiofor async orchestration andrayonfor CPU-intensive tasks (like file hashing or list processing). The scheduler supports multiple concurrency modes:Background(1 job),Balanced(capped), andThroughput(uncapped). - State Management: The backend uses
broadcastchannels to separate high-volume events (Progress, Logs) from low-volume system events (Config updates). This prevents UI "flicker" and unnecessary re-renders in the frontend. - API Structure:
- RESTful endpoints for jobs, settings, and stats.
- SSE (
src/server/sse.rs) for real-time progress updates, ensuring a reactive UI without high-frequency polling. - Auth (
src/server/auth.rs): Implements JWT-based authentication with Argon2 hashing for the initial setup.
3. Database Schema (SQLite/SQLx)
- Stability: The project uses 16+ migrations, showing a mature evolution from a simple schema to a sophisticated job-tracking system.
- Decision Logging: The
decisionsandjob_failure_explanationstables are a standout feature. They store the "why" behind every action as structured JSON, which is then humanized in the UI (e.g., explaining exactly why a file was skipped). - Data Integrity: Foreign keys and WAL (Write-Ahead Logging) mode ensure database stability even during heavy concurrent I/O.
4. Frontend Design (Astro/React/Helios)
- Stack: Astro 5 provides a fast, static-first framework with React 18 handles the complex stateful dashboards.
- Design System ("Helios"):
- Identity: A dark-themed, data-dense industrial aesthetic.
- Findings: While functional, the system suffers from "component bloat."
JobManager.tsx(~2,000 lines) is a significant maintainability risk. It contains UI logic, filtering logic, and data transformation logic mixed together.
- Data Visualization: Uses
rechartsfor historical trends and performance metrics.- Improvement: The charts are currently static snapshots. Adding real-time interactivity (brushing, zooming) would improve the exploration of large datasets.
5. System & Hardware Integration
- Hardware Discovery:
src/system/hardware.rsis extensive, detecting NVIDIA, Intel, AMD, and Apple Silicon capabilities. It correctly maps these toffmpegencoder flags. - FS Browser: A custom filesystem browser (
src/system/fs_browser.rs) allows for secure directory selection during setup, preventing path injection and ensuring platform-agnostic path handling.
6. Critical Areas for Improvement
Maintainability (High Priority)
- Decouple
JobManager.tsx: Refactor into functional hooks (useJobs,useFilters) and smaller, presentation-only components. - Standardize Formatters: Move
formatBytes,formatTime, andformatReductioninto a centralizedlib/formatters.tsto reduce code duplication across the Dashboard and Stats pages.
UX & Performance (Medium Priority)
- Polling vs. SSE: Ensure all real-time metrics (like GPU temperature) are delivered via SSE rather than periodic polling to reduce backend load and improve UI responsiveness.
- Interactive Decision Explanations: The current skip reasons are helpful but static. Adding links to the relevant settings (e.g., "Change this threshold in Transcoding Settings") would close the loop for users.
Reliability (Low Priority)
- E2E Testing: While Playwright tests exist, they focus on "reliability." Expanding these to cover complex "edge cases" (like network-attached storage disconnects during a scan) would improve long-term stability.
7. Stitch Recommendation
Use Stitch to generate atomic component refinements based on this audit.
- Prompt Example: "Refine the JobTable row to use iconic status indicators with tooltips for skip reasons, as outlined in the Alchemist Audit."
- Prompt Example: "Create a unified
Formatterutility library in TypeScript that handles bytes, time, and percentage formatting for the Helios design system."