# auth0/auth0-flutter architecture

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

- Interactive diagram: https://gitdiagram.com/auth0/auth0-flutter
- Repository: https://github.com/auth0/auth0-flutter

## Overview

##### Project type and purpose
- This is a Flutter plugin SDK (“auth0_flutter”) and its shared platform interface (“auth0_flutter_platform_interface”).
- Purpose: Expose Auth0 authentication & authorization functionality to Flutter apps on Android, iOS, macOS/Darwin, web, Linux, Windows.

##### File structure
- Top-level packages:
- auth0_flutter/      → Dart API surface & platform‐specific implementations
- auth0_flutter_platform_interface/ → Abstract interfaces & shared data models
- appium-test/, scripts/, .github/, example apps & CI config
- auth0_flutter/lib/src:
- mobile/         → Dart wrappers over MethodChannel calls
- web/            → JS interop implementations & stubs
- Native directories under auth0_flutter/:
- android/        → Kotlin plugin code, MethodCall handlers, API request handlers, CredentialsManager handlers
- ios/, darwin/, macos/ → ObjC/Swift plugin code, method handlers for AuthAPI, CredentialsManager, WebAuth
- Example directory (auth0_flutter/example/) shows a consuming Flutter app with Android, iOS, Linux, macOS, web, Windows targets.
- Platform interface defines the contract; auth0_flutter implements it via MethodChannel or JS proxy.

##### README for insights
- Describes two packages: the public SDK and its platform interface.
- Targets: Android, iOS, macOS, web Flutter apps.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    A["Flutter Application"]:::dart
    click A "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/example/lib/main.dart"

    %% Dart SDK Layer
    subgraph "Dart SDK (auth0_flutter)" 
        direction TB
        B["Auth0FlutterApi"]:::dart
        click B "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/auth0_flutter.dart"
        C["Auth0FlutterWebEntry"]:::dart
        click C "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/auth0_flutter_web.dart"
        subgraph "Mobile Wrappers" 
            direction TB
            M1["AuthenticationApi (mobile)"]:::dart
            click M1 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/mobile/authentication_api.dart"
            M2["CredentialsManager (mobile)"]:::dart
            click M2 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/mobile/credentials_manager.dart"
            M3["WebAuthentication (mobile)"]:::dart
            click M3 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/mobile/web_authentication.dart"
        end
        subgraph "Web JS-Interop" 
            direction TB
            W1["PluginReal"]:::web
            click W1 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/web/auth0_flutter_plugin_real.dart"
            W2["PluginStub"]:::web
            click W2 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/web/auth0_flutter_plugin_stub.dart"
            W3["WebPlatformProxy"]:::web
            click W3 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/web/auth0_flutter_web_platform_proxy.dart"
            J1["js_interop.dart"]:::web
            click J1 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/web/js_interop.dart"
            J2["js_interop_utils.dart"]:::web
            click J2 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/web/js_interop_utils.dart"
            J3["jwt_decode.dart"]:::web
            click J3 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/web/jwt_decode.dart"
            J4["jwt_decode_exception.dart"]:::web
            click J4 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/web/jwt_decode_exception.dart"
            subgraph "extensions" 
                direction TB
                E1["web extensions"]:::web
                click E1 "https://github.com/auth0/auth0-flutter/tree/main/auth0_flutter/lib/src/web/extensions/"
            end
        end
    end

    %% Platform Interface Layer
    subgraph "Platform Interface (auth0_flutter_platform_interface)" 
        direction TB
        P0["Auth0FlutterPlatformInterface"]:::interface
        click P0 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter_platform_interface/lib/auth0_flutter_platform_interface.dart"
        P1["AuthPlatform"]:::interface
        click P1 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter_platform_interface/lib/src/auth0_flutter_auth_platform.dart"
        P2["WebAuthPlatform"]:::interface
        click P2 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter_platform_interface/lib/src/auth0_flutter_web_auth_platform.dart"
        P3["WebPlatform"]:::interface
        click P3 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter_platform_interface/lib/src/auth0_flutter_web_platform.dart"
        P4["CredentialsManagerPlatform"]:::interface
        click P4 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter_platform_interface/lib/src/credentials-manager/credentials_manager_platform.dart"
        P5["MethodChannelCredentialsManager"]:::interface
        click P5 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter_platform_interface/lib/src/credentials-manager/method_channel_credentials_manager.dart"
    end

    %% MethodChannel Implementations
    subgraph "MethodChannel Implementations" 
        direction TB
        MC1["MethodChannel Auth"]:::interface
        click MC1 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter_platform_interface/lib/src/method_channel_auth0_flutter_auth.dart"
        MC2["MethodChannel WebAuth"]:::interface
        click MC2 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter_platform_interface/lib/src/method_channel_auth0_flutter_web_auth.dart"
    end

    %% Native Implementations
    subgraph "Native Implementations" 
        direction TB
        subgraph "Android Plugin" 
            direction TB
            AN1["Auth0FlutterPlugin.kt"]:::native
            click AN1 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/android/src/main/kotlin/com/auth0/auth0_flutter/Auth0FlutterPlugin.kt"
            AN2["AuthMethodCallHandler.kt"]:::native
            click AN2 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/android/src/main/kotlin/com/auth0/auth0_flutter/Auth0FlutterAuthMethodCallHandler.kt"
            AN3["CredentialsManagerHandler.kt"]:::native
            click AN3 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/android/src/main/kotlin/com/auth0/auth0_flutter/CredentialsManagerMethodCallHandler.kt"
            AN4["WebAuthHandler.kt"]:::native
            click AN4 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/android/src/main/kotlin/com/auth0/auth0_flutter/Auth0FlutterWebAuthMethodCallHandler.kt"
            subgraph "API Handlers" 
                direction TB
                AAPI["/request_handlers/api/"]:::native
                click AAPI "https://github.com/auth0/auth0-flutter/tree/main/auth0_flutter/android/src/main/kotlin/com/auth0/auth0_flutter/request_handlers/api/"
            end
            subgraph "Credential Handlers" 
                direction TB
                ACM["/request_handlers/credentials_manager/"]:::native
                click ACM "https://github.com/auth0/auth0-flutter/tree/main/auth0_flutter/android/src/main/kotlin/com/auth0/auth0_flutter/request_handlers/credentials_manager/"
            end
            subgraph "WebAuth Handlers" 
                direction TB
                AW["/request_handlers/web_auth/"]:::native
                click AW "https://github.com/auth0/auth0-flutter/tree/main/auth0_flutter/android/src/main/kotlin/com/auth0/auth0_flutter/request_handlers/web_auth/"
            end
        end
        subgraph "iOS/macOS/Darwin Plugin" 
            direction TB
            IOS1["SwiftAuth0FlutterPlugin.swift"]:::native
            click IOS1 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/ios/Classes/SwiftAuth0FlutterPlugin.swift"
            MAC1["SwiftAuth0FlutterPlugin.swift (macOS)"]:::native
            click MAC1 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/macos/Classes/SwiftAuth0FlutterPlugin.swift"
            DAR1["SwiftAuth0FlutterPlugin.swift (Darwin)"]:::native
            click DAR1 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/darwin/Classes/SwiftAuth0FlutterPlugin.swift"
        end
    end

    %% Storage
    subgraph "Credentials Storage" 
        direction TB
        S1["Android SharedPreferences"]:::storage
        S2["iOS/macOS Keychain"]:::storage
        S3["Web localStorage"]:::storage
        click S3 "https://github.com/auth0/auth0-flutter/blob/main/auth0_flutter/lib/src/web/extensions/credentials_extension.dart"
    end

    %% External Service
    Auth0["Auth0 Service (Auth API)"]:::external

    %% Connections
    A -->|"calls"| B
    A -->|"calls"| C
    B -->|"forwards to"| P0
    C -->|"forwards to"| W1
    P0 -->|"dispatches via"| MC1
    P0 -->|"dispatches via"| MC2
    MC1 -->|"invokes"| AN1
    MC1 -->|"invokes"| AN2
    MC1 -->|"invokes"| AN3
    MC1 -->|"invokes"| AN4
    MC2 -->|"invokes"| IOS1
    MC2 -->|"invokes"| MAC1
    MC2 -->|"invokes"| DAR1
    MC1 -->|"invokes"| AAPI
    MC1 -->|"invokes"| ACM
    MC1 -->|"invokes"| AW
    AN2 -->|"HTTP"| Auth0
    AN4 -->|"HTTP"| Auth0
    IOS1 -->|"HTTP"| Auth0
    MAC1 -->|"HTTP"| Auth0
    DAR1 -->|"HTTP"| Auth0
    ACM -->|"uses"| S1
    AN3 -->|"uses"| S1
    IOS1 -->|"uses"| S2
    MAC1 -->|"uses"| S2
    DAR1 -->|"uses"| S2
    W1 -->|"JS calls"| J1
    J1 -->|"builds HTTP"| Auth0
    W3 -->|"storage"| S3

    %% Styles
    classDef dart fill:#D0E6FF,stroke:#0366D6,color:#0366D6;
    classDef web fill:#FFE8A1,stroke:#D29922,color:#A45F09;
    classDef interface fill:#E5D3FF,stroke:#9B59B6,color:#6C3483;
    classDef native fill:#D5F5E3,stroke:#27AE60,color:#1E8449;
    classDef storage fill:#FCF3CF,stroke:#F1C40F,color:#B9770E;
    classDef external fill:#FADBD8,stroke:#E74C3C,color:#922B21;
```
