# hyochan/react-native-iap architecture

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

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

## Overview

##### Project Type and Purpose
- This is a multi‐platform React Native library (an NPM package) that provides a unified JavaScript API for in-app purchases (IAP) across Apple App Store (StoreKit1 & StoreKit2), Google Play Billing, and Amazon IAP.
- It includes:
- Core TypeScript/JavaScript code under `/src` implementing hooks, event emitters, and platform abstraction.
- Native Android modules under `/android/src` (Play, Amazon, common) written in Kotlin/Java.
- Native iOS modules under `/ios` (Swift/Objective-C) bridging to StoreKit1/StoreKit2.
- An Expo config plugin (`/plugin`) for automating native project setup.
- An example React Native application (`/IapExample`) illustrating end-to-end usage.
- A documentation site (`/docs`) built with Docusaurus.
- CI/CD pipelines under `.github/workflows`, release scripts, and testing harnesses.

##### File Structure Analysis
- Top-level components:
- `/src` – Core JS API: entry point, `iap.ts`, `hooks/`, `modules/` (amazon.ts, android.ts, ios.ts, iosSk2.ts, common.ts), `eventEmitter.ts`, `PromiseUtils`.
- `/android` – Android library source tree, with subfolders for each store flavor (main, play, amazon), test targets (`testPlay`, `testAmazon`).
- `/ios` – iOS native module source (Swift & Obj-C), bridging header, promise keeper, support for StoreKit2.
- `/plugin` – Expo config plugin source for auto-linking (withIAP.ts).
- `/IapExample` – React Native example app: TypeScript UI (`src/`), native Android & iOS projects, Metro config.
- `/docs` – Documentation content (MDX), config, UI components.
- CI & publishing: `.github/workflows/*.yml`, `release-it.js`, `scripts/bootstrap.js`.
- Tests: unit tests under `/src/__tests__`, `/android/src/test*`, `/plugin/__tests__`, `/IapExample/__tests__`.

##### Key Insights from README
- Unified IAP interface for multiple store SDKs.
- Hooks API for React (useIAP, withIAPContext).
- Migration notes: StoreKit2, Play Billing Library v5, Amazon 3.x SDK.
- Example usage in `IapExample`.
- Documentation published separately via Docusaurus.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers Top to Bottom
    subgraph "Example Application" 
        direction TB
        ExampleApp["IapExample (React Native App)"]:::blue
    end

    subgraph "JS Core Layer" 
        direction TB
        IndexTS["index.ts"]:::blue
        IAPTS["iap.ts"]:::blue
        EventEmitter["eventEmitter.ts"]:::blue
        subgraph "Hooks"
            direction TB
            UseIAP["useIAP.ts"]:::blue
            WithIAPCtx["withIAPContext.tsx"]:::blue
        end
        subgraph "Platform Modules"
            direction TB
            AndroidMod["android.ts"]:::blue
            IOSMod["ios.ts"]:::blue
            IOSSk2Mod["iosSk2.ts"]:::blue
            AmazonMod["amazon.ts"]:::blue
            CommonMod["common.ts"]:::blue
        end
    end

    subgraph "React Native Bridge"
        direction TB
        Bridge["Auto-generated Native Module Registry"]:::blue
    end

    subgraph "Native Modules"
        direction TB
        subgraph "Android Modules"
            direction TB
            RNIapModule["RNIapModule.kt"]:::green
            PlayUtils["PlayUtils.kt"]:::green
            RNIapAmazon["RNIapAmazonModule.kt"]:::green
            AmazonProxy["PurchasingServiceProxyAmazonImpl.kt"]:::green
            PromiseUtilsAndroid["PromiseUtils.kt"]:::green
        end
        subgraph "iOS Modules"
            direction TB
            RNIapIosSwift["RNIapIos.swift"]:::orange
            RNIapIosObjC["RNIapIos.m"]:::orange
            RNIapSk2Swift["RNIapIosSk2.swift"]:::orange
            RNIapSk2ObjC["RNIapIosSk2.m"]:::orange
            IapUtils["IapUtils.swift"]:::orange
            IapSerUtils["IapSerializationUtils.swift"]:::orange
            PromiseKeeper["LatestPromiseKeeper.swift"]:::orange
            BridgingHeader["RNIapIos-Bridging-Header.h"]:::orange
        end
    end

    subgraph "External Store SDKs"
        direction TB
        PlaySDK["Google Play Billing Library"]:::gray
        AmazonSDK["Amazon IAP SDK"]:::gray
        StoreKit1["Apple StoreKit1"]:::gray
        StoreKit2["Apple StoreKit2"]:::gray
    end

    subgraph "Expo Config Plugin"
        direction TB
        WithIAPTS["withIAP.ts"]:::blue
        WithIAPJS["withIAP.js"]:::blue
    end

    subgraph "Documentation Site"
        direction TB
        DocusaurusConfig["docusaurus.config.js"]:::blue
        Sidebars["sidebars.js"]:::blue
        DocsContent["MDX docs/"]:::blue
        DocsUI["docs/src/"]:::blue
    end

    subgraph "CI/CD & Release"
        direction TB
        CI_CI["ci.yml"]:::purple
        CI_Android["ci-example-android.yml"]:::purple
        CI_iOS["ci-example-ios.yml"]:::purple
        CI_DeployDocs["deploy-documentation.yml"]:::purple
        CI_PublishPkg["publish-package.yml"]:::purple
        ReleaseScript["release-it.js"]:::purple
        Bootstrap["scripts/bootstrap.js"]:::purple
    end

    %% Connections
    ExampleApp -->|"imports API"| IndexTS
    IndexTS --> IAPTS
    IAPTS --> EventEmitter
    IAPTS --> UseIAP
    IAPTS --> WithIAPCtx
    IAPTS --> AndroidMod
    IAPTS --> IOSMod
    IAPTS --> IOSSk2Mod
    IAPTS --> AmazonMod
    IAPTS --> CommonMod

    IAPTS -->|"calls"| Bridge
    Bridge -->|"JNI / Objective-C Bridge"| RNIapModule
    Bridge --> RNIapAmazon
    Bridge --> PromiseUtilsAndroid
    Bridge --> RNIapIosSwift
    Bridge --> RNIapIosObjC
    Bridge --> RNIapSk2Swift
    Bridge --> RNIapSk2ObjC

    RNIapModule -->|"calls"| PlaySDK
    RNIapAmazon -->|"calls"| AmazonSDK
    RNIapIosSwift -->|"calls"| StoreKit1
    RNIapSk2Swift -->|"calls"| StoreKit2

    WithIAPTS -->|"build-time patch"| RNIapModule
    WithIAPTS --> RNIapIosSwift

    CI_CI -->|"runs tests"| IndexTS
    CI_CI -->|"runs tests"| RNIapModule
    CI_CI -->|"runs tests"| RNIapIosSwift
    CI_CI -->|"build example"| ExampleApp
    CI_DeployDocs -->|"deploys"| DocsContent
    CI_PublishPkg -->|"publishes"| IAPTS

    %% Click Events
    click IndexTS "https://github.com/hyochan/react-native-iap/blob/main/src/index.ts"
    click IAPTS "https://github.com/hyochan/react-native-iap/blob/main/src/iap.ts"
    click EventEmitter "https://github.com/hyochan/react-native-iap/blob/main/src/eventEmitter.ts"
    click UseIAP "https://github.com/hyochan/react-native-iap/blob/main/src/hooks/useIAP.ts"
    click WithIAPCtx "https://github.com/hyochan/react-native-iap/blob/main/src/hooks/withIAPContext.tsx"
    click AndroidMod "https://github.com/hyochan/react-native-iap/blob/main/src/modules/android.ts"
    click IOSMod "https://github.com/hyochan/react-native-iap/blob/main/src/modules/ios.ts"
    click IOSSk2Mod "https://github.com/hyochan/react-native-iap/blob/main/src/modules/iosSk2.ts"
    click AmazonMod "https://github.com/hyochan/react-native-iap/blob/main/src/modules/amazon.ts"
    click CommonMod "https://github.com/hyochan/react-native-iap/blob/main/src/modules/common.ts"

    click RNIapModule "https://github.com/hyochan/react-native-iap/blob/main/android/src/play/java/com/dooboolab/rniap/RNIapModule.kt"
    click PlayUtils "https://github.com/hyochan/react-native-iap/blob/main/android/src/play/java/com/dooboolab/rniap/PlayUtils.kt"
    click RNIapAmazon "https://github.com/hyochan/react-native-iap/blob/main/android/src/amazon/java/com/dooboolab/rniap/RNIapAmazonModule.kt"
    click AmazonProxy "https://github.com/hyochan/react-native-iap/blob/main/android/src/amazon/java/com/dooboolab/rniap/PurchasingServiceProxyAmazonImpl.kt"
    click PromiseUtilsAndroid "https://github.com/hyochan/react-native-iap/blob/main/android/src/main/java/com/dooboolab/rniap/PromiseUtils.kt"

    click RNIapIosSwift "https://github.com/hyochan/react-native-iap/blob/main/ios/RNIapIos.swift"
    click RNIapIosObjC "https://github.com/hyochan/react-native-iap/blob/main/ios/RNIapIos.m"
    click RNIapSk2Swift "https://github.com/hyochan/react-native-iap/blob/main/ios/RNIapIosSk2.swift"
    click RNIapSk2ObjC "https://github.com/hyochan/react-native-iap/blob/main/ios/RNIapIosSk2.m"
    click IapUtils "https://github.com/hyochan/react-native-iap/blob/main/ios/IapUtils.swift"
    click IapSerUtils "https://github.com/hyochan/react-native-iap/blob/main/ios/IapSerializationUtils.swift"
    click PromiseKeeper "https://github.com/hyochan/react-native-iap/blob/main/ios/LatestPromiseKeeper.swift"
    click BridgingHeader "https://github.com/hyochan/react-native-iap/blob/main/ios/RNIapIos-Bridging-Header.h"

    click WithIAPTS "https://github.com/hyochan/react-native-iap/blob/main/plugin/src/withIAP.ts"
    click WithIAPJS "https://github.com/hyochan/react-native-iap/blob/main/plugin/build/withIAP.js"

    click ExampleApp "https://github.com/hyochan/react-native-iap/tree/main/IapExample/src/"
    click DocsContent "https://github.com/hyochan/react-native-iap/tree/main/docs/docs/"
    click DocusaurusConfig "https://github.com/hyochan/react-native-iap/blob/main/docs/docusaurus.config.js"
    click Sidebars "https://github.com/hyochan/react-native-iap/blob/main/docs/sidebars.js"
    click DocsUI "https://github.com/hyochan/react-native-iap/tree/main/docs/src/"

    click CI_CI "https://github.com/hyochan/react-native-iap/blob/main/.github/workflows/ci.yml"
    click CI_Android "https://github.com/hyochan/react-native-iap/blob/main/.github/workflows/ci-example-android.yml"
    click CI_iOS "https://github.com/hyochan/react-native-iap/blob/main/.github/workflows/ci-example-ios.yml"
    click CI_DeployDocs "https://github.com/hyochan/react-native-iap/blob/main/.github/workflows/deploy-documentation.yml"
    click CI_PublishPkg "https://github.com/hyochan/react-native-iap/blob/main/.github/workflows/publish-package.yml"
    click ReleaseScript "https://github.com/hyochan/react-native-iap/blob/main/release-it.js"
    click Bootstrap "https://github.com/hyochan/react-native-iap/blob/main/scripts/bootstrap.js"

    %% Styles
    classDef blue fill:#D0E7FF,stroke:#0274BC,color:#022B3A
    classDef green fill:#D7F0D4,stroke:#2E7D32,color:#1B5E20
    classDef orange fill:#FFE0B2,stroke:#FB8C00,color:#E65100
    classDef purple fill:#E1BEE7,stroke:#8E24AA,color:#4A148C
    classDef gray fill:#F5F5F5,stroke:#9E9E9E,color:#424242
```
