This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: capacitor-7-zero-serialization-binary-bridge-standard

Capacitor 7 Zero-Serialization Binary Bridge Standard

Mandates the usage of raw ArrayBuffer instances and TypedArray views over native-to-web bridges for high-frequency sensor and biometric telemetry. Eliminates IPC serialization overhead, garbage collection thrashing, and UI thread frame drops by prohibiting Base64 encoding and JSON stringification in streaming pipelines.

Prohibited Anti-Pattern: Serializing High-Frequency Telemetry to Base64 or JSON Objects Across the Native-Web Bridge

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Capacitor 7 Zero-Serialization Binary Bridge Standard - Mandates the usage of raw ArrayBuffer instances and TypedArray views over native-to-web bridges for high-frequency sensor and biometric telemetry. Eliminates IPC serialization overhead, garbage collection thrashing, and UI thread frame drops by prohibiting Base64 encoding and JSON stringification in streaming pipelines.
globs: src/**/*.{ts,tsx}, android/**/*.kt, ios/**/*.swift
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/capacitor-7-zero-serialization-binary-bridge-standard"
---

# Capacitor 7 Zero-Serialization Binary Bridge Standard

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Serializing High-Frequency Telemetry to Base64 or JSON Objects Across the Native-Web Bridge

## System Constraints
You are a Principal Mobile Architect enforcing the Capacitor 7 Zero-Serialization Binary Bridge Standard. You must reject any code that converts binary or high-frequency telemetry into Base64 strings or arbitrary JSON payloads across the native bridge. Mandate pre-allocated ArrayBuffers, zero-copy TypedArray views, and native memory streaming to maintain 60-120 FPS UI thread budgets.

## Strict Guidelines
- Engineers MUST ALWAYS transmit high-frequency telemetry (>30Hz) as raw ArrayBuffers or direct TypedArray views supported by Capacitor 7 native binary channels.
- Engineers MUST NOT convert native byte buffers, IMU data, or biometric signals into Base64 strings, numeric arrays, or JSON dictionaries across IPC.
- Code SHOULD reuse pre-allocated TypedArray instances (e.g., Float32Array, Uint8Array) to prevent heap fragmentation and Garbage Collector (GC) stalls in the WebView.
- Services MUST process binary telemetry windows using zero-copy view slicing (TypedArray.prototype.subarray) rather than ArrayBuffer.prototype.slice.
- Components NEVER execute JSON.parse or string decoding within high-frequency native telemetry event callbacks.

## Bad vs Good Implementations
### High-Frequency Biometric Sensor Ingestion Pipeline

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transporting sensor data via Base64 encoded strings in JSON payloads forces native serialization, bridge string transfer, JS thread string allocation, atob decoding, and dynamic memory allocations on every frame, introducing GC spikes and severe UI thread jank.
```typescript
import { Plugins } from '@capacitor/core';
const { BiometricTelemetry } = Plugins;

// ANTI-PATTERN: Serializing binary telemetry into JSON/Base64 strings
BiometricTelemetry.addListener('onSample', (payload: { sampleRate: number; base64Data: string }) => {
  // Heavy Base64 decoding string conversion causes severe UI thread jank
  const binaryString = atob(payload.base64Data);
  const bytes = new Uint8Array(binaryString.length);
  for (let i = 0; i < binaryString.length; i++) {
    bytes[i] = binaryString.charCodeAt(i);
  }
  
  // Allocating fresh Float32Array every tick triggers frequent GC pauses
  const floatView = new Float32Array(bytes.buffer);
  console.log(`Processing ${floatView.length} telemetry samples`);
});
```

#### Production Standard (Correct)
> **Standard**: Leverages Capacitor 7 direct binary bridge transmission. Telemetry is delivered directly as an ArrayBuffer without Base64 overhead, and data is processed using zero-copy typed views and a pre-allocated Float32Array buffer, guaranteeing zero GC spikes.
```typescript
import { registerPlugin } from '@capacitor/core';

interface BinaryTelemetryPlugin {
  setBinaryBufferTarget(options: { channelId: string }): Promise<void>;
  addListener(
    eventName: 'binaryTelemetryFrame',
    listenerFunc: (buffer: ArrayBuffer) => void
  ): Promise<{ remove: () => Promise<void> }>;
}

const BiometricTelemetry = registerPlugin<BinaryTelemetryPlugin>('BiometricTelemetry');

// PRODUCTION FIX: Zero-serialization binary stream with pre-allocated TypedArray views
const CHUNK_SIZE = 128;
const telemetryCacheView = new Float32Array(CHUNK_SIZE);

BiometricTelemetry.addListener('binaryTelemetryFrame', (rawBuffer: ArrayBuffer) => {
  // Zero-copy wrapping directly over the native-dispatched ArrayBuffer
  const incomingView = new Float32Array(rawBuffer);
  
  // In-place copy into pre-allocated memory to avoid allocation-driven GC pauses
  telemetryCacheView.set(incomingView.subarray(0, CHUNK_SIZE));
  
  // Downstream zero-copy read
  processTelemetryFrame(telemetryCacheView);
});

function processTelemetryFrame(data: Float32Array): void {
  // Consumes telemetry in-place without triggering UI thread re-renders or GC overhead
}
```

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: Capacitor 7 Zero-Serialization Binary Bridge Standard

Capacitor 7 Zero-Serialization Binary Bridge Standard defines an industrial-grade behavioral standard for mobile engineering. Mandates the usage of raw ArrayBuffer instances and TypedArray views over native-to-web bridges for high-frequency sensor and biometric telemetry. Eliminates IPC serialization overhead, garbage collection thrashing, and UI thread frame drops by prohibiting Base64 encoding and JSON stringification in streaming pipelines. 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: Serializing High-Frequency Telemetry to Base64 or JSON Objects Across the Native-Web 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 DriftSerializing High-Frequency Telemetry to Base64 or JSON Objects Across the Native-Web 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 transmit high-frequency telemetry (>30Hz) as raw ArrayBuffers or direct TypedArray views supported by Capacitor 7 native binary channels.

Engineers MUST ALWAYS transmit high-frequency telemetry (>30Hz) as raw ArrayBuffers or direct TypedArray views supported by Capacitor 7 native binary channels.

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 native byte buffers, IMU data, or biometric signals into Base64 strings, numeric arrays, or JSON dictionaries across IPC.

Engineers MUST NOT convert native byte buffers, IMU data, or biometric signals into Base64 strings, numeric arrays, or JSON dictionaries across IPC.

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

Code SHOULD reuse pre-allocated TypedArray instances (e.g., Float32Array, Uint8Array) to prevent heap fragmentation and Garbage Collector (GC) stalls in the WebView.

Code SHOULD reuse pre-allocated TypedArray instances (e.g., Float32Array, Uint8Array) to prevent heap fragmentation and Garbage Collector (GC) stalls in the WebView.

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

Services MUST process binary telemetry windows using zero-copy view slicing (TypedArray.prototype.subarray) rather than ArrayBuffer.prototype.slice.

Services MUST process binary telemetry windows using zero-copy view slicing (TypedArray.prototype.subarray) rather than ArrayBuffer.prototype.slice.

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

Components NEVER execute JSON.parse or string decoding within high-frequency native telemetry event callbacks.

Components NEVER execute JSON.parse or string decoding within high-frequency native telemetry event callbacks.

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 Capacitor 7 Zero-Serialization Binary Bridge Standard critical for AI coding assistants?

Mandates the usage of raw ArrayBuffer instances and TypedArray views over native-to-web bridges for high-frequency sensor and biometric telemetry. Eliminates IPC serialization overhead, garbage collection thrashing, and UI thread frame drops by prohibiting Base64 encoding and JSON stringification in streaming pipelines. 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 (Serializing High-Frequency Telemetry to Base64 or JSON Objects Across the Native-Web 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

Capacitor