This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: tauri2-zero-copy-ipc-arraybuffer-boundary

Tauri 2.0 Zero-Copy Native IPC ArrayBuffer Memory-Mapping Boundary

Enforces serialization-free, memory-mapped binary transfers between mobile WebViews and native Rust engines in Tauri 2.0. Eliminates main-thread JSON serialization and base64 overhead that cause dropped frames and UI stalls during high-throughput sensor, camera, and audio streaming. Mandates the use of raw byte buffers via Tauri 2.0 Channel/Response abstractions rather than structured JSON bridging.

Prohibited Anti-Pattern: Base64 or Number-Array Serialized IPC Streaming Over Webview Bridge

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Zero-Copy Native IPC ArrayBuffer Memory-Mapping Boundary - Enforces serialization-free, memory-mapped binary transfers between mobile WebViews and native Rust engines in Tauri 2.0. Eliminates main-thread JSON serialization and base64 overhead that cause dropped frames and UI stalls during high-throughput sensor, camera, and audio streaming. Mandates the use of raw byte buffers via Tauri 2.0 Channel/Response abstractions rather than structured JSON bridging.
globs: src/**/*.{ts,tsx}, src-tauri/src/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri2-zero-copy-ipc-arraybuffer-boundary"
---

# Tauri 2.0 Zero-Copy Native IPC ArrayBuffer Memory-Mapping Boundary

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Base64 or Number-Array Serialized IPC Streaming Over Webview Bridge

## System Constraints
You are a Principal Software Architect enforcing zero-copy binary IPC standards for Tauri 2.0 mobile applications. You must strictly forbid JSON and base64 encoding of continuous byte data, large sensor buffers, and media streams across the Rust-WebView boundary. Mandate native raw ArrayBuffer transfers, tauri::ipc::Response binary payloads, and tauri::ipc::Channel streaming buffers to preserve mobile UI frame budgets at 60/120 FPS.

## Strict Guidelines
- Engineers MUST ALWAYS transfer binary data larger than 1 KiB across the Tauri boundary using raw binary `tauri::ipc::Response` or binary `tauri::ipc::Channel` instances.
- Engineers MUST NOT convert binary buffers to base64 strings or `Vec<u8>`/`number[]` arrays for transport across IPC invokes.
- Frontend callers MUST invoke binary endpoints using raw buffer configurations or dedicated streaming channels that decode directly into `Uint8Array` or `ArrayBuffer` without JSON deserialization.
- Rust commands handling continuous stream ingestion MUST yield thread control using non-blocking channels and write directly into pre-allocated memory slices.
- Webview consumers MUST NEVER process raw binary buffers on the main execution thread; incoming `ArrayBuffer` instances exceeding 64 KiB must be transferred to a Dedicated Web Worker via `postMessage([buffer], [buffer])`.
- Rust backend services MUST leverage `tauri::ipc::Response::new(bytes)` with appropriate mime-types for zero-copy streaming, avoiding `serde` serialization macros on raw byte payloads.

## Bad vs Good Implementations
### Streaming Frame Ingestion Across Tauri 2.0 IPC Boundary

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transporting raw byte buffers as `number[]` or base64 over Tauri's default JSON IPC bridge triggers massive GC pressure and CPU saturation. Each byte expands into multiple JSON tokens, blocking the mobile WebView main thread and causing severe UI stutter.
```typescript
import { invoke } from '@tauri-apps/api/core';

// ANTI-PATTERN: Serializing 4MB frame buffer as JSON number[] or base64
// Destroys mobile V8/JSC heap and blocks UI thread during serde parsing
export async function fetchCameraFrame(frameId: number): Promise<Uint8Array> {
  const response = await invoke<{ frameData: number[] }>('get_camera_frame', {
    frameId,
  });
  return new Uint8Array(response.frameData);
}
```

#### Production Standard (Correct)
> **Standard**: Leveraging Tauri 2.0's typed Channel IPC delivers the payload directly as a raw JavaScript TypedArray/ArrayBuffer. This bypasses the serde_json parser entirely, executing zero-copy memory transfers between the mobile native runtime and the WebView.
```typescript
import { Channel, invoke } from '@tauri-apps/api/core';

// PRODUCTION INVARIANT: Streamed via Tauri 2.0 Channel as raw Uint8Array ArrayBuffer
export function setupFrameStream(
  onFrame: (buffer: Uint8Array) => void
): () => void {
  const onData = new Channel<Uint8Array>();
  
  onData.onmessage = (chunk: Uint8Array) => {
    // Direct zero-copy view over transferred ArrayBuffer
    onFrame(chunk);
  };

  void invoke('start_camera_stream', { onData });

  return () => {
    void invoke('stop_camera_stream');
  };
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Tauri 2.0 Zero-Copy Native IPC ArrayBuffer Memory-Mapping Boundary

Tauri 2.0 Zero-Copy Native IPC ArrayBuffer Memory-Mapping Boundary defines an industrial-grade behavioral standard for mobile engineering. Enforces serialization-free, memory-mapped binary transfers between mobile WebViews and native Rust engines in Tauri 2.0. Eliminates main-thread JSON serialization and base64 overhead that cause dropped frames and UI stalls during high-throughput sensor, camera, and audio streaming. Mandates the use of raw byte buffers via Tauri 2.0 Channel/Response abstractions rather than structured JSON bridging. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Base64 or Number-Array Serialized IPC Streaming Over Webview Bridge Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftBase64 or Number-Array Serialized IPC Streaming Over Webview BridgeCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS transfer binary data larger than 1 KiB across the Tauri boundary using raw binary `tauri

Engineers MUST ALWAYS transfer binary data larger than 1 KiB across the Tauri boundary using raw binary `tauri::ipc::Response` or binary `tauri::ipc::Channel` instances.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT convert binary buffers to base64 strings or `Vec<u8>`/`number[]` arrays for transport across IPC invokes.

Engineers MUST NOT convert binary buffers to base64 strings or `Vec<u8>`/`number[]` arrays for transport across IPC invokes.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Frontend callers MUST invoke binary endpoints using raw buffer configurations or dedicated streaming channels that decode directly into `Uint8Array` or `ArrayBuffer` without JSON deserialization.

Frontend callers MUST invoke binary endpoints using raw buffer configurations or dedicated streaming channels that decode directly into `Uint8Array` or `ArrayBuffer` without JSON deserialization.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Rust commands handling continuous stream ingestion MUST yield thread control using non-blocking channels and write directly into pre-allocated memory slices.

Rust commands handling continuous stream ingestion MUST yield thread control using non-blocking channels and write directly into pre-allocated memory slices.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Webview consumers MUST NEVER process raw binary buffers on the main execution thread

Webview consumers MUST NEVER process raw binary buffers on the main execution thread; incoming `ArrayBuffer` instances exceeding 64 KiB must be transferred to a Dedicated Web Worker via `postMessage([buffer], [buffer])`.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Rust backend services MUST leverage `tauri

Rust backend services MUST leverage `tauri::ipc::Response::new(bytes)` with appropriate mime-types for zero-copy streaming, avoiding `serde` serialization macros on raw byte payloads.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Tauri 2.0 Zero-Copy Native IPC ArrayBuffer Memory-Mapping Boundary critical for AI coding assistants?

Enforces serialization-free, memory-mapped binary transfers between mobile WebViews and native Rust engines in Tauri 2.0. Eliminates main-thread JSON serialization and base64 overhead that cause dropped frames and UI stalls during high-throughput sensor, camera, and audio streaming. Mandates the use of raw byte buffers via Tauri 2.0 Channel/Response abstractions rather than structured JSON bridging. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Base64 or Number-Array Serialized IPC Streaming Over Webview Bridge) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Tauri