# basf-mobile-solutions/piano_analytics architecture

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

- Interactive diagram: https://gitdiagram.com/basf-mobile-solutions/piano_analytics
- Repository: https://github.com/basf-mobile-solutions/piano_analytics

## Overview

##### Project Type and Purpose
- This is a cross-platform Flutter plugin for Piano Analytics.
- Its purpose is to provide a unified API (through Dart) that communicates with native implementations on Android and iOS.
- The README shows sample usage of initializing, configuring, and tracking events with the Piano Analytics SDK.

##### Analyzing the File Structure
- Top-level directories include:
- lib: Contains the Dart interface files for the plugin (e.g. piano_flutter_plugin.dart, piano_flutter_plugin_method_channel.dart, piano_flutter_plugin_platform_interface.dart).
- android: Holds the Android-side native code, clearly organized in Kotlin under packages (com/basf/piano/flutter/plugin/piano_flutter_plugin). This is the native bridge for Android.
- ios: Contains iOS native code (Objective-C and Swift files like PianoFlutterPlugin.h, PianoFlutterPlugin.m, SwiftPianoFlutterPlugin.swift) used to implement the plugin functionality for iOS.
- example: Provides a demo Flutter app with platform-specific setups (Android and iOS) showing how to integrate and test the plugin.
- Other files, like pubspec.yaml and test directories, indicate the plugin follows common Flutter package conventions.

##### Key Components
a. Flutter Application (or Consumer App):
- Represents any Flutter app that imports the plugin via pubspec.yaml.
- How the app calls the plugin API (e.g., configuration and trackEvent methods).

b. Dart Plugin Interface:
- Core Dart files in the “lib” directory.
- Platform interface (piano_flutter_plugin_platform_interface.dart) to define how the Dart side communicates with native code.
- Method channel (piano_flutter_plugin_method_channel.dart) implementation, which is the conduit between Dart and native layers.

c. Native Platform Implementations:
- Android:
- Android module from the “android” directory. Include the Kotlin code in PianoFlutterPlugin.kt, which implements the plugin functionality that interfaces with the Piano Analytics SDK on Android.
- iOS:
- IOS module from the “ios” directory. Note the Objective-C (PianoFlutterPlugin.h/m) and Swift (SwiftPianoFlutterPlugin.swift) files that provide the code needed for iOS integration.

d. Example Application:
- It includes platform-specific application setups for both Android and iOS.
- This is useful to understand how the plugin is integrated and tested.

##### Relationships and Interactions
- That the communication happens through a platform channel mechanism:
- The MethodChannel acts as a bi-directional bridge: Commands (like trackEvent) flow out from Dart and responses or native triggers are sent back.

##### Architectural Patterns & Design Principles
- Clear separation of concerns by isolating the Flutter (Dart) API from native (Android/iOS) implementations.
- Use of the Platform Interface pattern: The ‘piano_flutter_plugin_platform_interface.dart’ defines the contract, while different implementations (MethodChannel for most cases) are provided per platform.
- The example project demonstrates integration best practices and can act as a template or use case scenario.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Flutter Consumer Layer"
        FCA["Flutter Consumer App"]:::consumer
    end

    subgraph "Dart Plugin Interface"
        API["Main API"]:::flutter
        PI["Platform Interface"]:::flutter
        MC["MethodChannel Implementation"]:::flutter
    end

    subgraph "Native Implementations"
        Android["Android Native Module (Kotlin)"]:::android
        subgraph "iOS Native Module"
            iOS_Header["PianoFlutterPlugin.h"]:::ios
            iOS_Impl["PianoFlutterPlugin.m"]:::ios
            iOS_Swift["SwiftPianoFlutterPlugin.swift"]:::ios
        end
    end

    FCA -->|"calls"| API
    API -->|"delegates"| MC
    API -->|"usesContract"| PI
    MC -.->|"implements"| PI
    MC -->|"callsViaChannel"| Android
    MC -->|"callsViaChannel"| iOS_Header
    MC -->|"callsViaChannel"| iOS_Impl
    MC -->|"callsViaChannel"| iOS_Swift

    click FCA "https://github.com/basf-mobile-solutions/piano_analytics/tree/main/example/"
    click API "https://github.com/basf-mobile-solutions/piano_analytics/blob/main/lib/piano_flutter_plugin.dart"
    click PI "https://github.com/basf-mobile-solutions/piano_analytics/blob/main/lib/piano_flutter_plugin_platform_interface.dart"
    click MC "https://github.com/basf-mobile-solutions/piano_analytics/blob/main/lib/piano_flutter_plugin_method_channel.dart"
    click Android "https://github.com/basf-mobile-solutions/piano_analytics/blob/main/android/src/main/kotlin/com/basf/piano/flutter/plugin/piano_flutter_plugin/PianoFlutterPlugin.kt"
    click iOS_Header "https://github.com/basf-mobile-solutions/piano_analytics/blob/main/ios/Classes/PianoFlutterPlugin.h"
    click iOS_Impl "https://github.com/basf-mobile-solutions/piano_analytics/blob/main/ios/Classes/PianoFlutterPlugin.m"
    click iOS_Swift "https://github.com/basf-mobile-solutions/piano_analytics/blob/main/ios/Classes/SwiftPianoFlutterPlugin.swift"

    classDef consumer fill:#ffe680,stroke:#333,stroke-width:2px;
    classDef flutter fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef android fill:#a8d08d,stroke:#333,stroke-width:2px;
    classDef ios fill:#f4b084,stroke:#333,stroke-width:2px;
```
