Aleksey Shakhmatov c35960761b feat(git): sync with a remote — fetch, pull and push
Add remote sync to the Git panel: set/edit an origin URL, then fetch, pull
(fast-forward) and push, with live ahead/behind counts against the
remote-tracking branch.

Backend:
- git_ops: remote_status (git2 ahead/behind + upstream), set_remote, and
  fetch/pull/push that shell out to the system git CLI so they reuse the
  user's existing credentials (SSH agent, keychain / credential helpers)
  instead of reimplementing libgit2 credential callbacks. Pull is --ff-only
  to avoid leaving a conflicted tree from the GUI; push uses --set-upstream.
- New commands git_remote_status/set_remote/fetch/pull/push, registered.
- Test: push to a bare local remote, then assert upstream + ahead/behind.

Frontend:
- RemoteStatus type, api wrappers, store state (remote, syncing) with
  refreshRemote wired into refreshGit; pull reloads diagrams + open buffer.
- GitPanel remote section: URL, ahead/behind badges, Fetch/Pull/Push, and a
  set-remote dialog.

cargo test (7 passing incl. roundtrip), svelte-check and build all green.
2026-05-22 21:32:48 +03:00

Mermix

A cross-platform Mermaid diagram editor & viewer with Git-backed projects. Organize many diagrams into projects, edit them with a live preview, export to SVG/PNG, and version everything with real Git branches and commits — all in a native desktop app.

Built with Rust + Tauri 2, SQLite (sqlx), git2, and a Svelte 5 + TypeScript frontend using CodeMirror 6 and Mermaid 11.


Features

  • Projects — each project is a folder on disk that is a real Git repository with a mermix.toml config and a diagrams/ directory of .mmd files.
  • Many diagrams per project with a sidebar explorer; create, rename, delete.
  • Live editor + preview — CodeMirror source on the left, debounced Mermaid render on the right, with zoom/pan and inline syntax-error reporting.
  • Git version control built in — view the working-tree status, write commit messages, browse history, create branches and switch between them. Each branch keeps its own set of diagrams, just like normal Git.
  • Remote sync — point a project at a remote (origin), then fetch, pull (fast-forward) and push from the Git panel, with live ahead/behind counts. Network operations shell out to your system git, so they reuse your existing credentials (SSH agent, keychain / credential helpers) — no separate login.
  • Optimize panel (Diagram Doctor) — analyse a tangled flowchart and declutter it in one click: a readability score and metrics (hubs, density, cross-group edges), plus source rewrites for the ELK layered layout, extra spacing/curved edges, de-emphasising cross-cutting hub edges (event bus, audit, cost-style fan-ins), and removing duplicate edges. A non-destructive focus mode spotlights any node and its neighbours so you can read a dense graph without changing it. Every rewrite lands in the editor and is reversible with ⌘Z.
  • Export the current diagram to SVG or PNG (2× scale), or copy a PNG straight to the clipboard. (PNG/clipboard re-render flowcharts with text labels so the bitmap rasterizes cleanly across platforms.)
  • Project registry — recently opened projects are remembered in a local SQLite database so you can jump back in from the start screen.
  • Themes — switch the Mermaid theme (default / neutral / dark / forest / base) per project.

Architecture

Mermix/
├─ src/                     # Svelte 5 + TS frontend
│  ├─ App.svelte            # layout, resizable editor/preview split
│  ├─ lib/
│  │  ├─ api.ts             # typed wrappers over Tauri commands
│  │  ├─ store.svelte.ts    # central rune-based app state
│  │  ├─ mermaid.ts         # render + error capture (registers ELK layout)
│  │  ├─ optimize.ts        # flowchart analysis + declutter transforms (pure)
│  │  ├─ export.ts          # SVG / PNG export via save dialog
│  │  └─ components/        # Sidebar, Editor, Preview, GitPanel, OptimizePanel, …
│  └─ main.ts
└─ src-tauri/               # Rust backend
   ├─ src/
   │  ├─ lib.rs             # Tauri builder, state, command registry
   │  ├─ commands.rs        # the IPC surface
   │  ├─ db.rs              # sqlx/SQLite project registry + settings
   │  ├─ project.rs         # mermix.toml, create/open, slugify
   │  ├─ diagram.rs         # .mmd CRUD, frontmatter titles
   │  ├─ git_ops.rs         # git2: commit, history, branches, status
   │  ├─ error.rs / state.rs
   │  └─ tests.rs           # headless core-logic tests
   └─ tauri.conf.json

Data model. Mermix keeps one small app-level SQLite database (in the OS app data directory) that only tracks the registry of known projects and user settings. All real content lives on disk inside each project's Git repository — so projects are portable, inspectable, and work with any other Git tooling.

A project on disk looks like:

my-diagrams/
├─ mermix.toml          # project id, name, description, default theme
├─ README.md
├─ .gitignore
├─ .git/                # full Git history
└─ diagrams/
   ├─ welcome.mmd
   └─ login-flow.mmd    # Mermaid source, optional YAML frontmatter title

Prerequisites

  • Rust (stable) and Cargo
  • Node.js 18+ and npm
  • Platform webview deps:
    • macOS — nothing extra (system WebKit)
    • Windows — WebView2 (preinstalled on Windows 11)
    • Linuxwebkit2gtk and related packages (see Tauri docs)

Getting started

npm install          # install frontend deps + Tauri CLI

npm run app:dev      # run the desktop app in dev mode (hot reload)
npm run app:build    # build a production bundle for your platform

Other useful scripts:

npm run dev          # frontend only (Vite) on http://localhost:1420
npm run build        # type-check + build the frontend bundle
npm run check        # svelte-check type checking

Backend logic is covered by headless tests:

cd src-tauri && cargo test

Keyboard shortcuts

Shortcut Action
⌘/Ctrl + S Save current diagram
⌘/Ctrl + Enter Commit (in commit box)
⌘/Ctrl + scroll Zoom the preview

How Git is used

  • Creating a project runs git init (default branch main) and makes an initial commit.
  • Commit stages every change (adds, edits, deletes) and records it with the message you type; the author defaults to your global Git identity, falling back to Mermix <mermix@localhost> if none is configured.
  • Branches are listed in the Git panel; create one and Mermix checks it out for you. Switching branches reloads the diagram list from that branch.
  • History shows the most recent commits with short SHA, message, author and relative time.
  • Remote sync sets/uses an origin remote. Fetch updates remote-tracking refs; pull is fast-forward only (it never leaves a half-merged tree from the GUI — reconcile divergent history yourself); push uses --set-upstream. These invoke the system git binary, which must be installed and on PATH.

License

MIT

Description
No description provided
Readme 528 KiB
Languages
TypeScript 37.6%
Svelte 35.7%
Rust 25%
CSS 1.4%
HTML 0.2%