# rrweb-io/rrweb architecture

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

- Interactive diagram: https://gitdiagram.com/rrweb-io/rrweb
- Repository: https://github.com/rrweb-io/rrweb

## Overview

##### Main Components Overview

a) rrweb-snapshot
- Purpose: DOM serialization and reconstruction
- Components to show:
- Snapshot engine
- DOM rebuilding engine
- Serialization layer

b) rrweb (core)
- Purpose: Recording and replaying
- Components to show:
- Record module
- Replay module
- Mutation observer system
- Event handling system

c) rrweb-player
- Purpose: UI playback interface
- Components to show:
- Player UI components
- Playback controls
- Timeline management

##### Data Flow Architecture

**Recording Flow:**
**DOM Events → Mutation Observer → Event Processor → Serializer → Storage**

**Replay Flow:**
**Storage → Deserializer → DOM Rebuilder → Player UI → Browser Rendering**

##### Key Architectural Elements

a) Core Services (show as separate modules):
- Canvas recording service
- Console recording service
- WebGL recording service
- Shadow DOM handling
- Cross-origin iframe management
- Stylesheet management

b) Plugin System (show as extensible modules):
- Plugin API interface
- WebRTC plugins
- Console plugins
- Sequential ID plugins

##### Integration Points

External integration points:
- Browser APIs
- Storage systems
- Cross-origin communication channels
- WebRTC connections
- Custom event handlers

##### Component Relationships

Relationships between:
- Record and replay modules
- Snapshot and mutation handling
- Player UI and replay engine
- Plugin system and core functionality

##### Technical Details

Annotations for:
- TypeScript integration
- Build system connections
- Test framework integration
- Package dependencies

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "rrweb-snapshot"
        Snapshot["DOM Snapshot Engine"]:::snapshot
        Rebuild["DOM Rebuild Engine"]:::rebuild
        Serial["Serialization Layer"]:::serial
    end

    subgraph "rrweb-core"
        RecordMod["Record Module"]:::record
        ReplayMod["Replay Module"]:::replay
        MutObs["Mutation Observer"]:::observer
        EventHandler["Event Handler"]:::event
    end

    subgraph "Services"
        CanvasServ["Canvas Service"]:::service
        ConsoleServ["Console Service"]:::service
        WebGLServ["WebGL Service"]:::service
        ShadowDOM["Shadow DOM Handler"]:::service
        CrossOrigin["Cross-Origin Manager"]:::service
        StyleSheet["Stylesheet Manager"]:::service
    end

    subgraph "rrweb-player"
        PlayerUI["Player UI"]:::player
        PlaybackCtrl["Playback Controls"]:::player
        Timeline["Timeline Management"]:::player
    end

    subgraph "Plugin System"
        PluginAPI["Plugin API"]:::plugin
        WebRTCPlugin["WebRTC Plugin"]:::plugin
        ConsolePlugin["Console Plugin"]:::plugin
        SeqIDPlugin["Sequential ID Plugin"]:::plugin
    end

    subgraph "Storage & Integration"
        Storage[(Storage)]:::storage
        BrowserAPI["Browser APIs"]:::external
        CrossOriginComm["Cross-Origin Comm"]:::external
        WebRTCConn["WebRTC Connections"]:::external
    end

    %% Core Flow
    BrowserAPI --> MutObs
    MutObs --> RecordMod
    RecordMod --> Serial
    Serial --> Storage
    Storage --> Rebuild
    Rebuild --> ReplayMod
    ReplayMod --> PlayerUI

    %% Service Connections
    RecordMod --> CanvasServ
    RecordMod --> ConsoleServ
    RecordMod --> WebGLServ
    RecordMod --> ShadowDOM
    RecordMod --> CrossOrigin
    RecordMod --> StyleSheet

    %% Plugin Integration
    PluginAPI --> WebRTCPlugin
    PluginAPI --> ConsolePlugin
    PluginAPI --> SeqIDPlugin
    RecordMod --> PluginAPI

    %% Player Integration
    PlayerUI --> PlaybackCtrl
    PlayerUI --> Timeline
    ReplayMod --> Timeline

    %% External Integration
    CrossOrigin --> CrossOriginComm
    WebRTCPlugin --> WebRTCConn

    %% Click Events
    click Snapshot "https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb-snapshot/src/snapshot.ts"
    click Rebuild "https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb-snapshot/src/rebuild.ts"
    click RecordMod "https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb/src/record/index.ts"
    click MutObs "https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb/src/record/observer.ts"
    click ReplayMod "https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb/src/replay/index.ts"
    click PlayerUI "https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb-player/src/Player.svelte"
    click PlaybackCtrl "https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb-player/src/Controller.svelte"
    click CanvasServ "https://github.com/rrweb-io/rrweb/tree/master/packages/rrweb/src/record/observers/canvas"
    click ConsoleServ "https://github.com/rrweb-io/rrweb/blob/master/packages/plugins/rrweb-plugin-console-record/src/index.ts"
    click ShadowDOM "https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb/src/record/shadow-dom-manager.ts"
    click CrossOrigin "https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb/src/record/cross-origin-iframe-mirror.ts"
    click StyleSheet "https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb/src/record/stylesheet-manager.ts"
    click WebRTCPlugin "https://github.com/rrweb-io/rrweb/tree/master/packages/plugins/rrweb-plugin-canvas-webrtc-record"
    click ConsolePlugin "https://github.com/rrweb-io/rrweb/tree/master/packages/plugins/rrweb-plugin-console-record"
    click SeqIDPlugin "https://github.com/rrweb-io/rrweb/tree/master/packages/plugins/rrweb-plugin-sequential-id-record"

    %% Styling
    classDef snapshot fill:#e1f5fe,stroke:#01579b
    classDef rebuild fill:#e1f5fe,stroke:#01579b
    classDef serial fill:#fff3e0,stroke:#ff6f00
    classDef record fill:#e8f5e9,stroke:#1b5e20
    classDef replay fill:#e3f2fd,stroke:#0d47a1
    classDef observer fill:#e8f5e9,stroke:#1b5e20
    classDef event fill:#e8f5e9,stroke:#1b5e20
    classDef service fill:#f3e5f5,stroke:#4a148c
    classDef player fill:#e3f2fd,stroke:#0d47a1
    classDef plugin fill:#e1bee7,stroke:#4a148c
    classDef storage fill:#fff3e0,stroke:#ff6f00
    classDef external fill:#eceff1,stroke:#263238
```
