# clevertap/clevertap-flutter architecture

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

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

## Overview

##### Main Components

a) Client-Side Components:
- Flutter Application Layer
- Platform-Specific Implementations (Android/iOS/Web)
- Background Processing Components
- Event Handling System

b) Integration Components:
- CleverTap Core Services Connection
- Push Notification System
- Analytics Pipeline
- Template Management System

**Top Level (Flutter Application Layer):**
- Flutter Plugin Interface
- clevertap_plugin.dart (Main Plugin Entry)

**Middle Level (Platform Channels):**
- Platform-Specific Implementations
- Android Implementation
- iOS Implementation
- Web Implementation

**Bottom Level (Native Services):**
- CleverTap Core Services
- Analytics
- Push Notifications
- User Engagement Features

##### Key Elements to Highlight

a) Communication Flows:
- Event flow from app to CleverTap services
- Background processing paths

- Rectangle: Core components
- Rounded Rectangle: Platform-specific implementations
- Hexagon: External services
- Circle: Event handlers

##### Specific Implementation Details

For Android:
- CleverTapPlugin.java as the main entry point
- CleverTapEventEmitter for event handling
- Background isolate executor system

For iOS:
- CleverTapPlugin.m as the main bridge
- Template presenter system
- Custom template handling

For Web:
- Web-specific implementation through clevertap_plugin_web.dart

##### Important Relationships

- Event flow from Flutter to native platforms
- Background processing system
- Push notification handling
- Template management system
- Analytics data flow

##### Additional Elements

- Different component types
- Background processing paths
- Integration points with CleverTap services

##### Technical Details to Note

- Platform channel communication
- Event handling system
- Background processing capability
- Push notification integration
- Custom template support
- Analytics tracking flow

This structure will provide a clear understanding of how the plugin bridges Flutter applications with CleverTap's services across different platforms while maintaining a clean architectural separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef flutter fill:#3498db,stroke:#2980b9,color:white
    classDef android fill:#2ecc71,stroke:#27ae60,color:white
    classDef ios fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef web fill:#e67e22,stroke:#d35400,color:white
    classDef service fill:#9b59b6,stroke:#8e44ad,color:white
    classDef event fill:#f1c40f,stroke:#f39c12,color:black
    classDef background fill:#1abc9c,stroke:#16a085,color:white
    classDef template fill:#e74c3c,stroke:#c0392b,color:white

    %% Main Flutter Layer
    subgraph FlutterLayer
        FPI["Flutter Plugin Interface"]:::flutter
        WB["Web Binding"]:::flutter
        CBD["Callback Dispatcher"]:::flutter
    end
    click FPI "https://github.com/CleverTap/clevertap-flutter/blob/master/lib/clevertap_plugin.dart"
    click WB "https://github.com/CleverTap/clevertap-flutter/blob/master/lib/src/clevertap_plugin_web_binding.dart"
    click CBD "https://github.com/CleverTap/clevertap-flutter/blob/master/lib/src/clevertap_callback_dispatcher.dart"

    %% Platform Implementations Layer
    subgraph PlatformLayer
        %% Android Implementation
        AP["Android Plugin"]:::android
        AEE["Event Emitter"]:::android
        AE["CleverTap Event"]:::android
        ENM["Event Name Mapper"]:::android
        DNC["Native Communicator"]:::android
        
        %% iOS Implementation
        IP["iOS Plugin"]:::ios
        
        %% Web Implementation
        WP["Web Plugin"]:::web
    end
    click AP "https://github.com/CleverTap/clevertap-flutter/blob/master/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java"
    click AEE "https://github.com/CleverTap/clevertap-flutter/blob/master/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapEventEmitter.kt"
    click AE "https://github.com/CleverTap/clevertap-flutter/blob/master/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapEvent.kt"
    click ENM "https://github.com/CleverTap/clevertap-flutter/blob/master/android/src/main/java/com/clevertap/clevertap_plugin/EventNameMapper.kt"
    click DNC "https://github.com/CleverTap/clevertap-flutter/blob/master/android/src/main/java/com/clevertap/clevertap_plugin/DartToNativePlatformCommunicator.kt"
    click IP "https://github.com/CleverTap/clevertap-flutter/blob/master/ios/Classes/CleverTapPlugin.m"
    click WP "https://github.com/CleverTap/clevertap-flutter/blob/master/lib/clevertap_plugin_web.dart"

    %% Background Processing Layer
    subgraph BackgroundLayer
        BIE["Background Isolate Executor"]:::background
        BIR["Background Isolate Runner"]:::background
    end
    click BIE "https://github.com/CleverTap/clevertap-flutter/blob/master/android/src/main/java/com/clevertap/clevertap_plugin/isolate/CleverTapBackgroundIsolateExecutor.java"
    click BIR "https://github.com/CleverTap/clevertap-flutter/blob/master/android/src/main/java/com/clevertap/clevertap_plugin/isolate/CleverTapBackgroundIsolateRunner.java"

    %% Template Management Layer
    subgraph TemplateLayer
        TPH["Template Presenter Header"]:::template
        TPM["Template Presenter"]:::template
        CT["Custom Templates"]:::template
    end
    click TPH "https://github.com/CleverTap/clevertap-flutter/blob/master/ios/Classes/CleverTapPluginTemplatePresenter.h"
    click TPM "https://github.com/CleverTap/clevertap-flutter/blob/master/ios/Classes/CleverTapPluginTemplatePresenter.m"
    click CT "https://github.com/CleverTap/clevertap-flutter/blob/master/android/src/main/java/com/clevertap/clevertap_plugin/ClevertapCustomTemplates.kt"

    %% CleverTap Services Layer
    subgraph ServicesLayer
        CTS["CleverTap Core Services"]:::service
        AN["Analytics"]:::service
        PN["Push Notifications"]:::service
        UE["User Engagement"]:::service
    end

    %% Connections
    FPI --> AP & IP & WP
    FPI --> WB
    FPI --> CBD
    
    AP --> AEE
    AEE --> AE
    AE --> ENM
    AP --> DNC
    
    AP --> BIE
    BIE --> BIR
    
    IP --> TPH
    TPH --> TPM
    AP --> CT
    
    AP & IP & WP --> CTS
    CTS --> AN & PN & UE
```
