# kevinnzou/compose-webview-multiplatform architecture

> Architecture diagram of the GitHub repository kevinnzou/compose-webview-multiplatform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kevinnzou/compose-webview-multiplatform
- Repository: https://github.com/kevinnzou/compose-webview-multiplatform

## Overview

##### Project's Main Components
- Library Core (Common Module): This includes the shared logic for WebView state management (WebViewState), navigation (WebViewNavigator), JavaScript bridge (WebViewJsBridge), request interception (RequestInterceptor), and web settings (WebSettings).
- Platform-specific Implementations:
- Android: Utilizes a forked version of the Accompanist WebView and custom Android integrations in webview/src/androidMain.
- iOS: Uses WKWebView from Apple, with its code under webview/src/iosMain.
- Desktop: Initially had a JavaFX WebView implementation; later versions use Java CEF Browser / Kotlin CEF Browser with desktop-specific code under webview/src/desktopMain.
- Sample/Example Apps: These directories (sample/androidApp, sample/iosApp, sample/desktopApp) show how to integrate the library into real applications.
- Documentation and Build Tools: Tools like Gradle scripts, CI workflows, and documentation in docs/ and mkdocs.yml support the development and publishing process.

- Integration of external libraries:
- Android’s integration with the forked Accompanist WebView library.
- iOS’s connection to WKWebView.
- Desktop’s connectivity with Java CEF Browser (or Kotlin CEF Browser).
- How the state management (WebViewState) and navigator (WebViewNavigator) interact with the UI layer in Compose, and also how the JavaScript bridge enables bidirectional communication between the WebView content and native code.

##### Architectural Patterns & Design Principles
- Multiplatform Abstraction: Detail how common interfaces and implementations are shared across platforms, while delegating platform-specific logic to their respective source sets.
- Compose UI Integration: Emphasize that the composable functions provide a declarative approach to constructing the UI, which internally relies on native WebView implementations.
- Extensibility: Show the customizable nature of settings (via WebSettings) and interception (via RequestInterceptor), which are designed to allow consumers to alter behavior without modifying core logic.
- Separation of Concerns: The library neatly separates UI (composables), state management, navigation, native integrations, and utility functionality.

##### Final Checklist
- Every component (common module, Android, iOS, Desktop, external dependencies, and sample apps) is represented.
- Annotations where appropriate (for example, note version changes such as “From JavaFX to CEF on Desktop”).
- Be as detailed as possible to reflect each architectural element—from user input in the Compose UI to native WebView rendering and back to state updates.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Shared Layer
    subgraph "Shared Library (Common Module)"
        Core["Library Core (Shared WebView API & State Management)"]:::shared
        Composable["Compose UI Integration (rememberWebViewState, rememberWebViewNavigator, rememberWebViewJsBridge)"]:::shared
    end

    %% Platform Specific Implementations
    subgraph "Platform Implementations"
        Android["Android Module (Accompanist-based WebView Implementation)"]:::android
        iOS["iOS Module (WKWebView Integration)"]:::ios
        Desktop["Desktop Module (CEF Browser/Kotlin CEF Browser Implementation)"]:::desktop
    end

    %% External Libraries for each platform
    subgraph "External Dependencies"
        Accompanist["Accompanist WebView Library"]:::external
        WKWebView["WKWebView (Apple)"]:::external
        CEF["Java/Kotlin CEF Browser"]:::external
    end

    %% Sample Apps
    subgraph "Sample Applications"
        AndroidSample["Android Sample App"]:::sample
        iOSSample["iOS Sample App"]:::sample
        DesktopSample["Desktop Sample App"]:::sample
    end

    %% Documentation & Build Tools
    Doc["Documentation & Build Tools"]:::doc

    %% Interactions from Shared Layer to Platform Modules
    Core -->|"delegates_to"| Android
    Core -->|"delegates_to"| iOS
    Core -->|"delegates_to"| Desktop

    Composable -->|"invokes_native"| Android
    Composable -->|"invokes_native"| iOS
    Composable -->|"invokes_native"| Desktop

    %% Platform Modules interacting with External Libraries
    Android -->|"integrates"| Accompanist
    iOS -->|"integrates"| WKWebView
    Desktop -->|"integrates"| CEF

    %% Sample Apps consuming the Library
    AndroidSample -->|"consumes"| Core
    iOSSample -->|"consumes"| Core
    DesktopSample -->|"consumes"| Core

    %% Supporting Documentation and Build Tools
    Core ---|"supported_by"| Doc
    Android ---|"supported_by"| Doc
    iOS ---|"supported_by"| Doc
    Desktop ---|"supported_by"| Doc

    %% Click Events
    click Core "https://github.com/kevinnzou/compose-webview-multiplatform/tree/main/webview/src/commonMain/kotlin/com/multiplatform/webview"
    click Android "https://github.com/kevinnzou/compose-webview-multiplatform/tree/main/webview/src/androidMain/kotlin/com/multiplatform/webview"
    click iOS "https://github.com/kevinnzou/compose-webview-multiplatform/tree/main/webview/src/iosMain/kotlin/com/multiplatform/webview"
    click Desktop "https://github.com/kevinnzou/compose-webview-multiplatform/tree/main/webview/src/desktopMain/kotlin/com/multiplatform/webview"
    click AndroidSample "https://github.com/kevinnzou/compose-webview-multiplatform/tree/main/sample/androidApp"
    click iOSSample "https://github.com/kevinnzou/compose-webview-multiplatform/tree/main/sample/iosApp"
    click DesktopSample "https://github.com/kevinnzou/compose-webview-multiplatform/tree/main/sample/desktopApp"
    click Doc "https://github.com/kevinnzou/compose-webview-multiplatform/tree/main/docs"

    %% Styles
    classDef shared fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef android fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef ios fill:#FFDAB9,stroke:#000,stroke-width:2px;
    classDef desktop fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef sample fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef doc fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
