# yazanturk/pusher_beams architecture

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

- Interactive diagram: https://gitdiagram.com/yazanturk/pusher_beams
- Repository: https://github.com/yazanturk/pusher_beams

## Overview

##### Project type and purpose
- Type: Federated Flutter plugin (SDK/library), not a standalone application
- Purpose: Expose Pusher Beams push-notification capabilities to Flutter apps via a single “app-facing” Dart API, dispatching calls to native (Android/iOS) or JavaScript (Web) implementations

##### File structure
- Top-level “packages” folder contains five packages:
– pusher_beams (app-facing Dart API + example)
– pusher_beams_platform_interface (abstract interface + Pigeon definitions)
– pusher_beams_android (Android native plugin implementation)
– pusher_beams_ios (iOS native plugin implementation)
– pusher_beams_web (Web JS plugin implementation)
- Example sub-folder under pusher_beams demonstrates usage + integration tests
- Makefile in platform_interface for Pigeon code generation
- pubspec.yaml files define inter-package dependencies

##### README for additional insights
- Section “Architecture” explicitly names the five packages and describes federated plugin architecture
- Pigeon is used to generate method-channel bindings
- Dependencies: Flutter (Dart), Android SDK (Firebase), iOS SDK (APNs), Web SDK (Pusher Beams JS)

##### Main components & interactions
a. Components:
– Flutter App (example or end-user app)
– pusher_beams Dart package (app-facing public API)
– pusher_beams_platform_interface (abstract interface & Pigeon messages)
– Platform plugins:
- pusher_beams_android (Android/Kotlin + Java)
- pusher_beams_ios (Objective-C + Swift)
- pusher_beams_web (Dart→JS wrapper)
– External services:
- Pusher Beams service (REST/WebSocket endpoint)
- Firebase (Android prereq: google-services.json)
- APNs (iOS prerequisite)
b. Relationships & data flow:
- Flutter App → calls methods on PusherBeams.instance (from pusher_beams package)
- pusher_beams package → delegates to PusherBeamsPlatform.instance (from platform_interface)
- platform_interface uses Pigeon-generated classes to route calls over MethodChannel (Android/iOS) or JS interop (Web)
- Platform plugin receives method call → invokes native SDK or JS SDK → communicates with Pusher Beams service
- Incoming messages/events propagate back: native/JS SDK → MethodChannel/JS callback → Dart layer → app
c. Architectural patterns & principles:
- Federated plugin architecture: clear separation between app API, platform-agnostic interface, and per-platform code
- Interface segregation: platform_interface package defines only abstract APIs
- Pigeon codegen: type-safe, generated MethodChannel glue
d. Key technologies/frameworks:
- Flutter / Dart
- MethodChannel (Android & iOS IPC)
- Pigeon (code generation for platform messaging)
- Kotlin/Java (Android), Swift/Obj-C (iOS), JS (Web)
- Firebase (Android), APNs (iOS), Pusher Beams JS SDK (Web)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Dart Layer
    subgraph "Dart Layer"
        App["Flutter App\n(example)\n(Dart)"]:::dart
        API["pusher_beams\n(Dart API)"]:::dart
    end

    %% Interface Layer
    subgraph "Platform Interface Layer"
        PI["pusher_beams_platform_interface\n(Abstract API)"]:::interface
        MCStub["MethodChannel Stub\n(method_channel_pusher_beams)"]:::interface
        PigeonSchema["Pigeon Schema\n(messages.dart)"]:::interface
        Makefile["Makefile"]:::interface
    end

    %% Channel / Interop Layer
    subgraph "Channel / JS Interop Layer"
        Channel["Platform Channel / JS Interop"]:::channel
    end

    %% Native Plugins
    subgraph "Native Plugin Implementations"
        Android["Android Plugin\n(Kotlin/Java)"]:::native
        iOS["iOS Plugin\n(Swift/Obj-C)"]:::native
        Web["Web Plugin\n(Dart→JS)"]:::native
    end

    %% External Services
    subgraph "External Services"
        PusherService["Pusher Beams Service\n(HTTP/WebSocket)"]:::external
        Firebase["Firebase\n(Android config)"]:::external
        APNs["APNs\n(iOS)"]:::external
    end

    %% Call Flow Top-Down
    App -->|"calls API"| API
    API -->|"delegates to PusherBeamsPlatform"| PI
    PI -->|"uses Pigeon messages"| PigeonSchema
    PI -->|"stub calls"| MCStub
    MCStub -->|"MethodChannel.invokeMethod"| Channel
    Channel -->|"/ Kotlin/Java"| Android
    Channel -->|"/ Obj-C/Swift"| iOS
    Channel -->|"JS interop"| Web

    %% Native to External
    Android -->|"HTTP/WebSocket"| PusherService
    Android -->|"Firebase config"| Firebase
    iOS -->|"APNs"| APNs
    Web -->|"HTTP/WebSocket"| PusherService

    %% Callbacks Back Up
    PusherService -->|"events"| Android
    PusherService -->|"events"| iOS
    PusherService -->|"events"| Web
    Android -->|"MethodChannel callback"| Channel
    iOS -->|"MethodChannel callback"| Channel
    Web -->|"JS callback"| Channel
    Channel -->|"response"| PI
    PI -->|"response"| API
    API -->|"Dart callback"| App

    %% Click Events
    click App "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams/example/lib/main.dart"
    click API "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams/lib/pusher_beams.dart"
    click PI "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_platform_interface/lib/pusher_beams_platform_interface.dart"
    click MCStub "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_platform_interface/lib/method_channel_pusher_beams.dart"
    click PigeonSchema "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_platform_interface/pigeons/messages.dart"
    click Makefile "https://github.com/yazanturk/pusher_beams/tree/master/packages/pusher_beams_platform_interface/Makefile"
    click Android "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_android/android/src/main/kotlin/com/pusher/pusher_beams/PusherBeamsPlugin.kt"
    click Android "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_android/android/src/main/java/com/pusher/pusher_beams/Messages.java"
    click iOS "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_ios/ios/Classes/SwiftPusherBeamsPlugin.swift"
    click iOS "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_ios/ios/Classes/PusherBeamsPlugin.h"
    click iOS "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_ios/ios/Classes/PusherBeamsPlugin.m"
    click iOS "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_ios/ios/Classes/messages.h"
    click iOS "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_ios/ios/Classes/messages.m"
    click Web "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_web/lib/pusher_beams_web.dart"
    click Web "https://github.com/yazanturk/pusher_beams/blob/master/packages/pusher_beams_web/lib/pusher_beams.dart"

    %% Styles
    classDef dart fill:#D6EFFF,stroke:#1E90FF,color:#000
    classDef interface fill:#FFF5B1,stroke:#FFD700,color:#000
    classDef channel fill:#E0E0E0,stroke:#A9A9A9,color:#000
    classDef native fill:#D5F5D5,stroke:#28A745,color:#000
    classDef external fill:#F0F0F0,stroke:#A9A9A9,color:#000
```
