# shopify/react-native-skia architecture

> Architecture diagram of the GitHub repository shopify/react-native-skia, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shopify/react-native-skia
- Repository: https://github.com/shopify/react-native-skia

## Overview

##### Main Components Architecture

**┌─ React Native Application ─────────────────────────────────────┐**

- ┌─ React Native Skia ──────────────────────────────────┐    │

- ┌─ JavaScript/TypeScript Layer ─────────────────┐   │    │
- Components API                              │   │    │
- Animation System                            │   │    │
- DOM Renderer                               │   │    │
- ┘   │    │

- ┌─ Native Bridge ────────────────────────────────┐  │    │
- JSI Bindings                                 │  │    │
- Native Module Interface                      │  │    │
- ┘  │    │

- ┌─ Platform-Specific Implementation ──────────────┐  │    │
- ┌─ iOS ─────────┐    ┌─ Android ────────┐     │  │    │
- Metal Context │    │ OpenGL Context   │     │  │    │
- ┘    └─────────────────┘     │  │    │
- ┌─ Web ─────────┐                            │  │    │
- WebGL Context │                            │  │    │
- ┘                            │  │    │
- ┘  │    │

- ┌─ Skia Engine ─────────────────────────────────┐   │    │
- Graphics Pipeline                           │   │    │
- Rendering Engine                           │   │    │
- Canvas Operations                          │   │    │
- ┘   │    │
- ┘    │
- ┘

##### Key Components to Highlight

a. JavaScript/TypeScript Layer:
- DOM API (`/src/dom`)
- Renderer (`/src/renderer`)
- Animation system (`/src/animation`)
- Component library (`/src/renderer/components`)

b. Native Bridge:
- JSI implementations (`/cpp/jsi`)
- Platform contexts (`/cpp/rnskia`)
- Native module specs (`/src/specs`)

c. Platform-Specific:
- iOS implementation (`/ios`)
- Android implementation (`/android`)
- Web implementation (`/src/web`)

d. Core Skia Integration:
- Skia types (`/src/skia/types`)
- Core functionality (`/src/skia/core`)
- Platform-specific bindings

##### Data Flow Indicators

- Component rendering pipeline
- Native bridge communication
- Graphics processing flow
- Event handling

##### Additional Elements

- Testing infrastructure
- Build system
- External dependencies
- Development tools

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph RN[React Native Application]
        subgraph RNSK[React Native Skia]
            subgraph JSLayer[JavaScript/TypeScript Layer]
                CompAPI[Components API]:::jscomp
                AnimSys[Animation System]:::jscomp
                DOMRend[DOM Renderer]:::jscomp
                DOMAPI[DOM API]:::jscomp
            end

            subgraph NativeBridge[Native Bridge]
                JSIBind[JSI Bindings]:::bridge
                NatMod[Native Module Interface]:::bridge
                PlatCtx[Platform Context]:::bridge
            end

            subgraph PlatImpl[Platform-Specific Implementation]
                subgraph iOS[iOS]
                    MetalCtx[Metal Context]:::platform
                end
                subgraph Android[Android]
                    OpenGLCtx[OpenGL Context]:::platform
                end
                subgraph Web[Web]
                    WebGLCtx[WebGL Context]:::platform
                end
            end

            subgraph SkiaEngine[Skia Engine]
                GraphPipe[Graphics Pipeline]:::skia
                RenderEng[Rendering Engine]:::skia
                CanvasOp[Canvas Operations]:::skia
                CoreTypes[Core Types]:::skia
            end

            subgraph Testing[Testing Infrastructure]
                TestFiles[Test Files]:::test
                TestExamples[Test Examples]:::test
            end

            subgraph Docs[Documentation]
                DocFiles[Documentation]:::docs
                Examples[Examples]:::docs
            end
        end
    end

    %% Connections
    CompAPI --> DOMRend
    AnimSys --> DOMRend
    DOMAPI --> DOMRend
    DOMRend --> JSIBind
    JSIBind --> NatMod
    NatMod --> PlatCtx
    PlatCtx --> MetalCtx & OpenGLCtx & WebGLCtx
    MetalCtx & OpenGLCtx & WebGLCtx --> GraphPipe
    GraphPipe --> RenderEng
    RenderEng --> CanvasOp
    CoreTypes --> CanvasOp

    %% Click Events
    click CompAPI "https://github.com/shopify/react-native-skia/tree/main/packages/skia/src/renderer/components/"
    click AnimSys "https://github.com/shopify/react-native-skia/tree/main/packages/skia/src/animation/"
    click DOMRend "https://github.com/shopify/react-native-skia/tree/main/packages/skia/src/renderer/"
    click DOMAPI "https://github.com/shopify/react-native-skia/tree/main/packages/skia/src/dom/"
    click JSIBind "https://github.com/shopify/react-native-skia/tree/main/packages/skia/cpp/jsi/"
    click NatMod "https://github.com/shopify/react-native-skia/tree/main/packages/skia/src/specs/"
    click PlatCtx "https://github.com/shopify/react-native-skia/blob/main/packages/skia/cpp/rnskia/RNSkPlatformContext.h"
    click iOS "https://github.com/shopify/react-native-skia/tree/main/packages/skia/ios/RNSkia-iOS/"
    click Android "https://github.com/shopify/react-native-skia/tree/main/packages/skia/android/"
    click Web "https://github.com/shopify/react-native-skia/tree/main/packages/skia/src/web/"
    click CoreTypes "https://github.com/shopify/react-native-skia/tree/main/packages/skia/src/skia/types/"
    click CanvasOp "https://github.com/shopify/react-native-skia/blob/main/packages/skia/src/skia/types/Canvas.ts"
    click TestFiles "https://github.com/shopify/react-native-skia/tree/main/packages/skia/src/__tests__/"
    click TestExamples "https://github.com/shopify/react-native-skia/tree/main/packages/skia/src/renderer/__tests__/"
    click DocFiles "https://github.com/shopify/react-native-skia/tree/main/apps/docs/docs/"
    click Examples "https://github.com/shopify/react-native-skia/tree/main/apps/paper/src/Examples/"

    %% Styles
    classDef jscomp fill:#3498db,stroke:#2980b9,color:white
    classDef bridge fill:#9b59b6,stroke:#8e44ad,color:white
    classDef platform fill:#e67e22,stroke:#d35400,color:white
    classDef skia fill:#2ecc71,stroke:#27ae60,color:white
    classDef test fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef docs fill:#f1c40f,stroke:#f39c12,color:black
```
