# pichillilorenzo/flutter_inappwebview architecture

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

- Interactive diagram: https://gitdiagram.com/pichillilorenzo/flutter_inappwebview
- Repository: https://github.com/pichillilorenzo/flutter_inappwebview

## Overview

##### Project’s Role
- It is not a traditional frontend/backend app but a **federated plugin library**.
- It exposes a **Dart API** (flutter_inappwebview) that Flutter apps consume.
- It comprises a **Platform Interface** package plus multiple **platform‐specific implementations**.
- It also houses an **example app**, **dev code‐generation packages**, and **test infrastructure**.

##### Spotlight the Major Components
1. **Example Flutter App**
– Located under flutter_inappwebview/example.
– Demonstrates usage of the Dart API.
2. **Core Dart Wrapper (flutter_inappwebview)**
– Exposes classes like InAppWebView, InAppBrowser, CookieManager, etc.
– Depends on the Platform Interface.
3. **Platform Interface (flutter_inappwebview_platform_interface)**
– Defines abstract contracts, data types, channel names.
– Shared dependency of all platform implementations.
4. **Platform Implementations**
– Android (flutter_inappwebview_android) → Java/Kotlin classes using Android WebView & Chrome Custom Tabs.
– iOS (flutter_inappwebview_ios) → Swift/Obj-C with WKWebView, SafariViewController.
– macOS (flutter_inappwebview_macos) → Swift with WKWebView.
– Windows (flutter_inappwebview_windows) → C++/WinRT wrapping WebView2.
– Web (flutter_inappwebview_web) → Dart + JavaScript bridge for browser environment.
5. **Native WebView Engines & OS Services**
– Android WebView, WKWebView on Apple platforms, Edge WebView2 on Windows, DOM Web APIs in browser.
6. **Dev Packages**
– flutter_inappwebview_internal_annotations (defines annotations).
– generators (build_runner builders that generate the g.dart files).
7. **Test & CI Infrastructure**
– test_node_server (HTTPS server for integration tests).
– scripts folder (publish.sh, test.sh, CI workflows).

##### Interactions & Data Flow
- **Flutter App** → calls → **Core Dart Wrapper**
- **Core Dart Wrapper** → delegates via → **Platform Interface (MethodChannel)**
- **Platform Interface** → invokes → **Platform Implementation**
- **Platform Implementation** → calls native WebView APIs → performs web actions
- **Native WebView** → sends events back → **Platform Implementation** → method channel → **Core Dart Wrapper** → **App**
- **Dev Packages** (build time) annotate and generate code in Dart packages.
- **Test Server** (external) provides assets and secure endpoints for integration tests.

##### Architectural Patterns
- **Federated Plugin Pattern** – separates interface from implementations.
- **Platform Channels** – MethodChannel/BasicMessageChannel bridging Dart ↔ native.
- **Code Generation** – build_runner + custom builders generate serialization code (G-files).
- **Monorepo Structure** – root organizes multiple pub packages in a single repository.

##### Putting It All Together
- **Layer 1 (App Layer)**
– Example Flutter App
- **Layer 2 (Plugin API Layer)**
– flutter_inappwebview (Dart)
- **Layer 3 (Interface Layer)**
– flutter_inappwebview_platform_interface
- **Layer 4 (Implementation Layer)**
– flutter_inappwebview_android → Android WebView
– flutter_inappwebview_ios → WKWebView/SafariViewController
– flutter_inappwebview_macos → WKWebView
– flutter_inappwebview_windows → WebView2
– flutter_inappwebview_web → DOM/JS Bridge
- **Layer 5 (Native Engines & OS)**
– Underlying WebView components on each platform
- **Side Components**
– Dev Packages (annotations, generators)
– Test Server & CI scripts

##### Final Touches
- Number or group related components.
- Federated pattern: separate interface vs implementations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Layer 1: App Layer"
        Example["Example Flutter App"]:::dart
    end

    subgraph "Layer 2: Plugin API Layer"
        Core["flutter_inappwebview (Dart)"]:::dart
    end

    subgraph "Layer 3: Interface Layer"
        Interface["flutter_inappwebview_platform_interface (Dart)"]:::interface
    end

    subgraph "Layer 4: Implementation Layer"
        Android["flutter_inappwebview_android (Java/Kotlin)"]:::impl
        iOS["flutter_inappwebview_ios (Swift/Obj-C)"]:::impl
        macOS["flutter_inappwebview_macos (Swift)"]:::impl
        Windows["flutter_inappwebview_windows (C++/WinRT)"]:::impl
        Web["flutter_inappwebview_web (Dart/JS)"]:::impl
    end

    subgraph "Layer 5: Native Engines"
        AndroidWeb["Android WebView"]:::native
        iOSEngine["WKWebView / SafariViewController"]:::native
        macOSEngine["macOS WKWebView"]:::native
        WinEngine["Edge WebView2"]:::native
        WebEngine["DOM / JS APIs"]:::native
    end

    Example -->|"calls"| Core
    Core -->|"MethodChannel"| Interface
    Interface -->|"invokes"| Android
    Interface -->|"invokes"| iOS
    Interface -->|"invokes"| macOS
    Interface -->|"invokes"| Windows
    Interface -->|"invokes"| Web

    Android -->|"uses"| AndroidWeb
    iOS -->|"uses"| iOSEngine
    macOS -->|"uses"| macOSEngine
    Windows -->|"uses"| WinEngine
    Web -->|"uses"| WebEngine

    AndroidWeb -->|"events"| Android
    iOSEngine -->|"events"| iOS
    macOSEngine -->|"events"| macOS
    WinEngine -->|"events"| Windows
    WebEngine -->|"events"| Web

    Android -->|"results via channel"| Core
    iOS -->|"results via channel"| Core
    macOS -->|"results via channel"| Core
    Windows -->|"results via channel"| Core
    Web -->|"results via channel"| Core

    Core -->|"returns"| Example

    subgraph "Dev & CI Tools"
        Annotations["flutter_inappwebview_internal_annotations"]:::dev
        Generators["generators"]:::dev
        TestServer["test_node_server (HTTPS Server)"]:::test
        Scripts["CI & Scripts"]:::test
    end

    Annotations -.->|"annotations"| Core
    Annotations -.->|"annotations"| Interface
    Generators -.->|"generates code"| Core
    Generators -.->|"generates code"| Interface

    classDef dart fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1
    classDef interface fill:#FFF9C4,stroke:#FDD835,color:#F9A825
    classDef impl fill:#FFE0B2,stroke:#FB8C00,color:#E65100
    classDef native fill:#C8E6C9,stroke:#43A047,color:#1B5E20
    classDef dev fill:#E0E0E0,stroke:#9E9E9E,color:#424242
    classDef test fill:#E1BEE7,stroke:#8E24AA,color:#4A148C

    click Example "https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview/example"
    click Core "https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview/lib"
    click Interface "https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_platform_interface/lib"
    click Android "https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_android/lib"
    click iOS "https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_ios/lib"
    click macOS "https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_macos/lib"
    click Windows "https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_windows/lib"
    click Web "https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_web/lib"
    click Annotations "https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/dev_packages/flutter_inappwebview_internal_annotations/lib"
    click Generators "https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/dev_packages/generators/lib"
    click TestServer "https://github.com/pichillilorenzo/flutter_inappwebview/blob/master/test_node_server/index.js"
    click Scripts "https://github.com/pichillilorenzo/flutter_inappwebview/blob/master/scripts/publish.sh"
```
