Skip to content

syntax-syndicate/zubridge

 
 

Repository files navigation

zubridge hero image

Zubridge

Cross-platform state without boundaries: Zustand-inspired simplicity



Why

tldr: I want to seamlessly interact with my backend state using Zustand-inspired hooks.

Zustand is a great state management library that, like Redux, recommends using a single store for your application. However, in cross-platform apps, this approach faces challenges when state needs to be accessed across process boundaries.

Zubridge solves this by enabling a single store workflow, abstracting away the IPC management and state synchronization between processes.

Features

  • Zustand-like API for state management across your entire cross-platform app
  • Frontend flexibility - works with React, other frontend frameworks, or vanilla JavaScript
  • Framework-agnostic backend contract that works with any state provider implementation
  • Type-safe state management between processes
  • Automatic state synchronization across multiple windows

Electron-specific features

  • Works with the latest security model in Electron
  • Supports Zustand and Redux
  • Supports various usage patterns when using Zustand for your main process store (store handlers, separate handlers, Redux-style reducers)
  • Supports dispatching thunks, action objects and string actions in both processes

Tauri-specific features

  • Compatible with both Tauri v1 and v2 APIs via dependency injection
  • Connect frontend components to Rust backend state using Zustand-like hooks
  • Clear separation between frontend state access and backend state logic

How It Works

Zubridge creates a bridge between your backend store and frontend processes. The backend (main process) store acts as the single source of truth, while frontend (renderer) processes receive synchronized copies of the state.

Actions from the frontend are sent through IPC to the backend, which updates the central store. These updates are then automatically broadcast to all connected frontend processes, ensuring consistent state throughout your application.

Getting Started

Zubridge is available for both Electron and Tauri apps:

Framework Support

Zubridge is available for multiple cross-platform application frameworks:

Electron

Install @zubridge/electron for Electron applications.

Uses Electron's built-in IPC system with minimal configuration required.

Tauri

Install @zubridge/tauri for Tauri applications (supports Tauri v1 and v2).

Uses Tauri's event system and commands, respecting its security model where main process actions must be explicitly allowed.

Inspiration / Prior Art

  • goosewobbler/zutron (Electron + Zustand)

    • Zustand store in the main process, synced to Zustand in the renderer
    • @zubridge/electron started as a rebrand of Zutron and evolved from there
  • vitordino/reduxtron (Electron + Redux + Zustand)

    • Redux store in the main process, optionally synced to Zustand in the renderer
    • Reduxtron is the original inspiration for Zutron (and hence @zubridge/electron)
  • klarna/electron-redux (Electron + Redux)

    • Bi-directional sync between one Redux store in the main process, and another in the renderer
    • No longer maintained. It was forked to enable support for Electron 14's security model improvements, but the architectural approach had serious limitations.

About

Streamlined state management for cross-platform apps

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 88.6%
  • Rust 7.9%
  • JavaScript 2.4%
  • Other 1.1%