# taoister39/tauri-motrix architecture

> Architecture diagram of the GitHub repository taoister39/tauri-motrix, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/taoister39/tauri-motrix
- Repository: https://github.com/taoister39/tauri-motrix

## Overview

##### Project Type and Purpose
- This is a full-stack, desktop application built with Tauri. It re-implements the Motrix download manager using:
- Frontend: React + TypeScript + MUI
- Backend: Rust (Tauri commands)
- Monorepo with supporting Node packages (aria2, torrent parsing) and auxiliary web & extension apps.
- Purpose: deliver a lightweight, cross-platform download manager that delegates heavy lifting to aria2, with a native UI via Tauri.

##### High-Level File Structure Analysis
- Root:
- .github/workflows, CI/CD configs
- package.json, pnpm-workspace.yaml, scripts/, build/test tooling
- apps/
- website/ (Next.js documentation site)
- extensions/ (JS build scripts for browser extensions)
- packages/
- aria2: Node library wrapping aria2 RPC
- torrent: Node library for magnet parsing
- src-tauri/
- Rust code defining Tauri CLI commands, services (aria2c, tray, logging, i18n), config, core logic, process handlers
- src/
- React app (UI components, business logic, state, hooks, services, store)
- tests/
- Jest + React Testing Library for front-end, HTTP tests for aria2c_api

##### Main Components
A. Monorepo Workspace
– Node toolchain (pnpm)
– Scripts & CI/CD pipelines
B. Frontend (src/)
– UI layer (React + MUI)
– Business modules (tasks, history, settings)
– State store (Zustand)
– Services:
- aria2c_api.ts (RPC client)
- database.ts (local persistence)
C. Backend (src-tauri/)
– Tauri commands (main.rs, lib.rs)
– Services layer (aria2c.rs spawns aria2, config, tray, log, i18n)
– Core layer (process orchestration, sys options)
– Config models & drafts
D. External Process
– aria2c CLI (128-threaded download engine)
E. Supporting Node Packages
– @project/aria2: RPC & utility wrappers
– @project/torrent: magnet & torrent parsing
F. Auxiliary Apps
– Website (Next.js) for docs
– Browser extensions (JS builds)
G. CI/CD
– GitHub Actions workflows: test, release, updater

##### Relationships & Data Flow
1. User interacts with React UI → calls a Tauri command via @tauri-apps/api
2. Tauri command handler routes to the appropriate Rust service (e.g., spawn aria2c, update config)
3. Rust service communicates with aria2c process over its JSON-RPC interface
4. aria2c emits events/status → Rust service captures and streams back to the frontend
5. Frontend updates state store & UI renders progress, history, speed graphs
6. Persistent data (download history, settings) is stored via local database service
7. Node packages (aria2, torrent) are imported by both frontend and scripts for parsing, RPC calls, and build processes
8. CI/CD pipelines validate code, run tests, package desktop builds, website deployments, and extension updates

##### Architectural Patterns & Principles
- Layered architecture in Rust: commands → services → core → process
- React/Flux variant with a centralized store (Zustand) + service‐based API calls
- Monorepo with workspace isolation for sharable logic (packages/)
- Event‐driven IPC between UI and native backend via Tauri
- Separation of concerns: UI, business logic, persistence, native services

##### Essential Elements Checklist
- All external dependencies (aria2c, local filesystem, OS tray) explicitly shown.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Monorepo Workspace
    subgraph "Monorepo Workspace"
        direction TB
        WorkspaceConfig["pnpm-workspace.yaml"]:::monorepo
        RootPackage["package.json"]:::monorepo
        Scripts["scripts/"]:::monorepo
        CIWorkflows[".github/workflows/"]:::cicd
    end

    %% Supporting Node Packages
    subgraph "Shared Node Packages"
        direction TB
        Aria2Pkg["@project/aria2"]:::packages
        TorrentPkg["@project/torrent"]:::packages
    end

    %% Auxiliary Applications
    subgraph "Auxiliary Apps"
        direction TB
        DocsSite["Website (Next.js)"]:::aux
        Extensions["Browser Extensions"]:::aux
    end

    %% Frontend Layer
    subgraph "Frontend (React + MUI)" 
        direction TB
        UIEntry["main.tsx"]:::frontend
        Pages["Pages (/src/pages/)"]:::frontend
        Layout["Layout (/src/layout/)"]:::frontend
        Components["Components (/src/components/)"]:::frontend
        Business["Business Modules (/src/business/)"]:::frontend
        Store["State Store (Zustand)"]:::frontend
        Aria2Client["aria2c_api.ts"]:::frontend
        DatabaseSvc["database.ts"]:::persistence
    end

    %% Backend Layer
    subgraph "Backend (Rust + Tauri)"
        direction TB
        TauriConf["tauri.conf.json"]:::backend
        subgraph "Command Handlers"
            direction TB
            MainCmd["main.rs"]:::backend
            AppCmd["app.rs"]:::backend
            Aria2Cmd["aria2.rs"]:::backend
            MotrixCmd["motrix.rs"]:::backend
        end
        subgraph "Services Layer"
            direction TB
            Aria2Svc["aria2c.rs"]:::backend
            TraySvc["tray.rs"]:::backend
            LogSvc["log.rs"]:::backend
            I18nSvc["i18n.rs"]:::backend
        end
        subgraph "Core Logic"
            direction TB
            CoreOrch["core.rs"]:::backend
            HandleCore["handle.rs"]:::backend
            SysOpt["sys_opt.rs"]:::backend
        end
        subgraph "Config Models"
            direction TB
            ConfigMod["config.rs"]:::backend
            DraftMod["draft.rs"]:::backend
            Aria2Conf["aria2.rs"]:::backend
            MotrixConf["motrix.rs"]:::backend
        end
        subgraph "Process Handlers"
            direction TB
            AsyncHandler["async_handler.rs"]:::backend
        end
    end

    %% External Process
    Aria2c["aria2c CLI"]:::process

    %% CI/CD
    subgraph "CI/CD Pipelines"
        direction TB
        PRWorkflow["pr.yml"]:::cicd
        TestWorkflow["test.yml"]:::cicd
        ReleaseWorkflow["release.yml"]:::cicd
        UpdaterWorkflow["updater.yml"]:::cicd
        UpdateScripts["scripts/ (updater.mjs, update_log.mjs)"]:::cicd
    end

    %% Relationships
    UIEntry -->|"imports"| Pages
    UIEntry --> Layout
    UIEntry --> Components
    UIEntry --> Business
    Business --> Store
    Business --> Aria2Client
    Business --> DatabaseSvc

    Pages -->|"renders UI"| Components
    Components -->|"dispatch actions"| Store

    Store -->|"invokeCommand('addTask')"| MainCmd
    Store -->|"invokeCommand('updateSettings')"| MotrixCmd

    MainCmd -->|routes| Aria2Svc
    Aria2Svc -->|spawns| Aria2c
    Aria2c -->|RPC events| Aria2Svc
    Aria2Svc -->|streams events| UIEntry

    MainCmd -->|routes| TraySvc
    MainCmd -->|routes| LogSvc
    MainCmd -->|routes| I18nSvc

    CoreOrch -->|orchestrates| AsyncHandler
    MainCmd -->|uses| CoreOrch

    ConfigMod -->|defines| Aria2Svc
    DraftMod -->|defines| Aria2Svc

    Aria2Client -->|JSON-RPC| Aria2Svc
    DatabaseSvc -->|reads/writes| FileSystem[("Local File System")]:::backend
    DatabaseSvc -->|persists| SettingsDB[("Local DB")]:::persistence

    Aria2Pkg -->|used by| Aria2Client
    Aria2Pkg -->|used by| Extensions
    TorrentPkg -->|used by| Business
    TorrentPkg -->|used by| DocsSite

    WorkspaceConfig -->|workspace| UIEntry
    RootPackage -->|defines deps| Aria2Pkg
    Scripts -->|runs build/test| UIEntry
    Scripts -->|runs updater| UpdateScripts

    CIWorkflows -->|runs| TestWorkflow
    CIWorkflows -->|runs| PRWorkflow
    CIWorkflows -->|runs| ReleaseWorkflow
    CIWorkflows -->|runs| UpdaterWorkflow

    DocsSite -->|deploys| CIWorkflows
    Extensions -->|builds| UpdateScripts

    %% Click Events
    click WorkspaceConfig "https://github.com/taoister39/tauri-motrix/blob/main//pnpm-workspace.yaml"
    click RootPackage "https://github.com/taoister39/tauri-motrix/blob/main//package.json"
    click Scripts "https://github.com/taoister39/tauri-motrix/tree/main//scripts/"
    click CIWorkflows "https://github.com/taoister39/tauri-motrix/tree/main//.github/workflows/"
    click UIEntry "https://github.com/taoister39/tauri-motrix/blob/main//src/main.tsx"
    click Pages "https://github.com/taoister39/tauri-motrix/tree/main//src/pages/"
    click Layout "https://github.com/taoister39/tauri-motrix/tree/main//src/layout/"
    click Components "https://github.com/taoister39/tauri-motrix/tree/main//src/components/"
    click Business "https://github.com/taoister39/tauri-motrix/tree/main//src/business/"
    click Store "https://github.com/taoister39/tauri-motrix/tree/main//src/store/"
    click Aria2Client "https://github.com/taoister39/tauri-motrix/blob/main//src/services/aria2c_api.ts"
    click DatabaseSvc "https://github.com/taoister39/tauri-motrix/blob/main//src/services/database.ts"
    click TauriConf "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/tauri.conf.json"
    click MainCmd "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/cmd/main.rs"
    click Aria2Svc "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/service/aria2c.rs"
    click TraySvc "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/service/tray.rs"
    click LogSvc "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/service/log.rs"
    click I18nSvc "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/service/i18n.rs"
    click CoreOrch "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/core/core.rs"
    click HandleCore "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/core/handle.rs"
    click SysOpt "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/core/sys_opt.rs"
    click ConfigMod "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/config/config.rs"
    click DraftMod "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/config/draft.rs"
    click AsyncHandler "https://github.com/taoister39/tauri-motrix/blob/main//src-tauri/src/process/async_handler.rs"
    click Aria2Pkg "https://github.com/taoister39/tauri-motrix/blob/main//packages/aria2/src/aria2.ts"
    click TorrentPkg "https://github.com/taoister39/tauri-motrix/blob/main//packages/torrent/src/magnet.ts"
    click DocsSite "https://github.com/taoister39/tauri-motrix/tree/main//apps/website/"
    click Extensions "https://github.com/taoister39/tauri-motrix/tree/main//apps/extensions/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6
    classDef backend fill:#DFFFE0,stroke:#22863A
    classDef persistence fill:#FFF5B1,stroke:#DAB200
    classDef process fill:#F0F0F0,stroke:#6a737d,stroke-dasharray: 5 5
    classDef packages fill:#FFEFEF,stroke:#cb2431
    classDef aux fill:#F5E1FF,stroke:#6f42c1
    classDef monorepo fill:#EDEDED,stroke:#444444
    classDef cicd fill:#FFE4E1,stroke:#d73a49
```
