# mmendesas/sdk-bridge architecture

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

- Interactive diagram: https://gitdiagram.com/mmendesas/sdk-bridge
- Repository: https://github.com/mmendesas/sdk-bridge

## Overview

##### Project type and purpose
- This is not a monolithic full-stack app but a dual-app “SDK Bridge” solution:
- A React Native mobile application (“mobile/”) that embeds a web store experience via WebView and exposes a native “inapp-sdk.”
- A React web application (“web/”) built with Vite that runs inside the WebView as a “web-sdk” and manages authentication flows via XState.
- Purpose: Demonstrate bidirectional communication between native and web SDKs to simulate purchase and authentication flows.

##### File structure
- mobile/ directory:
- Native folders (android/, ios/) with MainActivity, AppDelegate, Gradle and Pod configurations
- JavaScript/TypeScript app code (App.tsx, index.js, src/)
- inapp-sdk subfolder (EventHub.ts, SDKWebView.tsx, useEventHub.ts)
- web/ directory:
- Vite config, package.json, tsconfigs
- React code in src/ (App.tsx, screens/, components/, context/PaymentProvider.tsx)
- web-sdk subfolder (EventHub.ts, channel.ts, index.ts)
- paymentMachine.ts (XState state machine)

##### Extract insights from the README
- Emphasizes two concurrently running projects (“mobile” with `npx react-native run-android`, “web” with `yarn dev`)
- Features:
- inapp-sdk ↔ web-sdk communication
- WebView embedding of web-app inside mobile
- State machine via XState controlling expiration timer and purchase flow
- No external backend: flows are simulated entirely in-app.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Host
    subgraph "Mobile Host"
        direction TB
        subgraph "Mobile JS Layer"
            direction TB
            AppTS["App.tsx"]:::mobile
            IndexJS["index.js"]:::mobile
            ComponentsMobile["components"]:::mobile
            ScreensMobile["screens"]:::mobile
        end
        subgraph "Native Modules"
            direction TB
            AndroidMainActivity["MainActivity.java"]:::native
            AndroidMainApplication["MainApplication.java"]:::native
            iOSAppDelegate["AppDelegate.mm"]:::native
            iOSInfoPlist["Info.plist"]:::native
        end
        subgraph "inapp-sdk"
            direction TB
            InAppEventHub["EventHub.ts"]:::mobile
            SDKWebView["SDKWebView.tsx"]:::mobile
            UseEventHub["useEventHub.ts"]:::mobile
        end
    end

    %% WebView Bridge
    WebViewBridge["WebView Bridge"]:::bridge

    %% Web Host
    subgraph "Web Host"
        direction TB
        subgraph "Web JS Layer"
            direction TB
            WebMainTS["main.tsx"]:::web
            WebAppTS["App.tsx"]:::web
            ComponentsWeb["components"]:::web
            ScreensWeb["screens"]:::web
        end
        subgraph "web-sdk"
            direction TB
            WebEventHub["EventHub.ts"]:::web
            Channel["channel.ts"]:::web
            SDKIndex["index.ts"]:::web
        end
        StateMachine["paymentMachine.ts"]:::web
        PaymentProvider["PaymentProvider.tsx"]:::web
    end

    %% Flow
    AppTS -->|"openWebView"| SDKWebView
    SDKWebView -->|renders| WebViewBridge
    WebViewBridge -->|loads| WebMainTS
    WebMainTS -->|"bootstrap web-sdk"| WebEventHub
    WebAppTS -->|"purchaseRequested"| WebEventHub
    WebEventHub -->|postMessage| SDKWebView
    SDKWebView -->|"authWindowOpened"| WebEventHub
    WebEventHub -->|"authWindowOpened"| AppTS
    WebEventHub -->|trigger| StateMachine
    StateMachine -->|authResult| WebEventHub
    WebEventHub -->|complete| SDKWebView
    SDKWebView -->|"closeWebView"| AppTS

    %% Click Events
    click AppTS "https://github.com/mmendesas/sdk-bridge/blob/main/mobile/App.tsx"
    click IndexJS "https://github.com/mmendesas/sdk-bridge/blob/main/mobile/index.js"
    click ComponentsMobile "https://github.com/mmendesas/sdk-bridge/tree/main/mobile/src/components"
    click ScreensMobile "https://github.com/mmendesas/sdk-bridge/tree/main/mobile/src/screens"
    click AndroidMainActivity "https://github.com/mmendesas/sdk-bridge/blob/main/mobile/android/app/src/main/java/com/mobile/MainActivity.java"
    click AndroidMainApplication "https://github.com/mmendesas/sdk-bridge/blob/main/mobile/android/app/src/main/java/com/mobile/MainApplication.java"
    click iOSAppDelegate "https://github.com/mmendesas/sdk-bridge/blob/main/mobile/ios/mobile/AppDelegate.mm"
    click iOSInfoPlist "https://github.com/mmendesas/sdk-bridge/blob/main/mobile/ios/mobile/Info.plist"
    click InAppEventHub "https://github.com/mmendesas/sdk-bridge/blob/main/mobile/src/inapp-sdk/EventHub.ts"
    click SDKWebView "https://github.com/mmendesas/sdk-bridge/blob/main/mobile/src/inapp-sdk/SDKWebView.tsx"
    click UseEventHub "https://github.com/mmendesas/sdk-bridge/blob/main/mobile/src/inapp-sdk/useEventHub.ts"
    click WebMainTS "https://github.com/mmendesas/sdk-bridge/blob/main/web/src/main.tsx"
    click WebAppTS "https://github.com/mmendesas/sdk-bridge/blob/main/web/src/App.tsx"
    click ComponentsWeb "https://github.com/mmendesas/sdk-bridge/tree/main/web/src/components"
    click ScreensWeb "https://github.com/mmendesas/sdk-bridge/tree/main/web/src/screens"
    click WebEventHub "https://github.com/mmendesas/sdk-bridge/blob/main/web/src/web-sdk/EventHub.ts"
    click Channel "https://github.com/mmendesas/sdk-bridge/blob/main/web/src/web-sdk/channel.ts"
    click SDKIndex "https://github.com/mmendesas/sdk-bridge/blob/main/web/src/web-sdk/index.ts"
    click StateMachine "https://github.com/mmendesas/sdk-bridge/blob/main/web/src/paymentMachine.ts"
    click PaymentProvider "https://github.com/mmendesas/sdk-bridge/blob/main/web/src/context/PaymentProvider.tsx"

    %% Styles
    classDef mobile fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef native fill:#b3e6b3,stroke:#333,stroke-width:1px
    classDef bridge fill:#eeeeee,stroke:#666,stroke-width:1px,stroke-dasharray: 5 5
    classDef web fill:#ffebcc,stroke:#333,stroke-width:1px
```
