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

Capacitor 7 Zero-Copy ArrayBuffer Native Bridge Standard

Enforces direct typed memory transfer across the Capacitor 7 JavaScript-to-Native bridge for binary payloads without intermediate Base64 serialization. Eliminates high-frequency garbage collection pauses, bridge payload inflation, and main-thread frame drops during large binary I/O operations.

Prohibited Anti-Pattern: Serializing Raw Binary Buffers to Base64 Strings Within Capacitor Plugin Call Payloads

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Capacitor 7 Zero-Copy ArrayBuffer Native Bridge Standard - Enforces direct typed memory transfer across the Capacitor 7 JavaScript-to-Native bridge for binary payloads without intermediate Base64 serialization. Eliminates high-frequency garbage collection pauses, bridge payload inflation, and main-thread frame drops during large binary I/O operations.
globs: src/**/*.{ts,tsx}, ios/App/**/*.{swift,m}, android/app/src/**/*.{kt,java}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/capacitor-7-zero-copy-arraybuffer-transfer-standard"
---

# Capacitor 7 Zero-Copy ArrayBuffer Native Bridge Standard

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Serializing Raw Binary Buffers to Base64 Strings Within Capacitor Plugin Call Payloads

## System Constraints
You are a Principal Mobile Architect enforcing the Capacitor 7 Hybrid Plugin Zero-Copy ArrayBuffer Transfer Standard. You mandate direct typed array transfers over native bridges, preventing Base64 stringification, string allocation bottlenecks, and UI thread starvation.

## Strict Guidelines
- Engineers MUST ALWAYS transfer binary payloads using native ArrayBuffer or Uint8Array objects natively supported by Capacitor 7 bridge interfaces.
- Engineers MUST NOT convert raw binary data to Base64, hex strings, or numeric arrays prior to passing parameters to native plugin methods.
- Code SHOULD leverage Web Workers or OffscreenCanvas contexts to prepare ArrayBuffers before dispatching bridge requests to isolate memory allocation from the UI thread.
- Native implementations MUST map the underlying ByteBuffer on Android or direct NSData pointers on iOS without copying memory chunks into intermediate JSON strings.
- Components NEVER execute bridge invocations exceeding 64KB on the main rendering tick or within tight animation frame loops.

## Bad vs Good Implementations
### Capacitor 7 Binary Ingestion: Base64 Stringification vs. Native ArrayBuffer Transfer

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Iterating over binary memory to create a character string and subsequently Base64 encoding via btoa creates immense garbage collector pressure, doubles or triples peak heap usage, and blocks the browser UI thread during bridge dispatch.
```typescript
import { registerPlugin } from '@capacitor/core';

interface LegacyDataTransferPlugin {
  uploadStream(options: { data: string }): Promise<{ bytesWritten: number }>;
}

const NativeTransfer = registerPlugin<LegacyDataTransferPlugin>('LegacyDataTransfer');

export async function sendTelemetryFrame(buffer: ArrayBuffer): Promise<number> {
  // ANTI-PATTERN: Base64 serialization inflates memory footprint by 33%
  // and triggers severe Garbage Collection stalls on the WebView main thread.
  const bytes = new Uint8Array(buffer);
  let binary = '';
  for (let i = 0; i < bytes.byteLength; i++) {
    binary += String.fromCharCode(bytes[i]);
  }
  const base64Data = btoa(binary);

  const result = await NativeTransfer.uploadStream({ data: base64Data });
  return result.bytesWritten;
}
```

#### Production Standard (Correct)
> **Standard**: Capacitor 7 allows direct passing of ArrayBuffer parameters without stringification. Native bridges map the memory directly via JNI DirectByteBuffer on Android and bridged NSData on iOS, avoiding all JSON encode/decode steps and thread stalls.
```typescript
import { registerPlugin } from '@capacitor/core';

interface ZeroCopyDataTransferPlugin {
  uploadStream(options: { data: ArrayBuffer }): Promise<{ bytesWritten: number }>;
}

const NativeTransfer = registerPlugin<ZeroCopyDataTransferPlugin>('ZeroCopyDataTransfer');

export async function sendTelemetryFrame(buffer: ArrayBuffer): Promise<number> {
  // PRODUCTION STANDARD: Pass raw ArrayBuffer directly to Capacitor 7 plugin bridge.
  // Native platform consumes zero-copy DirectByteBuffer on Android and NSData zero-copy reference on iOS.
  const result = await NativeTransfer.uploadStream({
    data: buffer
  });

  return result.bytesWritten;
}
```

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-Copy ArrayBuffer Native Bridge Standard

Capacitor 7 Zero-Copy ArrayBuffer Native Bridge Standard defines an industrial-grade behavioral standard for mobile engineering. Enforces direct typed memory transfer across the Capacitor 7 JavaScript-to-Native bridge for binary payloads without intermediate Base64 serialization. Eliminates high-frequency garbage collection pauses, bridge payload inflation, and main-thread frame drops during large binary I/O operations. 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 Raw Binary Buffers to Base64 Strings Within Capacitor Plugin Call Payloads 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 Raw Binary Buffers to Base64 Strings Within Capacitor Plugin Call PayloadsCritical
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 payloads using native ArrayBuffer or Uint8Array objects natively supported by Capacitor 7 bridge interfaces.

Engineers MUST ALWAYS transfer binary payloads using native ArrayBuffer or Uint8Array objects natively supported by Capacitor 7 bridge interfaces.

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 raw binary data to Base64, hex strings, or numeric arrays prior to passing parameters to native plugin methods.

Engineers MUST NOT convert raw binary data to Base64, hex strings, or numeric arrays prior to passing parameters to native plugin methods.

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 leverage Web Workers or OffscreenCanvas contexts to prepare ArrayBuffers before dispatching bridge requests to isolate memory allocation from the UI thread.

Code SHOULD leverage Web Workers or OffscreenCanvas contexts to prepare ArrayBuffers before dispatching bridge requests to isolate memory allocation from the UI thread.

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

Native implementations MUST map the underlying ByteBuffer on Android or direct NSData pointers on iOS without copying memory chunks into intermediate JSON strings.

Native implementations MUST map the underlying ByteBuffer on Android or direct NSData pointers on iOS without copying memory chunks into intermediate JSON strings.

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 bridge invocations exceeding 64KB on the main rendering tick or within tight animation frame loops.

Components NEVER execute bridge invocations exceeding 64KB on the main rendering tick or within tight animation frame loops.

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-Copy ArrayBuffer Native Bridge Standard critical for AI coding assistants?

Enforces direct typed memory transfer across the Capacitor 7 JavaScript-to-Native bridge for binary payloads without intermediate Base64 serialization. Eliminates high-frequency garbage collection pauses, bridge payload inflation, and main-thread frame drops during large binary I/O operations. 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 Raw Binary Buffers to Base64 Strings Within Capacitor Plugin Call Payloads) 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