# zarishsphere/zs-note architecture

> Architecture diagram of the GitHub repository zarishsphere/zs-note, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zarishsphere/zs-note
- Repository: https://github.com/zarishsphere/zs-note

## Overview

#### Purpose and Runtime Topology
ZarishNote is a local-first desktop Markdown note editor: a Svelte WebView frontend communicates with a Rust Tauri v2 host for privileged operations. A separate Python CLI converts external documents to Markdown. Main runtime entry points are `src/main.ts`, `src-tauri/src/main.rs`, `src-tauri/src/lib.rs`, and `ingestion/src/zarishnote_ingest/cli.py`.

#### Frontend Application and Editor
The Svelte 5 UI root assembles the workspace, panels, and modal-driven workflows in `src/lib/components/App.svelte`. Editor orchestration supports WYSIWYG, source, and split modes through `src/lib/components/Editor.svelte`, `src/lib/components/MilkdownEditor.svelte`, and `src/lib/components/SourceEditor.svelte`. Milkdown/ProseMirror setup is isolated in `src/lib/milkdown/setup.ts`; frontend stores own reactive editor, file, AI, config, MCP, plugin, and collaboration state under `src/lib/stores/`.

#### Tauri Command Boundary
Frontend actions cross the WebView/native boundary through typed invoke wrappers in `src/lib/commands/` and Rust Tauri handlers registered through `src-tauri/src/commands/mod.rs`. Command modules form the backend API for editor/file work, AI, import/ingestion, sandboxing, Git, MCP, search, publishing, voice, plugins, and configuration; representative paths are `src-tauri/src/commands/editor.rs`, `src-tauri/src/commands/ai.rs`, and `src-tauri/src/commands/ingest.rs`. Tauri capability permissions constrain exposed operations in `src-tauri/capabilities/default.json`.

#### Local Vault, Versioning, and Knowledge Flow
The editor and file tree operate on vault content through backend file CRUD, while Git services provide commits, history, and synchronization through `src-tauri/src/git/mod.rs`, `src-tauri/src/git/history.rs`, and `src-tauri/src/git/sync.rs`. Imported content flows from a frontend import action to the Rust ingestion command, launches the Python engine, then returns Markdown for vault/editor use. Local semantic retrieval indexes and queries content via `src-tauri/src/vector/index.rs` and `src-tauri/src/vector/query.rs`; the documented store is in-memory with fastembed.

#### AI, MCP, and Sandboxed Execution
AI chat is presented by `src/lib/components/AIPanel.svelte` and dispatched through the AI command layer to provider adapters: `src-tauri/src/ai/openai.rs`, `src-tauri/src/ai/claude.rs`, `src-tauri/src/ai/gemini.rs`, and local Ollama support. MCP integration separates protocol, transports, routing, and marketplace concerns in `src-tauri/src/mcp/protocol.rs`, `src-tauri/src/mcp/transport.rs`, and `src-tauri/src/mcp/router.rs`. AI tools, MCP servers, and plugins are intended to execute behind the Wasmtime boundary, whose executor, capability policy, network controls, state, and tool calls reside in `src-tauri/src/sandbox/executor.rs`, `src-tauri/src/sandbox/capability.rs`, and `src-tauri/src/sandbox/network.rs`.

#### Ingestion Pipeline
The Python package detects MIME/charset, chooses a converter, and normalizes supported inputs to Markdown. Its CLI and MarkItDown integration are in `ingestion/src/zarishnote_ingest/cli.py` and `ingestion/src/zarishnote_ingest/markitdown.py`; format-specific conversion implementations live under `ingestion/src/zarishnote_ingest/converters/`, including PDF, Office, HTML, notebooks, feeds, and web sources. This is a process boundary from Rust rather than an embedded library.

#### External Infrastructure and Delivery
Primary external services are configurable AI providers (OpenAI, Claude, Gemini, Ollama), MCP stdio/HTTP servers, Git/GitHub publishing, and optional Cloudflare real-time relay infrastructure at `cloudflare/realtime-worker/src/index.ts` and `cloudflare/realtime-worker/src/relay.ts`. Native desktop packaging is governed by `src-tauri/tauri.conf.json`; generated Android and Apple artifacts indicate mobile targets. GitHub Actions under `.github/workflows/` builds, tests, releases, deploys Cloudflare, and publishes Pages.

Main entry points: [`src-tauri/src/commands/mod.rs`](https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/commands/mod.rs) (Command API), [`src/lib/components/App.svelte`](https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/App.svelte) (Workspace UI), [`src/lib/components/Editor.svelte`](https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/Editor.svelte) (Editor modes), [`src-tauri/src/mcp/router.rs`](https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/mcp/router.rs) (MCP router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Svelte WebView"]
  node_ui["Workspace UI<br/>Svelte application<br/>[App.svelte]"]
  node_editor["Editor modes<br/>editor orchestration<br/>[Editor.svelte]"]
  node_milkdown["Milkdown editor<br/>ProseMirror editor"]
  node_source["Source editor"]
  node_stores[("Reactive stores<br/>frontend state<br/>[editor.svelte.ts]")]
  node_invoke["Typed invoke API<br/>command wrappers<br/>[editor.ts]"]
  node_ai_panel["AI panel<br/>chat UI<br/>[AIPanel.svelte]"]
end

subgraph group_native["Tauri host"]
  node_tauri["Tauri application<br/>Rust host runtime<br/>[lib.rs]"]
  node_commands["Command API<br/>Tauri handlers<br/>[mod.rs]"]
  node_vault[("Local vault<br/>Markdown files")]
  node_git["Git versioning<br/>history and sync<br/>[mod.rs]"]
  node_vector[("Semantic retrieval<br/>in-memory vector index<br/>[index.rs]")]
  node_ai["AI adapters<br/>provider integration<br/>[openai.rs]"]
  node_mcp["MCP router<br/>protocol routing<br/>[router.rs]"]
  node_sandbox{{"Wasmtime sandbox<br/>tool execution boundary<br/>[executor.rs]"}}
  node_ingest_command["Ingestion command<br/>process launcher<br/>[ingest.rs]"]
end

subgraph group_ingestion["Python ingestion process"]
  node_ingest_cli["Ingestion CLI<br/>Python entry point<br/>[cli.py]"]
  node_converters["Format converters<br/>MarkItDown conversions<br/>[markitdown.py]"]
end

subgraph group_external["External services"]
  node_providers(("AI providers<br/>configured LLM services"))
  node_mcp_servers(("MCP servers<br/>stdio and HTTP services"))
  node_github(("Git and GitHub<br/>remote sync and publishing"))
  node_relay["Realtime relay<br/>Cloudflare worker<br/>[relay.ts]"]
end

node_ui -->|"hosts"| node_editor
node_editor -->|"WYSIWYG mode"| node_milkdown
node_editor -->|"source mode"| node_source
node_ui -->|"reads and updates"| node_stores
node_ui -->|"native actions"| node_invoke
node_ai_panel -->|"AI requests"| node_invoke
node_invoke -->|"Tauri invoke"| node_commands
node_tauri -->|"registers"| node_commands
node_commands -->|"file CRUD"| node_vault
node_commands -->|"history and sync"| node_git
node_vault -->|"indexed for retrieval"| node_vector
node_commands -->|"search queries"| node_vector
node_commands -->|"AI dispatch"| node_ai
node_ai -->|"provider calls"| node_providers
node_commands -->|"MCP operations"| node_mcp
node_mcp -->|"stdio or HTTP"| node_mcp_servers
node_mcp -->|"tool execution"| node_sandbox
node_commands -->|"plugins and tools"| node_sandbox
node_commands -->|"import request"| node_ingest_command
node_ingest_command -.->|"spawns process"| node_ingest_cli
node_ingest_cli -->|"selects converter"| node_converters
node_ingest_command -->|"Markdown result"| node_vault
node_git -->|"sync and publish"| node_github
node_stores -.->|"optional collaboration"| node_relay

click node_ui "https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/App.svelte"
click node_editor "https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/Editor.svelte"
click node_milkdown "https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/MilkdownEditor.svelte"
click node_source "https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/SourceEditor.svelte"
click node_stores "https://github.com/zarishsphere/zs-note/blob/main/src/lib/stores/editor.svelte.ts"
click node_invoke "https://github.com/zarishsphere/zs-note/blob/main/src/lib/commands/editor.ts"
click node_ai_panel "https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/AIPanel.svelte"
click node_tauri "https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/lib.rs"
click node_commands "https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/commands/mod.rs"
click node_git "https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/git/mod.rs"
click node_vector "https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/vector/index.rs"
click node_ai "https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/ai/openai.rs"
click node_mcp "https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/mcp/router.rs"
click node_sandbox "https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/sandbox/executor.rs"
click node_ingest_command "https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/commands/ingest.rs"
click node_ingest_cli "https://github.com/zarishsphere/zs-note/blob/main/ingestion/src/zarishnote_ingest/cli.py"
click node_converters "https://github.com/zarishsphere/zs-note/blob/main/ingestion/src/zarishnote_ingest/markitdown.py"
click node_relay "https://github.com/zarishsphere/zs-note/blob/main/cloudflare/realtime-worker/src/relay.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui,node_editor,node_milkdown,node_source,node_stores,node_invoke,node_ai_panel toneBlue
class node_tauri,node_commands,node_vault,node_git,node_vector,node_ai,node_mcp,node_sandbox,node_ingest_command toneAmber
class node_ingest_cli,node_converters toneMint
class node_providers,node_mcp_servers,node_github,node_relay toneRose
```

## Components

### Svelte WebView

- [Workspace UI](https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/App.svelte): Svelte application · Assembles workspace, panels, and modal workflows. · `src/lib/components/App.svelte`
- [Editor modes](https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/Editor.svelte): editor orchestration · Coordinates WYSIWYG, source, and split editing. · `src/lib/components/Editor.svelte`
- [Milkdown editor](https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/MilkdownEditor.svelte): ProseMirror editor · `src/lib/components/MilkdownEditor.svelte`
- [Source editor](https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/SourceEditor.svelte): Markdown source editor · `src/lib/components/SourceEditor.svelte`
- [Reactive stores](https://github.com/zarishsphere/zs-note/blob/main/src/lib/stores/editor.svelte.ts): frontend state · Holds editor, file, AI, configuration, MCP, plugin, and collaboration state. · `src/lib/stores/editor.svelte.ts`
- [Typed invoke API](https://github.com/zarishsphere/zs-note/blob/main/src/lib/commands/editor.ts): command wrappers · `src/lib/commands/editor.ts`
- [AI panel](https://github.com/zarishsphere/zs-note/blob/main/src/lib/components/AIPanel.svelte): chat UI · `src/lib/components/AIPanel.svelte`

### Tauri host

- [Tauri application](https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/lib.rs): Rust host runtime · Registers the native application and command handlers. · `src-tauri/src/lib.rs`
- [Command API](https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/commands/mod.rs): Tauri handlers · Backend API for files, AI, ingestion, Git, MCP, search, plugins, and configuration. · `src-tauri/src/commands/mod.rs`
- **Local vault**: Markdown files · Local-first note content accessed through backend file CRUD.
- [Git versioning](https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/git/mod.rs): history and sync · `src-tauri/src/git/mod.rs`
- [Semantic retrieval](https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/vector/index.rs): in-memory vector index · Indexes and queries vault content with fastembed. · `src-tauri/src/vector/index.rs`
- [AI adapters](https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/ai/openai.rs): provider integration · Dispatches requests to OpenAI, Claude, Gemini, or Ollama. · `src-tauri/src/ai/openai.rs`
- [MCP router](https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/mcp/router.rs): protocol routing · Connects protocol and transport handling to MCP servers. · `src-tauri/src/mcp/router.rs`
- [Wasmtime sandbox](https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/sandbox/executor.rs): tool execution boundary · Applies capabilities and network controls to tools, MCP servers, and plugins. · `src-tauri/src/sandbox/executor.rs`
- [Ingestion command](https://github.com/zarishsphere/zs-note/blob/main/src-tauri/src/commands/ingest.rs): process launcher · Launches the external converter and returns Markdown. · `src-tauri/src/commands/ingest.rs`

### Python ingestion process

- [Ingestion CLI](https://github.com/zarishsphere/zs-note/blob/main/ingestion/src/zarishnote_ingest/cli.py): Python entry point · Detects inputs and selects a Markdown conversion path. · `ingestion/src/zarishnote_ingest/cli.py`
- [Format converters](https://github.com/zarishsphere/zs-note/blob/main/ingestion/src/zarishnote_ingest/markitdown.py): MarkItDown conversions · Converts PDF, Office, HTML, notebooks, feeds, and web sources. · `ingestion/src/zarishnote_ingest/markitdown.py`

### External services

- **AI providers**: configured LLM services · OpenAI, Claude, Gemini, and Ollama.
- **MCP servers**: stdio and HTTP services
- **Git and GitHub**: remote sync and publishing
- [Realtime relay](https://github.com/zarishsphere/zs-note/blob/main/cloudflare/realtime-worker/src/relay.ts): Cloudflare worker · Optional collaboration relay infrastructure. · `cloudflare/realtime-worker/src/relay.ts`

## Connections

- Workspace UI → Editor modes: hosts
- Editor modes → Milkdown editor: WYSIWYG mode
- Editor modes → Source editor: source mode
- Workspace UI → Reactive stores: reads and updates
- Workspace UI → Typed invoke API: native actions
- AI panel → Typed invoke API: AI requests
- Typed invoke API → Command API: Tauri invoke
- Tauri application → Command API: registers
- Command API → Local vault: file CRUD
- Command API → Git versioning: history and sync
- Local vault → Semantic retrieval: indexed for retrieval
- Command API → Semantic retrieval: search queries
- Command API → AI adapters: AI dispatch
- AI adapters → AI providers: provider calls
- Command API → MCP router: MCP operations
- MCP router → MCP servers: stdio or HTTP
- MCP router → Wasmtime sandbox: tool execution
- Command API → Wasmtime sandbox: plugins and tools
- Command API → Ingestion command: import request
- Ingestion command → Ingestion CLI: spawns process · Python runs outside the Rust host process.
- Ingestion CLI → Format converters: selects converter
- Ingestion command → Local vault: Markdown result
- Git versioning → Git and GitHub: sync and publish
- Reactive stores → Realtime relay: optional collaboration
