-
Notifications
You must be signed in to change notification settings - Fork 10
Architecture
Jules Martins edited this page May 12, 2026
·
3 revisions
MangoFetch is built with a modular, crate-based architecture designed for performance, memory safety, and minimal dependency overhead. It is written entirely in Rust.
The repository is organized as a workspace with three primary crates:
-
mangofetch-core: The engine. UI-agnostic library containing:- Download Manager: Queue handling, task scheduling, and state persistence.
- Platform Registry: A modular system where different "Extractors" are registered.
- Dependency Engine: Logic to ensure FFmpeg and yt-dlp are available.
-
mangofetch-cli: The binary. A thin wrapper over the core that provides:- The
clap-based command line interface. - The
ratatui-based Terminal User Interface.
- The
-
mangofetch-plugin-sdk: Tools and traits to build 3rd-party platform extractors.
Understanding how a URL becomes a file on your disk:
-
Extraction Phase: The
PlatformRegistryidentifies the correct downloader (e.g., YouTubeDownloader). It fetches metadata (Title, Author, Qualities) without downloading the media. -
Queueing Phase: The item is added to the
DownloadQueue. If the slot is available, it transitions toActive. -
Execution Phase:
- For standard videos, we invoke yt-dlp with specific performance flags.
- For direct links, we use a custom Rust-native HTTP downloader with multi-segment support.
- For P2P/Torrents, we utilize specialized crates for swarm connectivity.
- Post-Processing Phase: FFmpeg is invoked to merge streams (e.g., VP9 video + Opus audio) or to embed metadata and thumbnails.
-
Finalization: The file is moved to the target directory, and the session is saved to
recovery.json.
MangoFetch takes security seriously:
- Sandboxed Subprocesses: We sanitize all inputs before passing them to external tools like FFmpeg.
- Cookie Protection: User cookies used for authentication (e.g., for age-restricted content) are handled securely and never logged.
- No Telemetry: MangoFetch does not "phone home". All download data remains local to your machine.
-
Async/Await: The entire engine is powered by
tokio, allowing it to handle thousands of concurrent network events with negligible CPU usage. - Zero-Copy Buffering: When downloading direct files, we minimize memory copies to maximize disk I/O throughput.
- Staggered Starts: We implement a staggering algorithm to avoid triggering rate-limiting when starting massive batch downloads.