# rive-app/rive-runtime architecture

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

- Interactive diagram: https://gitdiagram.com/rive-app/rive-runtime
- Repository: https://github.com/rive-app/rive-runtime

## Overview

##### High-Level Architecture Overview
The system should be represented as a layered architecture with these main components:

a. Core Runtime Layer
- File Loading & Parsing
- Scene Graph Management
- Animation System
- State Machine System
- Math & Utilities

b. Rendering Layer
- Abstract Renderer Interface
- Multiple Concrete Renderers (Skia, OpenGL, etc.)
- Asset Management

c. Platform Integration Layer
- Platform-specific implementations
- Build System
- Testing Framework

##### Key Components

a. File Processing Pipeline:
**.riv File → Binary Reader → Artboard Loading → Scene Graph Construction**

b. Animation System:
**Linear Animations ←→ State Machines**
- ↓
**Animation Instance**
- ↓
**Scene Graph Updates**

c. Rendering Pipeline:
**Abstract Renderer**
- ↓
**Concrete Implementations**
- Skia Renderer
- OpenGL Renderer
- Platform-specific renderers

##### Detailed Component Breakdown

Core Systems:
**Artboard**
- ↓
**Components**
- Nodes
- Constraints
- Bones
- ↓
**Animation System**
- Linear Animations
- State Machines
- Interpolators

##### Integration Points

Clear boundaries between:
- Core library and client code
- Abstract interfaces and implementations
- Platform-dependent and platform-independent code

##### Implementation Details

Technical aspects:
- SIMD optimization support
- Clang vector builtins usage
- Cross-platform compatibility
- Performance-critical paths

- Clean separation between core runtime and rendering
- Extensibility points for new renderers
- Platform abstraction layer
- Asset management system
- Testing and validation infrastructure

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef core fill:#e1f5fe,stroke:#01579b
    classDef render fill:#e8f5e9,stroke:#1b5e20
    classDef platform fill:#fff3e0,stroke:#e65100
    classDef test fill:#f5f5f5,stroke:#424242
    classDef build fill:#f3e5f5,stroke:#4a148c

    subgraph CoreRuntime["Core Runtime Layer"]
        FileLoad["File Loading & Parsing"]:::core
        SceneGraph["Scene Graph Management"]:::core
        AnimSystem["Animation System"]:::core
        StateMachine["State Machine System"]:::core
        MathUtils["Math & Utilities"]:::core
        DataBind["Data Binding"]:::core
        TextSystem["Text System"]:::core
        LayoutSystem["Layout System"]:::core
    end

    subgraph RenderLayer["Rendering Layer"]
        AbstractRenderer["Abstract Renderer Interface"]:::render
        SkiaRenderer["Skia Renderer"]:::render
        OpenGLRenderer["OpenGL Renderer"]:::render
        CGRenderer["Core Graphics Renderer"]:::render
        AssetMgmt["Asset Management"]:::render
        AssetDecoders["Asset Decoders"]:::render
    end

    subgraph PlatformLayer["Platform Integration Layer"]
        BuildSystem["Build System"]:::build
        TestFramework["Testing Framework"]:::test
        PlatformImpl["Platform-specific Implementations"]:::platform
    end

    %% Core Runtime Relationships
    FileLoad --> SceneGraph
    SceneGraph --> AnimSystem
    AnimSystem --> StateMachine
    MathUtils --> SceneGraph
    DataBind --> SceneGraph
    TextSystem --> SceneGraph
    LayoutSystem --> SceneGraph

    %% Rendering Relationships
    AbstractRenderer --> SkiaRenderer
    AbstractRenderer --> OpenGLRenderer
    AbstractRenderer --> CGRenderer
    AssetMgmt --> AssetDecoders
    SceneGraph --> AbstractRenderer
    AssetMgmt --> AbstractRenderer

    %% Platform Integration
    PlatformImpl --> AbstractRenderer
    BuildSystem --> PlatformImpl
    TestFramework --> CoreRuntime

    %% Click Events
    click FileLoad "https://github.com/rive-app/rive-runtime/blob/main/include/rive/core/binary_reader.hpp"
    click AnimSystem "https://github.com/rive-app/rive-runtime/tree/main/include/rive/animation/"
    click StateMachine "https://github.com/rive-app/rive-runtime/blob/main/include/rive/animation/state_machine.hpp"
    click MathUtils "https://github.com/rive-app/rive-runtime/tree/main/include/rive/math/"
    click SceneGraph "https://github.com/rive-app/rive-runtime/blob/main/include/rive/artboard.hpp"
    click AbstractRenderer "https://github.com/rive-app/rive-runtime/blob/main/include/rive/renderer.hpp"
    click SkiaRenderer "https://github.com/rive-app/rive-runtime/tree/main/skia/renderer/"
    click OpenGLRenderer "https://github.com/rive-app/rive-runtime/tree/main/renderer/include/rive/renderer/gl/"
    click CGRenderer "https://github.com/rive-app/rive-runtime/tree/main/cg_renderer/"
    click AssetMgmt "https://github.com/rive-app/rive-runtime/tree/main/include/rive/assets/"
    click AssetDecoders "https://github.com/rive-app/rive-runtime/tree/main/decoders/"
    click BuildSystem "https://github.com/rive-app/rive-runtime/tree/main/build/"
    click TestFramework "https://github.com/rive-app/rive-runtime/tree/main/tests/"
    click PlatformImpl "https://github.com/rive-app/rive-runtime/tree/main/dependencies/"
    click DataBind "https://github.com/rive-app/rive-runtime/tree/main/include/rive/data_bind/"
    click TextSystem "https://github.com/rive-app/rive-runtime/tree/main/include/rive/text/"
    click LayoutSystem "https://github.com/rive-app/rive-runtime/tree/main/include/rive/layout/"

    %% Legend
    subgraph Legend
        CoreComp["Core Component"]:::core
        RenderComp["Rendering Component"]:::render
        PlatformComp["Platform Component"]:::platform
        TestComp["Testing Component"]:::test
        BuildComp["Build Component"]:::build
    end
```
