# abdullah-youssef/gdpr_admob architecture

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

- Interactive diagram: https://gitdiagram.com/abdullah-youssef/gdpr_admob
- Repository: https://github.com/abdullah-youssef/gdpr_admob

## Overview

##### Project Type and Purpose
- This is a Flutter “plugin” package named gdpr_admob. Its job is to present a GDPR consent form to EEA users and then initialize Google Mobile Ads in a Flutter app according to the user’s choice.
- The top‐level `lib/` folder contains the Dart API, and the `example/` folder holds a full multi‐platform Flutter application demonstrating usage on Android, iOS, Linux, macOS, Windows, and Web.

##### File Structure
- Top‐level: plugin config files (`pubspec.yaml`, `.gitignore`, `LICENSE`, etc.) plus `lib/`, `test/`, `example/`.
- `lib/gdpr_admob.dart` and `lib/src/gdpr_admob.dart`: Dart wrapper that exposes `GdprAdmob` class with methods like `initialize()`, `getConsentStatus()`, `resetConsentStatus()`.
- `example/`: a standard Flutter app scaffold, with platform directories under `android/`, `ios/`, `linux/`, `macos/`, `windows/`, `web/` linking in the plugin and demonstrating UI interactions.
- No custom native source in the plugin root—platform code is pulled in via MethodChannels to the Google Mobile Ads SDK / UMP libraries provided by each platform.

##### Main Components
a. Flutter Application (UI Layer)
- Widgets invoking `GdprAdmob.initialize()`, listening for results, showing dialogs or messages.
b. Plugin API Layer (Dart)
- `GdprAdmob` singleton class in `lib/`, exposing Futures and callbacks to the app.
c. Platform Channel Bridge
- One or more `MethodChannel` instances behind the scenes, routing Dart calls to native code on each platform.
d. Native Platform Modules
- Google’s User Messaging Platform (UMP)/Consent SDK + Google Mobile Ads SDK on Android, iOS, macOS, Windows, Linux.
e. External Services
- Google Consent Servers (for GDPR rules and form content)
- Google AdMob Ad Servers (for fetching and serving ads post‐consent)

##### Architectural Patterns and Design Principles
- Plugin Pattern: clean separation between Dart API and native implementations via MethodChannel.
- Singleton + Async Futures: `GdprAdmob` as a lazily‐initialized singleton exposing async methods.
- Cross‐platform layering: one Dart interface, multiple native backends.

##### Technologies, Frameworks, and Libraries
- Flutter (Dart)
- MethodChannel (Flutter plugin interop)
- Google Mobile Ads SDK (androidX, iOS CocoaPod, etc.)
- Google User Messaging Platform (Consent SDK)
- pub.dev plugin tooling (pubspec, example project)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Flutter Layers
    subgraph "Flutter UI Layer"
        FlutterUI["Flutter UI\n(example/lib/main.dart)"]:::front
    end

    subgraph "Plugin API Layer"
        PluginAPI["Dart Plugin API\nlib/gdpr_admob.dart"]:::front
    end

    %% Interop Layer
    MethodChannel["MethodChannel Bridge\nlib/src/gdpr_admob.dart"]:::interop

    %% Native Platform Modules
    NativeSDK["Native Platform Modules\n(UMP & AdMob SDKs)"]:::native

    %% Example App Demonstration
    subgraph "Example App (Demonstration)"
        AndroidRunner["Android MainActivity.kt"]:::native
        iOSRunner["iOS AppDelegate.swift"]:::native
        LinuxMain["Linux main.cc"]:::native
        LinuxReg["Linux GeneratedPluginRegistrant"]:::native
        MacOSApp["macOS AppDelegate.swift"]:::native
        MacOSReg["macOS GeneratedPluginRegistrant.swift"]:::native
        WindowsMain["Windows main.cpp"]:::native
        WindowsWin["Windows flutter_window.cpp/h"]:::native
        WebIndex["Web index.html"]:::native
    end

    %% External Services
    ExternalConsent["Google Consent Servers"]:::external
    ExternalAd["Google AdMob Servers"]:::external

    %% Data Flow
    FlutterUI -->|"initialize()/showConsentDialog"| PluginAPI
    PluginAPI -->|"invoke initialize via MethodChannel"| MethodChannel
    MethodChannel -->|"fetchConsentForm() via UMP"| NativeSDK
    NativeSDK -->|"fetch form config"| ExternalConsent
    NativeSDK -->|"display consent form"| FlutterUI
    NativeSDK -->|"return ConsentStatus"| PluginAPI
    PluginAPI -->|"AdMob.initialize()"| NativeSDK
    NativeSDK -->|"fetch ads"| ExternalAd
    NativeSDK -->|"return ad results"| PluginAPI
    PluginAPI -->|"return status/results"| FlutterUI

    %% Click Events
    click FlutterUI "https://github.com/abdullah-youssef/gdpr_admob/blob/main/example/lib/main.dart"
    click PluginAPI "https://github.com/abdullah-youssef/gdpr_admob/blob/main/lib/gdpr_admob.dart"
    click MethodChannel "https://github.com/abdullah-youssef/gdpr_admob/blob/main/lib/src/gdpr_admob.dart"
    click AndroidRunner "https://github.com/abdullah-youssef/gdpr_admob/blob/main/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt"
    click iOSRunner "https://github.com/abdullah-youssef/gdpr_admob/blob/main/example/ios/Runner/AppDelegate.swift"
    click LinuxMain "https://github.com/abdullah-youssef/gdpr_admob/blob/main/example/linux/main.cc"
    click LinuxReg "https://github.com/abdullah-youssef/gdpr_admob/blob/main/example/linux/flutter/generated_plugin_registrant.cc"
    click MacOSApp "https://github.com/abdullah-youssef/gdpr_admob/blob/main/example/macos/Runner/AppDelegate.swift"
    click MacOSReg "https://github.com/abdullah-youssef/gdpr_admob/blob/main/example/macos/Flutter/GeneratedPluginRegistrant.swift"
    click WindowsMain "https://github.com/abdullah-youssef/gdpr_admob/blob/main/example/windows/runner/main.cpp"
    click WindowsWin "https://github.com/abdullah-youssef/gdpr_admob/blob/main/example/windows/runner/flutter_window.cpp"
    click WebIndex "https://github.com/abdullah-youssef/gdpr_admob/blob/main/example/web/index.html"

    %% Styles
    classDef front fill:#add8e6,stroke:#000
    classDef interop fill:#90ee90,stroke:#000
    classDef native fill:#ffa500,stroke:#000
    classDef external fill:#d3d3d3,stroke:#000
```
