$ show chen08209/FlClash
FlClash is a production multi-platform proxy/VPN client that embeds and manages the mihomo (Clash.Meta) Go core. The Dart/Flutter app (Riverpod, Drift, freezed) drives a real core lifecycle: profile/subscription import and validation, proxy group and rule management, TUN/VPN on Android, system proxy on desktop, live connections/requests/DNS views, latency probing, streaming-service availability checks, and WebDAV backup/restore. The Go core exposes a method-dispatch IPC contract (updateConfig, changeProxy, getConnections, watchRoute, probe, serviceCheck, etc.) consumed through an Android cgo bridge and a desktop helper process. This is a full application, not a library or data project — no notebooks, no research pipelines. The architecture is layered: Flutter UI → manager/provider layers → core controller → framed JSON IPC → Go mihomo core. Desktop builds add a Rust privileged helper service (systemd unit / Windows SCM, Unix socket with peer-credential auth) and Rust plugins for global hotkeys, QuickJS evaluation of script-based profile overrides, and a rope-backed code editor (code_forge). Native integration plugins for system tray, window management, system proxy, and WiFi SSID are shipped as separate Dart packages with per-OS implementations in C++/Swift/Kotlin. A custom build-hook system compiles and SHA-256-fingerprints the Go core and Rust helper artifacts with file-locking to make native builds cacheable and idempotent. The codebase is unusually disciplined. Test/ subdirectories include contract tests that parse Go structs from the mihomo submodule to verify DNS-override parity, AST-parsing tests verifying every core method is dispatchable, architectural lint tests (platform layering, dead-file detection, UI tooltip enforcement, Material-icon bans), plus unit and widget tests across every layer. Concurrency is handled deliberately: priority message batching between core and UI, serial task scheduling, claim/cancel semantics for GEO/probe updates, and an Android service state machine with newest-request-wins arbitration. Release tooling generates changelogs from conventional commits and a CI pipeline produces deb/rpm/AppImage/DMG/Inno packages. Caveats: the polyglot stack (Dart, Go, Rust, Kotlin, C++, Swift) and tight coupling to mihomo internals via a git submodule make wholesale extraction impractical, and large amounts of generated code (freezed, riverpod_generator, Drift, flutter_rust_bridge) require coordinated regeneration. Browser-platform and TV branches add conditional complexity, and some UI tests assert precise pixel/animation timings that are brittle. The genuinely reusable value lives in the standalone patterns — IPC framing and batching, the rope data structure, fractional indexing, async utilities, and the fingerprinted build cache — plus the independent plugin packages themselves.
The LLM identified 6 files worth highlighting for reuse:
Length-prefixed frame-based IPC server with nonblocking partial reads, a byte-budgeted send queue with timeout, Windows pipe backoff handling, and Unix peer-credential authorization on accept. Self-contained and directly portable to any Rust process that needs a safe, bounded, authenticated inter-process channel.
Priority-aware message batcher for pub/sub notifications: state, priority, and bulk message classes with non-blocking enqueue, eviction of stale messages, and batch flushing by size and interval. Solves the classic 'don't flood the UI with high-frequency core updates' problem and is extractable as a standalone batching primitive.
Debouncer, Throttler, and SerialTaskScheduler primitives for async Dart code. Each is self-contained, testable, and directly portable to any Flutter/Dart project needing rate-limited or serialized asynchronous work; no coupling to the FlClash app layer.
Content-fingerprint build cache for native toolchains: SHA-256 over sorted inputs, serialized concurrent check/rebuild with file locks, verification that outputs exist and are fresh, and deliberate avoidance of keying on dynamic directory content. A reusable pattern for any project with expensive native compilation steps that must be skipped when unchanged.
Rope data structure for efficient text editing at arbitrary offsets (logarithmic insert/delete), used as the backing store of a custom code editor with an undo/redo layer. The data structure itself is standalone and portable to any text-heavy Dart application.
Fractional indexing for generating order keys between arbitrary strings without renumbering — the pattern used by collaborative editors and reorderable lists. Solves a recurring UX problem (stable drag-reorder persistence) with a compact, dependency-free implementation that can be lifted into any project.