# bndkt/react-native-widget-extension architecture

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

- Interactive diagram: https://gitdiagram.com/bndkt/react-native-widget-extension
- Repository: https://github.com/bndkt/react-native-widget-extension

## Overview

##### Main Components
- Expo Config Plugin Module (Plugin Code):
- Located in the “plugin” folder (and supplementary code in “src”).
- Contains code that integrates with the Expo (React Native) ecosystem via functions such as withConfig, withPodfile, withWidgetExtensionEntitlements, and withXcode.
- Houses helper methods in “plugin/src/lib” and “plugin/src/xcode” that modify the native iOS project files.
- Widget Extension Swift Files:
- Provided by the developer in a folder (e.g., “SampleWidgetExtension” as shown in the “example” folder).
- Contains key Swift source files like Attributes.swift, Module.swift, and additional asset/configuration files (e.g., Info.plist, Assets.xcassets).
- React Native App & App Configuration:
- The configuration happens via app.json where the plugin is referenced and configured (parameters like frequentUpdates, widgetsFolder, deploymentTarget, etc.).
- Acts as an entry point from the React side that calls functions such as startActivity, updateActivity, endActivity.
- Xcode Project Modifications:
- Implicit in the plugin code: the plugin uses its helper functions to update the Xcode project automatically to include the widget extension.
- This process involves modifying build phases, PBX project groups, targets, and entitlements.
- Example Application:
- Located in the “example” folder.
- Acts as a demo project that uses the plugin, providing a concrete illustration of how the widget extension is integrated.

##### Relationships and Data Flow
- The React Native application uses the Expo config plugin by referencing it in app.json.
- The Expo config plugin then invokes various helper functions (from “plugin/src/lib” and “plugin/src/xcode”) to modify the iOS Xcode project.
- The plugin services leverage the provided Swift widget extension code from the specified widgetsFolder.
- Relationship between the plugin processing and the native Swift widget components (e.g., Assets, module definitions, attributes).
- Finally, on the runtime side, the native Swift module exposes functions (startActivity, stopActivity, etc.) that can be called from JavaScript.

##### Architectural Patterns & Design Principles
- Extensibility and Modularity: The plugin is highly modular – it separates concerns between Expo configuration, native iOS modifications (handled by the helper functions) and the widget code provided by the developer.
- Integration/Bridging Layer: The plugin serves as a bridge between JavaScript (Expo/React Native) and native iOS (Swift), so it’s important to clearly mark the boundary between these layers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "React Native Layer"
        A["App Configuration (app.json)"]:::js
        B["React Native API Layer (App.tsx)"]:::js
        H["Example Application"]:::js
    end

    subgraph "Plugin Core"
        C["Expo Config Plugin Module"]:::plugin
        F["iOS Lib Helpers"]:::plugin
        G["iOS Xcode Helpers"]:::plugin
    end

    subgraph "Native iOS Integration"
        D["Xcode Project Modifier"]:::native
        E["Swift Widget Extension"]:::native
    end

    A -->|"config"| C
    B -->|"invokes"| C
    H -->|"demonstrates"| C
    F -->|"supports"| C
    G -->|"supports"| C
    C -->|"patches"| D
    C -->|"integrates"| E
    D -->|"modifies"| E
    B <-->|"liveUpdate"| E

    click A "https://github.com/bndkt/react-native-widget-extension/blob/main/example/app.json"
    click B "https://github.com/bndkt/react-native-widget-extension/blob/main/example/App.tsx"
    click H "https://github.com/bndkt/react-native-widget-extension/tree/main/example/"
    click C "https://github.com/bndkt/react-native-widget-extension/tree/main/plugin/"
    click F "https://github.com/bndkt/react-native-widget-extension/tree/main/plugin/src/lib"
    click G "https://github.com/bndkt/react-native-widget-extension/tree/main/plugin/src/xcode"
    click E "https://github.com/bndkt/react-native-widget-extension/tree/main/example/SampleWidgetExtension"

    classDef js fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef plugin fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef native fill:#ffcc99,stroke:#333,stroke-width:2px;
```
