Skip to content

Architecture EN

zipax-bot edited this page Aug 11, 2026 · 1 revision

Architecture

Overview

┌─────────────────────────────────────────────────┐
│          Frontend (React + TypeScript)          │
│   src/ · hooks/ · components/ · store/ · styles │
└──────────────────────┬──────────────────────────┘
                       │ Tauri IPC (invoke)
┌──────────────────────▼──────────────────────────┐
│        Tauri shell zipax-app (src-tauri)        │
│  lib.rs · commands · autostart · tray · watcher │
│  gs_install · app_window · file_commands ...    │
└──────────────────────┬──────────────────────────┘
                       │ Rust function calls
┌──────────────────────▼──────────────────────────┐
│          zipax-core (shared core)               │
│  compress/ · plan/ · config/ · format/ · utils  │
└─────────────────────────────────────────────────┘
        ▲                          ▲
        │                          │
┌───────┴───────┐          ┌───────┴────────┐
│   zipax-cli   │          │  Filesystem /  │
│  (CLI entry)  │          │  external (GS) │
└───────────────┘          └────────────────┘

Cargo Workspace

  • zipax-cross/Cargo.toml — workspace root, resolver = "2", shared versions & deps
  • crates/zipax-core — compression engine (no platform deps, shared by app & CLI)
  • crates/zipax-cli — CLI entry (testing & automation)
  • src-tauri — Tauri desktop app (crate name zipax-app)

Rust Core Modules (zipax-core)

Module Responsibility
compress/ Per-format compression: jpeg.rs png.rs webp.rs avif.rs heic.rs pdf.rs image_pdf.rs
plan.rs Compression planning (plan_compression → CompressionPlan), size/target prediction
config.rs Config parsing: CompressionMode, OutputFormat, QualityLevel, ResizeOptions
format.rs Format detection (ImageKind)
error.rs Error types (Error / Result)
image_io.rs Image read/write wrappers
process.rs Multi-file batch processing
utils.rs Utilities

Tauri Modules (src-tauri)

commands.rs is split into focused modules:

Module Responsibility
commands.rs Core compression commands (compress_file / compress_batch / plan_compression / get_app_info)
autostart.rs Launch-at-login read/write (incl. Windows registry path fix)
tray_commands.rs Tray menu state (close-to-tray, auto-update, automation toggles)
watch_commands.rs Folder watching (watch_folder / stop_all_watchers)
file_commands.rs File ops (save_temp_image / copy_file)
gs_install.rs One-click Ghostscript install (cross-platform)
compression_options.rs Compression option mapping
compression_runtime.rs Compression runtime (concurrency queue)
state.rs Tauri managed state (AppBehaviorState / TrayMenuState / WatcherState)
watcher.rs notify wrapper
app_window.rs Main window config (frameless, transparent, auto-size)

Tauri Command Registration (lib.rs)

.invoke_handler(tauri::generate_handler![
    commands::compress_file,
    commands::compress_batch,
    commands::plan_compression,
    commands::get_app_info,
    autostart::set_autostart_enabled,
    autostart::get_autostart_enabled,
    gs_install::install_ghostscript,
    tray_commands::set_close_to_tray_enabled,
    tray_commands::get_close_to_tray_enabled,
    tray_commands::set_tray_status,
    watch_commands::watch_folder,
    watch_commands::stop_all_watchers,
    file_commands::save_temp_image,
    file_commands::copy_file,
])

Startup & System Integration

  • Single instance: tauri-plugin-single-instance — re-launches bring up the main window
  • Tray: TrayIcon + menu (open / stats / auto-update toggle / automation toggle / quit)
  • Close to tray: when close_to_tray is true, close events are intercepted and the window is hidden
  • macOS: uses macos-private-api and ActivationPolicy::Accessory for activation policy switching
  • Window: frameless + transparent (decorations: false, transparent: true), auto-sizes to content after page load
  • Auto-update: tauri-plugin-updater, endpoint is the GitHub Release latest.json

Frontend Structure

src/
├── main.tsx / App.tsx        # Entry & routing
├── i18n.ts                   # i18n (English / Chinese, and more)
├── store/                    # Zustand (types / app / utils)
├── hooks/                    # useAutoWindowSize, useManualCompressionActions,
│                             # useAutomationRules, useUpdateCheck, useAppEffects ...
├── components/               # ManualCompression, AutomationView, GeneralView,
│                             # WorkflowView, WindowFrame, UpdatePrompt, ui/ ...
├── lib/                      # tauri.ts (command wrappers), update.ts, format.ts, utils.ts
└── styles/                   # base / components / manual / automation / settings /
                              # config / motion / window / about

Back to Home-EN · 中文版:架构设计

Clone this wiki locally