Skip to content

leeroybrun/clara

Repository files navigation

Clara - Magic background removal app

Clara - Magic background removal app

Clara is a cross-platform background removal application built with Wails. It combines a native Go backend with a React (Vite) interface and supports multiple “engines” (local ONNX Runtime presets, optional RMBG-2.0, and an IMG.LY Web engine).

Highlights

  • Queue UX: virtualized queue list (handles large batches), per-item preview, keyboard shortcuts, onboarding modal.
  • Multiple engines: local ONNX Runtime engine (preset-based models like U²‑Net / BiRefNet), RMBG‑2.0 engine, and optional IMG.LY Web engine (WASM, consent-gated).
  • Output modes + formats: cutout/mask/composite; outputs in PNG/JPG/WebP (mask forces PNG).
  • Optimisation pipeline: optional post-processing via built-in and external optimizer tools (installable per platform; format/mode aware).
  • Automation + file ops: folder watch + auto-import, deterministic destination naming with duplicate handling, optional timestamp preservation, “Reveal in Explorer/Finder”.

System Requirements

Platform Minimum Notes
macOS 11 Big Sur Apple Silicon & Intel supported
Windows 10 (19045) WebView2 runtime must be present
Linux Ubuntu 22.04 / Fedora 38 libwebkit2gtk (Wails dependency)
Toolchain (dev/build) Go 1.22+, Node 22+, npm 10+, Wails CLI

Project Structure

.
├── backend/                  # Go backend (config, filesystem, Wails bindings)
├── pkg/                      # Go domain packages (engine, models, imgly, optimizers)
├── frontend/                 # React UI (Vite + Vitest)
├── assets/                   # Source assets (manifests, optimizer binaries, optional IMG.LY bundle)
├── scripts/                  # Unified cross-platform Node.js scripts (fetch/build/package/clean)
├── build/                    # Generated outputs (ignored except a few Wails metadata files)
├── main.go                   # Wails application bootstrap
└── wails.json                # Wails config (frontend embed, app metadata)

Key Concepts (assets vs build outputs)

  • Repo assets/: source inputs for building (manifests + optional bundled assets).
  • build/bin/: build output folder (contains clara.exe / .app and staged runtime payload).
  • build/cache/ort/<platform-arch>/: download cache for ONNX Runtime libraries (not shipped directly).
  • Runtime payload: build/bin/assets/… (what the packaged app reads at runtime).

Quickstart (recommended)

Use the bootstrapper to get a fresh machine ready (downloads runtime deps and installs JS/Go deps):

node scripts/ensure-deps.mjs --accept-license --imgly-models

Notes:

  • --accept-license is required to download IMG.LY assets (AGPL). If you don’t want IMG.LY, add --skip-imgly.
  • On Windows, this script can also try to install packaging tools (NSIS/WiX) via winget (best-effort).

Development

Start dev mode:

wails dev

This runs the Go backend and proxies the Vite dev server.

Build (unified Node.js)

Build the app and stage runtime assets into the output folder:

node scripts/build.mjs --preset community
node scripts/build.mjs --preset personal

Presets

  • community: ships manifests and runtime libs, but does not bundle user model weights and does not bundle IMG.LY by default.
  • personal: bundles your user-installed model weights + user IMG.LY assets (if present).
  • none: minimal baseline; you explicitly enable bundling with --bundle-* flags.

Bundling knobs (all optional)

  • --bundle-config: use your current user config.json as assets/defaults.json (bundled defaults)
  • --bundle-defaults / --no-bundle-defaults: include/omit assets/defaults.json
  • --bundle-models / --no-bundle-models: include/omit user-installed ONNX weights
  • --models <comma-separated preset IDs>: restrict which user-installed weights to bundle
  • --bundle-imgly / --no-bundle-imgly: include/omit IMG.LY bundle
  • --imgly-source user|repo: bundle IMG.LY from user install or from repo assets/imgly
  • --bundle-optimizers / --no-bundle-optimizers: include/omit optimizer binaries (manifest is always included)
  • --bundle-ort / --no-bundle-ort: stage/remove ORT shared libraries beside the binary

Preview the effective plan without building:

node scripts/build.mjs --preset personal --bundle-config --dry-run

Package (portable archives + installers)

Packaging outputs are written to:

build/packages/<platform-arch>/

Examples:

# Portable only
node scripts/package.mjs --preset personal --outputs portable

# Portable + Windows installers (run on Windows + tools installed)
node scripts/package.mjs --preset personal --outputs portable,nsis,msi

Windows notes:

  • NSIS installer defaults to per-user install under %LOCALAPPDATA%\Programs\Clara (no admin).
  • Use --install-scope machine for a machine-wide install (Program Files, admin required).

Clean build artifacts

npm run clean:build

Optional:

  • node scripts/clean-build.mjs --packages (remove packaged artifacts)
  • node scripts/clean-build.mjs --assets (remove staged runtime payload under build/bin/assets)
  • node scripts/clean-build.mjs --caches (remove ORT caches under build/cache/ort)

User data locations (what the app installs/downloads at runtime)

Backend uses os.UserConfigDir()/clara/... (lowercase clara):

Platform Base dir (os.UserConfigDir()) Clara user dir
Windows %APPDATA% %APPDATA%\clara\
macOS ~/Library/Application Support ~/Library/Application Support/clara/
Linux $XDG_CONFIG_HOME or ~/.config ~/.config/clara/

Important subfolders:

  • config.json (settings)
  • models/ (installed ONNX weights)
  • imgly/ (installed IMG.LY bundle)

Internal architecture overview (high level)

  • Config: backend loads config in layers: hardcoded defaults → bundled assets/defaults.json → user config.json.
  • Models: assets/onnx-models/manifest.json defines available presets; weights are downloaded into the user directory after consent; personal builds can bundle them into build/bin/assets/onnx-models/.
  • IMG.LY: installed into the user dir and optionally bundled into build/bin/assets/imgly/.
  • ORT: downloaded into build/cache/ort/<platform-arch>/ and staged beside the binary (onnxruntime*.dll/.so/.dylib) for reliable dynamic loading.
  • Frontend: React UI calls backend via Wails bindings (frontend/wailsjs/...) for config, install/uninstall, and processing.

Testing

go test ./...
cd frontend
npm test

License

MIT License - Copyright (c) 2025 Leeroy Brun

About

Multi-platform on-device image background removal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors