# doug821/react-native-squircle architecture

> Architecture diagram of the GitHub repository doug821/react-native-squircle, 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/doug821/react-native-squircle
- Repository: https://github.com/doug821/react-native-squircle

## Overview

##### Project’s type and purpose
- This is a React Native UI library (“react-native-squircle-layout”) that provides a customizable “SquircleView” component.
- It consists of three logical layers:
- JavaScript/TypeScript wrapper (in src/)
- Native Android implementation (in android/)
- Native iOS implementation (in ios/)
- There is also an example/demo app (in example/) demonstrating usage on both platforms.

##### File‐structure and infer architectural choices
- Top-level directories:
- src/ – cross-platform JS/TS code, React component, hooks, types, tests.
- android/ – Android native code (ViewManager, View), two flavors: old architecture (legacy bridge) and new architecture (TurboModules/JSI spec).
- ios/ – iOS native code (Objective-C++/MM ViewManager, View).
- example/ – a full React Native app scaffold (android/, ios/, src/App.tsx) to test the library.
- Config & build:
- package.json, tsconfig.json, babel.config.js for building/publishing.
- react-native-squircle.podspec to integrate with CocoaPods.
- Yarn v3 workspace (.yarn/, turbo.json) to manage monorepo.

##### README insights
- It mentions it was generated with create-react-native-library (builder-bob), which imposes a standard RN native module pattern.

a. Main components
1. JS Layer
– SquircleView React component (src/components/SquircleView)
– Hook (useElementSize) for dynamic sizing
– Type definitions (src/@types)
2. React Native Bridge
– JS → Native calls
– Property serialization, event callbacks
3. Native Modules
– Android
- SquircleViewManager.kt
- SquircleView.kt (draws squircle via Canvas/Drawable)
- Two packages: legacy bridge (android/src/oldarch) and new architecture spec (android/src/newarch)
– iOS
- RCTSquircleViewManager.mm
- SquircleView.mm (CAShapeLayer or CoreGraphics)
4. Build/Test/Example
– Example app demonstrating integration
– Unit tests (src/__tests__)
– CI workflows (GitHub Actions)

b. Relationships & data flow
– The React component (JS) instantiates a native view via the bridge.
– The example app sits atop the published package, consuming the JS entry point (index.tsx) and linking native modules via Gradle/CocoaPods.

c. Architectural patterns & principles
– Layered architecture: clear separation between JS UI API, bridge, and platform-specific rendering.
– Bridge pattern in React Native: decoupling JS and native.
– Monorepo/workspace structure for co-development of JS, Android, iOS.
– Example-driven development: isolated “example” project to validate pipelines and manual QA.

d. Key technologies & frameworks
– React Native (JS bridge)
– TypeScript for type safety
– Android: Kotlin/Java, AndroidX, Canvas
– iOS: Objective-C++ (.mm), CoreGraphics/CALayer
– Yarn v3 workspaces, TurboRepo (turbo.json)
– CocoaPods for iOS integration
– Gradle for Android builds
– GitHub Actions for CI

##### Essential details to capture
- The dual-architecture approach on Android (legacy vs new).
- The podspec and Gradle plugin that handle native linking.
- The monorepo build flow: yarn build → ts-compile → native code compile.
- The test harness: unit tests in src/__tests__, CI → example app build/test.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Swimlanes / Layers
    subgraph "Example App" 
        direction TB
        EA_App["App.tsx"]:::example
        EA_AndroidMain["MainActivity.kt"]:::example
        EA_iOSDelegate["AppDelegate.mm"]:::example
    end

    subgraph "JS Layer" 
        direction TB
        JS_Index["index.tsx"]:::js
        JS_SquircleComp["SquircleView (JS Component)"]:::js
        JS_HostBinding["SquircleViewNativeComponent"]:::js
        JS_Hook["useElementSize Hook"]:::js
        JS_Types["squircle.d.ts"]:::js
        JS_Tests["index.test.tsx"]:::js
    end

    subgraph "React Native Bridge" 
        direction TB
        Bridge["Bridge (Serialization & Calls)"]:::bridge
    end

    subgraph "Android Native Module" 
        direction TB
        AND_Package["SquirclePackage.kt"]:::android
        AND_VM_Legacy["SquircleViewManager.kt"]:::android
        AND_View["SquircleView.kt"]:::android
        AND_Spec_Old["OldArch Spec Stub"]:::android
        AND_Spec_New["NewArch Spec Stub"]:::android
    end

    subgraph "iOS Native Module" 
        direction TB
        IOS_VM["SquircleViewManager.mm"]:::ios
        IOS_View["SquircleView.mm"]:::ios
        IOS_Header["SquircleView.h"]:::ios
    end

    subgraph "Linking & Config" 
        direction TB
        Podspec["react-native-squircle.podspec"]:::config
        Gradle["Gradle/CocoaPods Linking"]:::config
    end

    subgraph "Rendering Layer" 
        direction TB
        Render_Android["Android Canvas Rendering"]:::render
        Render_iOS["CoreGraphics/CALayer Rendering"]:::render
    end

    %% Connections
    EA_App -->|"imports from"| JS_Index
    EA_AndroidMain -->|"launches example"| EA_App
    EA_iOSDelegate -->|"launches example"| EA_App

    JS_Index -->|"exports component"| JS_SquircleComp
    JS_SquircleComp -->|"uses hook"| JS_Hook
    JS_Index -->|"provides binding"| JS_HostBinding
    JS_Index -->|"types from"| JS_Types
    JS_Index -->|"tested by"| JS_Tests

    JS_HostBinding -->|"invokes"| Bridge
    JS_SquircleComp -->|"renders via"| JS_HostBinding

    Bridge -->|"package registration"| AND_Package
    Bridge -->|"calls view manager"| AND_VM_Legacy
    Bridge -->|"calls view manager"| AND_Spec_Old
    Bridge -->|"calls view manager"| AND_Spec_New
    Bridge -->|"calls view manager"| IOS_VM

    AND_VM_Legacy -->|"creates instance"| AND_View
    AND_Spec_Old -->|"implements stub"| AND_View
    AND_Spec_New -->|"implements stub"| AND_View
    IOS_VM -->|"creates instance"| IOS_View

    AND_View -->|"draws shape"| Render_Android
    IOS_View -->|"draws shape"| Render_iOS

    AND_Package -->|"registers modules"| Gradle
    Podspec -->|"integrates via CocoaPods"| Gradle

    %% Styles and click events
    classDef js fill:#cce5ff,stroke:#2f6f9f;
    classDef android fill:#d4edda,stroke:#256029;
    classDef ios fill:#d4edda,stroke:#256029;
    classDef bridge fill:#e2e3e5,stroke:#6c757d;
    classDef example fill:#fff3cd,stroke:#856404;
    classDef config fill:#f8d7da,stroke:#721c24;
    classDef render fill:#fde2b2,stroke:#b07200;

    click EA_App "https://github.com/doug821/react-native-squircle/blob/main/example/src/App.tsx"
    click EA_AndroidMain "https://github.com/doug821/react-native-squircle/blob/main/example/android/app/src/main/java/com/squircleexample/MainActivity.kt"
    click EA_iOSDelegate "https://github.com/doug821/react-native-squircle/blob/main/example/ios/SquircleExample/AppDelegate.mm"
    click JS_Index "https://github.com/doug821/react-native-squircle/blob/main/src/index.tsx"
    click JS_SquircleComp "https://github.com/doug821/react-native-squircle/blob/main/src/components/SquircleView/index.tsx"
    click JS_HostBinding "https://github.com/doug821/react-native-squircle/blob/main/src/SquircleViewNativeComponent.ts"
    click JS_Hook "https://github.com/doug821/react-native-squircle/blob/main/src/hooks/useElementSize.ts"
    click JS_Types "https://github.com/doug821/react-native-squircle/blob/main/src/@types/squircle.d.ts"
    click JS_Tests "https://github.com/doug821/react-native-squircle/blob/main/src/__tests__/index.test.tsx"
    click AND_Package "https://github.com/doug821/react-native-squircle/blob/main/android/src/main/java/com/squircle/SquirclePackage.kt"
    click AND_VM_Legacy "https://github.com/doug821/react-native-squircle/blob/main/android/src/main/java/com/squircle/SquircleViewManager.kt"
    click AND_View "https://github.com/doug821/react-native-squircle/blob/main/android/src/main/java/com/squircle/SquircleView.kt"
    click AND_Spec_Old "https://github.com/doug821/react-native-squircle/blob/main/android/src/oldarch/SquircleViewManagerSpec.kt"
    click AND_Spec_New "https://github.com/doug821/react-native-squircle/blob/main/android/src/newarch/SquircleViewManagerSpec.kt"
    click IOS_VM "https://github.com/doug821/react-native-squircle/blob/main/ios/SquircleViewManager.mm"
    click IOS_View "https://github.com/doug821/react-native-squircle/blob/main/ios/SquircleView.mm"
    click IOS_Header "https://github.com/doug821/react-native-squircle/blob/main/ios/SquircleView.h"
    click Podspec "https://github.com/doug821/react-native-squircle/blob/main/react-native-squircle.podspec"
```
