# Data flow — clash-verge-rev/clash-verge-rev

> Canonical page: https://codevetter.com/unpack/clash-verge-rev/data-flow

# Data flow — clash-verge-rev/clash-verge-rev

Scanned commit fd06fbb3b71ee5c4467bc0e3cc505dcac5348371 (2026-09-22). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

User input enters through Tauri invoke, the Mihomo plugin's local socket, deep links, or the localhost warp server. Rust turns profiles and verge/clash settings into one runtime YAML via enhance::enhance, validates it by executing the Mihomo sidecar with -t, then applies it to the running core. Live proxy and traffic data flow the other way: the UI polls get_proxy_view and Mihomo HTTP, and the backend pushes verge:// events. Durable files are YAML under the app home. WebDAV credentials are encrypted only while the task-local encryption flag is on.
- src/services/cmds.ts is the typed invoke() boundary. Examples: get_profiles, import_profile, get_proxy_view (rejects schemaVersion other than 1), patch_verge_config, and save_profile_file, which treats ValidationOutcome.status === 'valid' as success. — [src/services/cmds.ts#L13-L58](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src/services/cmds.ts#L13-L58) [src/services/cmds.ts#L136-L142](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src/services/cmds.ts#L136-L142)
- Live Mihomo data does not all go through cmds.ts. AppDataProvider uses tauri-plugin-mihomo-api getBaseConfig, getRules, and getRuleProviders, and polls getProxyView every 15 seconds via an SWR wrapper in src/services/query-client.ts. — [src/providers/app-data-provider.tsx#L1-L30](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src/providers/app-data-provider.tsx#L1-L30) [src/providers/app-data-provider.tsx#L56-L77](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src/providers/app-data-provider.tsx#L56-L77) [src/services/query-client.ts#L1-L40](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src/services/query-client.ts#L1-L40)
- Backend events subscribed in src/services/events.ts include verge://refresh-clash-config, verge://refresh-verge-config, verge://refresh-profiles, verge://notice-message, verge://run-state-changed, profile-changed, and profile-update-started/completed. — [src/services/events.ts#L6-L20](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src/services/events.ts#L6-L20)
- In-memory config is Draft<T> from clash-verge-draft: data_arc is the committed snapshot, latest_arc prefers the uncommitted draft, edit_draft clones only when the Arc is shared, and apply commits the draft. — [crates/clash-verge-draft/src/lib.rs#L31-L79](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/crates/clash-verge-draft/src/lib.rs#L31-L79)
- Config::generate_with_profiles calls enhance::enhance, resolves provider path conflicts, sanitizes tunnels, optionally injects MixedPort::session_fallback, and stores the mapping on the runtime draft as IRuntime { config, dns_override, exists_keys, chain_logs }. generate_file writes that YAML to app_home/clash-verge.yaml with a generated-by header. — [src-tauri/src/config/config.rs#L196-L248](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/config/config.rs#L196-L248)
- enhance() order is: collect current profile items; process seq rules/proxies/groups; merge GUI clash defaults and port toggles; apply builtin scripts; use_tun; merge dns_config.yaml when DNS settings are enabled; run global merge then global script; run profile merge then profile script; enforce authoritative fields; cleanup proxy groups and sort keys. — [src-tauri/src/enhance/mod.rs#L872-L969](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/enhance/mod.rs#L872-L969)
- Script enhancers run in Boa. The stock tmpl::ITEM_SCRIPT skips the engine. Other scripts get a 5 second timeout, a 10_000_000 loop-iteration cap, a 10MB JSON input cap, and a console that only calls __verge_log__. Exceptions return the input config unchanged plus an exception log. — [src-tauri/src/enhance/script.rs#L12-L66](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/enhance/script.rs#L12-L66) [src-tauri/src/enhance/script.rs#L123-L132](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/enhance/script.rs#L123-L132)
- Builtin script src-tauri/src/enhance/builtin/meta_guard.js rewrites config.mode from script to rule. It is applied from the Rust enhancer, not from the webview. — [src-tauri/src/enhance/builtin/meta_guard.js#L1-L7](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/enhance/builtin/meta_guard.js#L1-L7) [src-tauri/src/enhance/mod.rs#L930](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/enhance/mod.rs#L930)
- verge.yaml WebDAV url, username, and password use serialize_encrypted / deserialize_encrypted. AES-256-GCM runs only when ENCRYPTION_ACTIVE is set by with_encryption. help.rs reads and writes YAML inside that scope. The 32-byte key is created with getrandom and stored at app_home/.encryption_key. — [src-tauri/src/config/verge.rs#L168-L190](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/config/verge.rs#L168-L190) [src-tauri/src/config/encrypt.rs#L18-L92](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/config/encrypt.rs#L18-L92) [src-tauri/src/utils/dirs.rs#L155-L170](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/utils/dirs.rs#L155-L170) [src-tauri/src/utils/help.rs#L1-L23](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/utils/help.rs#L1-L23)
- Core config validation shells out to the selected sidecar: app_handle.shell().sidecar(clash_core) with args -t -d <app dir> -f <config path>, timeout 5 seconds. ValidationOutcome is Valid, Invalid, Skipped (exiting or debounced), or Busy. — [src-tauri/src/core/validate.rs#L20-L21](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/core/validate.rs#L20-L21) [src-tauri/src/core/validate.rs#L113-L136](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/core/validate.rs#L113-L136) [src-tauri/src/core/validate.rs#L361-L364](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/core/validate.rs#L361-L364)
- A node click calls Mihomo selectNodeForGroup or unfixedProxy, then sync_tray_proxy_selection, then record_selected_node or forget_selected_node. If auto_close_connection is set, connections whose chain includes the previous proxy are closed. — [src/hooks/use-proxy-selection.ts#L66-L96](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src/hooks/use-proxy-selection.ts#L66-L96) [src-tauri/src/cmd/proxy.rs#L19-L32](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/cmd/proxy.rs#L19-L32)
- The embedded warp server binds 127.0.0.1. /commands/visible and /commands/scheme require header x-instance-token. /commands/pac does not: it substitutes %mixed-port% into pac_file_content or DEFAULT_PAC and is fail-closed until PAC_AVAILABLE is set. — [src-tauri/src/utils/server.rs#L51-L94](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/utils/server.rs#L51-L94) [src-tauri/src/utils/server.rs#L198-L266](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/utils/server.rs#L198-L266) [src-tauri/src/config/mod.rs#L17-L20](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/config/mod.rs#L17-L20)
- Deep-link import parses clash or clash-verge URLs, takes the raw url= query (percent-decoded at most twice), builds a PrfItem with PrfItem::from_url, appends and saves profiles, refreshes Timer, and calls CoreManager::update_config_forced only when that import becomes the first current profile. — [src-tauri/src/utils/resolve/scheme.rs#L13-L158](https://github.com/clash-verge-rev/clash-verge-rev/blob/fd06fbb3b71ee5c4467bc0e3cc505dcac5348371/src-tauri/src/utils/resolve/scheme.rs#L13-L158)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
