ADR-005: WebAssembly Integration for Browser and Mobile Deployment
Date: 2026-02-01
Status: Accepted
Context
QNTX has multiple Rust components (parser, fuzzy matching, storage, video inference) integrated into a Go server via CGO. The parser (qntx-core) is a critical component that tokenizes and parses AX query strings.
The vision for QNTX includes:
Running entirely in the browser as an offline-first application
Running on resource-constrained devices ("mobile potato")
Tauri-based desktop application (web/src-tauri) that wraps the web interface
Unified codebase across server, browser, and desktop
Currently, the Tauri app and web interface don't share the core parsing logic with the server, leading to potential inconsistencies.
Decision
We will integrate the qntx-core parser as a WebAssembly module, making it the first component in our gradual migration from CGO to WASM. This enables the same parser to run in:
Go server (via wazero)
Web browser (via web/ts)
Tauri desktop app (via embedded webview)
Mobile browsers (lightweight WASM)
Implementation Details
WASM Runtime:
Server: wazero (pure Go WebAssembly runtime)
Browser/Tauri: Native WebAssembly API
Distribution: Triple strategy:
Embed WASM modules in Go binary via go:embed for server deployment
Distribute same WASM modules for web/ts frontend for offline browser execution
Bundle WASM with Tauri app for desktop deployment
Build Configuration: Always enable WASM parser by default (remove opt-in build tag requirement)
Failure Handling: Log and fall back to Go implementation if WASM fails (server only)
Migration Strategy
Gradually migrate all Rust components to WASM:
✅ Parser (qntx-core) - COMPLETED (89KB)
⏳ Fuzzy matching (fuzzy-ax)
⏳ Storage (qntx-sqlite) - IndexedDB for browser, SQLite for Tauri
⏳ Video inference (vidstream) - May remain server-only due to size
Consequences
Positive
Unified Logic: Server, browser, and Tauri use identical parsing implementation
Offline-First: Full QNTX functionality without server connection
Mobile Ready: Lightweight WASM (89KB) suitable for mobile browsers
Tauri Benefits: Desktop app gets same parser without bundling Go server
Portability: No CGO dependency for parser, simplifying builds
Progressive Web App: Path to PWA with offline capabilities
Negative
Performance: WASM has overhead vs native (accepted as non-critical)
Complexity: Additional abstraction layer between Rust and Go
Size: Each platform carries WASM modules
Debugging: More complex stack traces crossing WASM boundary
Browser Limitations: Storage and video modules may not fully port to WASM
Neutral
Runtime Choice: wazero is the only pure-Go runtime (no CGO) — wasmtime/wasmer are faster but re-introduce the CGO dependency this migration eliminates
Fallback Path: Go implementation maintained during transition
Tauri Architecture: Tauri app can use either WASM or native Rust (flexibility)