# mrousavy/react-native-vision-camera architecture

> Architecture diagram of the GitHub repository mrousavy/react-native-vision-camera, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mrousavy/react-native-vision-camera
- Repository: https://github.com/mrousavy/react-native-vision-camera

## Overview

##### Main Components Overview

a) React Native Layer
- Camera Component (Camera.tsx)
- Hooks (useCameraDevice, useCameraFormat, etc.)
- Device Management
- Configuration Interface

b) Native Bridge Layer
- Frame Processor Bridge
- Camera Module Bridge
- Device Manager Bridge

c) Platform-Specific Implementation
- iOS Implementation (AVFoundation)
- Android Implementation (CameraX)
- Native Camera Controls

##### Core Functional Blocks

Create distinct sections for the main features:

a) Camera Core
**┌─ Camera Core ──────────────┐**
- Device Management       │
- Session Management      │
- Configuration Control   │
- Preview Pipeline       │
- ┘

b) Media Capture
**┌─ Media Pipeline ─────────┐**
- Photo Capture         │
- Video Recording       │
- HDR Processing        │
- Format Management     │
- ┘

c) Frame Processing
**┌─ Frame Processing ───────┐**
- Frame Processor Runtime│
- Plugin System         │
- Worklet Execution     │
- Native Acceleration   │
- ┘

##### Data Flow Representation

**User Input → React Native → Native Bridge → Platform Camera APIs**
- ↓
**Frame Processors ← Native Bridge ← Camera Output**

##### Integration Points

External integration points:
- ML Kit Vision
- Reanimated
- Skia
- Frame Processor Plugins

##### Technical Details

Annotations for:
- Supported formats (4k/8k)
- FPS ranges (30-240)
- Hardware acceleration points
- Memory management
- Thread management

##### Architecture Patterns

Architectural patterns:
- Plugin System
- Event System
- Worklet System
- Buffer Management

- High-performance pipeline
- Native code integration
- Frame processor architecture
- Platform-specific optimizations
- Plugin extensibility

Remember to:
- Keep components visually distinct
- Clear data flow paths
- Performance-critical paths
- Hardware acceleration points

This system design should reflect VisionCamera's sophisticated architecture while maintaining clarity about how the components interact to deliver high-performance camera functionality.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph RNLayer["React Native Layer"]
        Camera["Camera Component"]:::rncomponent
        Hooks["Hooks"]:::rncomponent
        DeviceManagement["Device Management"]:::rncomponent
        Config["Configuration Interface"]:::rncomponent
    end

    subgraph Bridge["Native Bridge Layer"]
        FPBridge["Frame Processor Bridge"]:::bridge
        CameraBridge["Camera Module Bridge"]:::bridge
        DeviceBridge["Device Manager Bridge"]:::bridge
    end

    subgraph Platform["Platform-Specific Implementation"]
        direction TB
        subgraph iOS["iOS Implementation"]
            direction TB
            iOSCore["Core"]:::ios
            iOSSession["Camera Session"]:::ios
            iOSFP["Frame Processors"]:::ios
        end

        subgraph Android["Android Implementation"]
            direction TB
            AndroidCore["Core"]:::android
            AndroidSession["Camera Session"]:::android
            AndroidFP["Frame Processors"]:::android
        end
    end

    subgraph Processing["Frame Processing"]
        FPRuntime["Frame Processor Runtime"]:::processing
        PluginSystem["Plugin System"]:::processing
        WorkletExec["Worklet Execution"]:::processing
        NativeAccel["Native Acceleration"]:::processing
    end

    subgraph Media["Media Pipeline"]
        PhotoCapture["Photo Capture"]:::media
        VideoRec["Video Recording"]:::media
        HDRProcess["HDR Processing"]:::media
        FormatMgmt["Format Management"]:::media
    end

    subgraph External["External Integrations"]
        MLKit["ML Kit Vision"]:::external
        Reanimated["Reanimated"]:::external
        Skia["Skia"]:::external
        Plugins["Frame Processor Plugins"]:::external
    end

    %% Connections
    Camera --> FPBridge
    Camera --> CameraBridge
    DeviceManagement --> DeviceBridge
    
    FPBridge --> iOSFP & AndroidFP
    CameraBridge --> iOSCore & AndroidCore
    DeviceBridge --> iOSCore & AndroidCore
    
    iOSCore --> Media
    AndroidCore --> Media
    
    Processing --> FPBridge
    External --> Processing

    %% Click Events
    click Camera "https://github.com/mrousavy/react-native-vision-camera/blob/main/package/src/Camera.tsx"
    click Hooks "https://github.com/mrousavy/react-native-vision-camera/tree/main/package/src/hooks/"
    click DeviceManagement "https://github.com/mrousavy/react-native-vision-camera/blob/main/package/src/CameraDevices.ts"
    click FPBridge "https://github.com/mrousavy/react-native-vision-camera/blob/main/package/src/frame-processors/VisionCameraProxy.ts"
    click CameraBridge "https://github.com/mrousavy/react-native-vision-camera/blob/main/package/src/NativeCameraModule.ts"
    click DeviceBridge "https://github.com/mrousavy/react-native-vision-camera/tree/main/package/src/devices/"
    click iOSCore "https://github.com/mrousavy/react-native-vision-camera/tree/main/package/ios/Core/"
    click iOSSession "https://github.com/mrousavy/react-native-vision-camera/blob/main/package/ios/Core/CameraSession.swift"
    click iOSFP "https://github.com/mrousavy/react-native-vision-camera/tree/main/package/ios/FrameProcessors/"
    click AndroidCore "https://github.com/mrousavy/react-native-vision-camera/tree/main/package/android/src/main/java/com/mrousavy/camera/core/"
    click AndroidSession "https://github.com/mrousavy/react-native-vision-camera/blob/main/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt"
    click AndroidFP "https://github.com/mrousavy/react-native-vision-camera/tree/main/package/android/src/main/java/com/mrousavy/camera/frameprocessors/"
    click FPRuntime "https://github.com/mrousavy/react-native-vision-camera/tree/main/package/src/frame-processors/"
    click PhotoCapture "https://github.com/mrousavy/react-native-vision-camera/blob/main/package/ios/Core/CameraSession+Photo.swift"
    click VideoRec "https://github.com/mrousavy/react-native-vision-camera/blob/main/package/ios/Core/CameraSession+Video.swift"

    %% Styles
    classDef rncomponent fill:#3498db,stroke:#2980b9,color:white
    classDef bridge fill:#2ecc71,stroke:#27ae60,color:white
    classDef ios fill:#e74c3c,stroke:#c0392b,color:white
    classDef android fill:#9b59b6,stroke:#8e44ad,color:white
    classDef processing fill:#f1c40f,stroke:#f39c12,color:black
    classDef media fill:#e67e22,stroke:#d35400,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        RN["React Native"]:::rncomponent
        BR["Bridge"]:::bridge
        IOS["iOS"]:::ios
        AN["Android"]:::android
        PR["Processing"]:::processing
        ME["Media"]:::media
        EX["External"]:::external
    end
```
