# storybookjs/react-native architecture

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

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

## Overview

##### Main Components

a. Core Components:
- Storybook UI Engine
- Story Loader System
- Metro Bundler Integration
- WebSocket Server (for device synchronization)
- Addon System

b. Package Structure:
- Core Package (@storybook/react-native)
- Ondevice Addons
- Controls
- Actions
- Backgrounds
- Notes
- React Native UI Components
- Theming System

**[Host React Native App] <---> [Storybook Entry Point] <---> [Story Renderer]**

- [Metro Bundler + Storybook Config]

- [Story Loader] <---> [Core Engine] <---> [WebSocket Server]

- [Addon System]

**[Controls Addon] --- [Actions Addon] --- [Backgrounds Addon] --- [Notes Addon]**
- ______________|__________________|________________/

- [Addon API]

##### Connection Types

- Double lines: Data flow

##### Key Elements to Highlight

a. Story Loading Pipeline:
**[Story Files] -> [Metro Transformer] -> [Story Registry] -> [UI Renderer]**

b. Device Communication:
**[Device UI] <---> [WebSocket Server] <---> [Other Devices]**

c. Configuration Flow:
**[main.ts] -> [Preview Config] -> [Story Config] -> [Addon Config]**

##### Additional Details

Annotations for:
- File paths for key configuration files
- Entry points for different platforms
- Addon registration process
- Story format (CSF) handling
- Metro configuration integration points

##### Implementation Notes

- Use standard UML or similar notation
- Maintain clear separation of concerns
- Both synchronous and asynchronous flows

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        HostApp["Host React Native App"]
        EntryPoint["Storybook Entry Point"]
        StoryRenderer["Story Renderer"]:::core
    end

    subgraph "Core Architecture"
        MetroBundler["Metro Bundler + Config"]:::core
        StoryLoader["Story Loader System"]:::core
        CoreEngine["Core Engine"]:::core
        WSServer["WebSocket Server"]:::core
        AddonSystem["Addon System"]:::addon
    end

    subgraph "Addon Layer"
        Controls["Controls Addon"]:::addon
        Actions["Actions Addon"]:::addon
        Backgrounds["Backgrounds Addon"]:::addon
        Notes["Notes Addon"]:::addon
        AddonAPI["Addon API"]:::addon
    end

    subgraph "UI and Preview"
        StoryView["Story View"]:::ui
        UIComponents["UI Components"]:::ui
        ThemeSystem["Theming System"]:::ui
        PreviewSystem["Preview System"]:::ui
    end

    subgraph "Configuration"
        Config["Configuration System"]:::config
        Types["Core Types & Interfaces"]:::config
    end

    %% Connections
    HostApp <--> EntryPoint
    EntryPoint <--> StoryRenderer
    StoryRenderer --> CoreEngine
    MetroBundler --> CoreEngine
    StoryLoader --> CoreEngine
    CoreEngine <--> WSServer
    CoreEngine --> AddonSystem
    
    AddonSystem --> AddonAPI
    AddonAPI --> Controls
    AddonAPI --> Actions
    AddonAPI --> Backgrounds
    AddonAPI --> Notes
    
    CoreEngine --> StoryView
    StoryView --> UIComponents
    ThemeSystem --> UIComponents
    PreviewSystem --> StoryRenderer
    
    Config -.-> CoreEngine
    Types -.-> CoreEngine

    %% Click Events
    click CoreEngine "https://github.com/storybookjs/react-native/tree/next/packages/react-native/src/"
    click StoryLoader "https://github.com/storybookjs/react-native/blob/next/packages/react-native/scripts/generate.js"
    click MetroBundler "https://github.com/storybookjs/react-native/blob/next/packages/react-native/src/metro/withStorybook.ts"
    click StoryView "https://github.com/storybookjs/react-native/tree/next/packages/react-native/src/components/StoryView/"
    click Controls "https://github.com/storybookjs/react-native/tree/next/packages/ondevice-controls/"
    click Actions "https://github.com/storybookjs/react-native/tree/next/packages/ondevice-actions/"
    click Backgrounds "https://github.com/storybookjs/react-native/tree/next/packages/ondevice-backgrounds/"
    click Notes "https://github.com/storybookjs/react-native/tree/next/packages/ondevice-notes/"
    click UIComponents "https://github.com/storybookjs/react-native/tree/next/packages/react-native-ui/src/"
    click ThemeSystem "https://github.com/storybookjs/react-native/tree/next/packages/react-native-theming/src/"
    click PreviewSystem "https://github.com/storybookjs/react-native/blob/next/packages/react-native/src/preview.ts"
    click Config "https://github.com/storybookjs/react-native/tree/next/examples/expo-example/.storybook/"
    click Types "https://github.com/storybookjs/react-native/tree/next/packages/react-native/src/types/"

    %% Styles
    classDef core fill:#2374ab,color:#fff
    classDef addon fill:#ff7f50,color:#fff
    classDef ui fill:#4caf50,color:#fff
    classDef config fill:#9c27b0,color:#fff

    %% Legend
    subgraph Legend
        CoreComp["Core Component"]:::core
        AddonComp["Addon Component"]:::addon
        UIComp["UI Component"]:::ui
        ConfigComp["Configuration"]:::config
    end
```
