# anand-cureocity/anura_flutter architecture

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

- Interactive diagram: https://gitdiagram.com/anand-cureocity/anura_flutter
- Repository: https://github.com/anand-cureocity/anura_flutter

## Overview

##### Project type and purpose
- This is a Federated Flutter Plugin repository (“anura_flutter”) that provides a single Dart API surface, exposed to Flutter apps.
- Internally it uses the federated‐plugin pattern: a platform interface package plus separate Android and iOS implementation packages.
- There’s also an example Flutter application (under `anura_flutter/example`) used for integration tests.

##### File structure and README
- Top‐level packages:
– anura_flutter (main plugin + example)
– anura_flutter_platform_interface (defines the Dart interface and method‐channel contract)
– anura_flutter_android (Android implementation in Kotlin + bundled AARs)
– anura_flutter_ios (iOS implementation in Swift + xcframeworks)
- Example app under `anura_flutter/example` uses Fluttium for integration tests.
- CI workflows configured under `.github/workflows` to build/test all packages on Android, iOS, and web.

##### Main components
A. Flutter Application (Example)
– Dart UI code calls into `anura_flutter` plugin API.
B. Dart Plugin Package (`anura_flutter/lib`)
– Exposes `AnuraFlutter` class methods.
– Delegates calls to `anura_flutter_platform_interface`.
C. Platform Interface Package
– Defines abstract methods and `MethodChannelAnuraFlutter` default implementation.
– Ensures both Android and iOS implementations adhere to the same contract.
D. MethodChannel / Platform Channel
– The runtime bridge over which Dart and native code communicate.
E. Android Implementation Package
– Kotlin classes (e.g. `AnuraFlutterPlugin.kt`, `AnuraScannerActivity.kt`).
– Bundled native SDKs (`.aar` files: Anura Core SDK, OpenCV, DFX extras, DFX SDK).
– Uses Android View, camera, etc., to perform scanning, then returns results via platform channel.
F. iOS Implementation Package
– Swift classes (`AnuraFlutterPlugin.swift`, networking, measurement delegate).
– Bundled xcframeworks (AnuraCore, FaceMesh, libdfx).
– Uses AVFoundation/CoreML/MediaPipe under the hood, responds via MethodChannel.
G. Native SDK Frameworks
– On Android: AARs that encapsulate native C++/Java code.
– On iOS: xcframeworks containing Swift/C++/C code, models.
H. CI/CD workflows
– GitHub Actions build/test each package on multiple platforms (Android, iOS).
I. Integration Tests (Fluttium)
– YAML flows drive the example app to validate end-to-end plugin behavior.

##### Relationships and data flow
1. Flutter UI (Example) → calls Dart API in `anura_flutter` package
2. `anura_flutter` → calls platform interface API
3. Platform interface default → uses `MethodChannel` to invoke native method
4. MethodChannel → dispatches to Android or iOS host code
5. Native implementation → invokes underlying AnuraCore/FaceMesh/DFX SDK for scanning
6. SDK → returns measurement/scanned data back up to host implementation
7. Host implementation → returns data via MethodChannel result callback to Dart
8. Dart receives result → propagates back to Flutter UI
9. Integration Tests drive the Flutter UI and assert behaviors.

##### Architectural patterns and principles
- Federated plugin architecture: isolates platform interface from platform implementations.
- Clean separation of concerns: Dart code does not depend directly on platform SDKs.
- Single source of truth for API: only the platform interface defines method signatures.
- CI-as-documentation: GitHub Actions workflows show how builds/tests run.

##### Technologies and frameworks
- Dart & Flutter (UI + plugin layer)
- MethodChannel (Flutter platform channel)
- Kotlin + Android SDK + AAR artifacts
- Swift + iOS frameworks + AVFoundation / CoreML
- GitHub Actions (CI/CD)
- Fluttium (integration testing)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Example["Flutter Application (Example)"]:::frontend
    Example -->|"calls Dart API"| DartPlugin

    %% Dart Plugin Package
    subgraph "anura_flutter (Dart Plugin Package)"
        direction TB
        DartPluginMain["anura_flutter.dart"]:::frontend
        Model1["anura_scanned_data.dart"]:::frontend
        Model2["anura_user_model.dart"]:::frontend
    end
    DartPlugin -->|"delegates to"| PlatformInterface

    %% Platform Interface
    subgraph "anura_flutter_platform_interface"
        direction TB
        PI_Main["anura_flutter_platform_interface.dart"]:::interface
        MethodChannel["method_channel_anura_flutter.dart"]:::channel
    end
    PlatformInterface -->|"uses MethodChannel"| MethodChannel
    PI_Main --> MethodChannel

    %% Platform channel bridge
    MethodChannel -->|"invokes native code via Platform Channel"| AndroidImpl
    MethodChannel -->|"invokes native code via Platform Channel"| iOSImpl

    %% Platform Implementations
    subgraph "Platform Implementations"
        direction TB

        subgraph "Android Implementation Package" 
            direction TB
            AndroidStub["anura_flutter_android.dart"]:::android
            PluginKotlin1["AnuraFlutterPlugin.kt"]:::android
            PluginKotlin2["AnuraScannerActivity.kt"]:::android
            Utils["Constants.kt, SampleTokenStore.kt, SharedPreferencesHelper.kt"]:::android
            ViewModel["ExampleStartViewModel.kt"]:::android
            AndroidSDK[/"Android AAR Frameworks"/]:::cylinder
            AndroidStub --> PluginKotlin1
            PluginKotlin1 --> PluginKotlin2
            PluginKotlin1 --> Utils
            PluginKotlin1 --> ViewModel
            PluginKotlin1 --> AndroidSDK
        end

        subgraph "iOS Implementation Package"
            direction TB
            iOSStub["anura_flutter_ios.dart"]:::ios
            SwiftPlugin["AnuraFlutterPlugin.swift"]:::ios
            Config["Config.swift"]:::ios
            Delegate["MeasurementDelegate.swift"]:::ios
            Loader["GlobalLoader.swift"]:::ios
            Demographics["UserDemographics.swift"]:::ios
            NetworkingAPI["Networking/API/*.swift"]:::ios
            NetworkingCore["Networking/Networking/*.swift"]:::ios
            ExampleUI["ExampleMeasurementUIConfiguration.swift"]:::ios
            Bridging["anura_flutter_ios-Bridging-Header.h"]:::ios
            iOSSDK(("iOS xcframeworks")):::cylinder

            iOSStub --> SwiftPlugin
            SwiftPlugin --> Config
            SwiftPlugin --> Delegate
            SwiftPlugin --> Loader
            SwiftPlugin --> Demographics
            SwiftPlugin --> NetworkingAPI
            SwiftPlugin --> NetworkingCore
            SwiftPlugin --> ExampleUI
            SwiftPlugin --> Bridging
            SwiftPlugin --> iOSSDK
        end
    end

    %% Integration Tests
    IntegrationTests["Integration Tests (Fluttium & Flutter)"]:::test
    IntegrationTests --> Example

    %% CI/CD
    CI["CI/CD Workflows"]:::cloud
    CI --> Example
    CI --> DartPlugin
    CI --> PlatformInterface
    CI --> AndroidImpl
    CI --> iOSImpl

    %% Click Events
    click Example "https://github.com/anand-cureocity/anura_flutter/tree/main/anura_flutter/example/"
    click DartPluginMain "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter/lib/anura_flutter.dart"
    click Model1 "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter/lib/models/anura_scanned_data.dart"
    click Model2 "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter/lib/models/anura_user_model.dart"
    click PI_Main "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_platform_interface/lib/anura_flutter_platform_interface.dart"
    click MethodChannel "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_platform_interface/lib/src/method_channel_anura_flutter.dart"
    click AndroidStub "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_android/lib/anura_flutter_android.dart"
    click PluginKotlin1 "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_android/android/src/main/kotlin/com/example/verygoodcore/AnuraFlutterPlugin.kt"
    click PluginKotlin2 "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_android/android/src/main/kotlin/com/example/verygoodcore/AnuraScannerActivity.kt"
    click Utils "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_android/android/src/main/kotlin/com/example/verygoodcore/anura/utils/Constants.kt"
    click ViewModel "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_android/android/src/main/kotlin/com/example/verygoodcore/anura/viewmodel/ExampleStartViewModel.kt"
    click AndroidSDK "https://github.com/anand-cureocity/anura_flutter/tree/main/anura_flutter_android/android/libs/"
    click iOSStub "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_ios/lib/anura_flutter_ios.dart"
    click SwiftPlugin "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_ios/ios/Classes/AnuraFlutterPlugin.swift"
    click Config "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_ios/ios/Classes/Config.swift"
    click Delegate "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_ios/ios/Classes/MeasurementDelegate.swift"
    click Loader "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_ios/ios/Classes/GlobalLoader.swift"
    click Demographics "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_ios/ios/Classes/UserDemographics.swift"
    click NetworkingAPI "https://github.com/anand-cureocity/anura_flutter/tree/main/anura_flutter_ios/ios/Classes/Networking/API/"
    click NetworkingCore "https://github.com/anand-cureocity/anura_flutter/tree/main/anura_flutter_ios/ios/Classes/Networking/Networking/"
    click ExampleUI "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_ios/ios/Classes/Examples/ExampleMeasurementUIConfiguration.swift"
    click Bridging "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter_ios/ios/Classes/anura_flutter_ios-Bridging-Header.h"
    click iOSSDK "https://github.com/anand-cureocity/anura_flutter/tree/main/anura_flutter_ios/ios/Frameworks/"
    click CI "https://github.com/anand-cureocity/anura_flutter/tree/main/.github/workflows/"
    click IntegrationTests "https://github.com/anand-cureocity/anura_flutter/blob/main/anura_flutter/example/flows/test_platform_name.yaml"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#333,stroke-width:1px
    classDef interface fill:#C5E1A5,stroke:#333,stroke-width:1px
    classDef channel fill:#FFF59D,stroke:#333,stroke-width:1px
    classDef android fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef ios fill:#FFCCBC,stroke:#333,stroke-width:1px
    classDef cylinder fill:#CFD8DC,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef cloud fill:#B3E5FC,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef test fill:#E1BEE7,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
