# playgama/bridge architecture

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

- Interactive diagram: https://gitdiagram.com/playgama/bridge
- Repository: https://github.com/playgama/bridge

## Overview

##### Main Components Identification

The system should be represented as a layered architecture with the following main components:

a) Game Integration Layer
- Entry point (PlaygamaBridge.js)
- Game Engine Plugins Interface

b) Core Services Layer
- Message Broker System
- Promise Management
- Timer Services
- Utility Functions

c) Functional Modules Layer
- Achievements
- Advertisements
- Clipboard
- Device
- Game
- Leaderboard
- Payments
- Platform
- Player
- Remote Config
- Social
- Storage

d) Platform Bridge Layer
- Multiple Platform-Specific Implementations
- Base Platform Bridge Interface

- [Game Integration Layer]
- ↓
- [Core Services Layer]
- ↓
- [Functional Modules Layer]
- ↓
- [Platform Bridge Layer]

##### Component Relationships

Following interactions:

- PlaygamaBridge and ModuleBase
- ModuleBase and PlatformBridgeBase
- MessageBroker and all modules

- Platform-specific implementations extending from PlatformBridgeBase
- Functional modules extending from ModuleBase

##### Specific Implementation Details

Key architectural elements:

a) Message Broker Pattern:
- How MessageBroker.js facilitates communication between components
- Event-driven architecture

b) Module System:
- Demonstrate how ModuleBase.js serves as the foundation for all functional modules
- Inheritance pattern for platform-specific implementations

##### External Integration Points

Integration points with:
- Game engines (Unity, Construct 3, Godot, etc.)
- Platform SDKs (Facebook, Telegram, etc.)
- HTML5 game containers

##### Technical Details

Annotations for:
- JavaScript/ES6+ implementation
- Webpack bundling process
- Promise-based async operations
- Platform-specific API adaptations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#2196F3,color:white
    classDef module fill:#4CAF50,color:white
    classDef platform fill:#FF9800,color:white
    classDef external fill:#9E9E9E,color:white

    %% Game Integration Layer
    subgraph GameIntegration
        Entry["PlaygamaBridge.js"]
        Bundle["index.js"]
        GameEngines["Game Engine Plugins"]
    end
    click Entry "https://github.com/playgama/bridge/blob/main/src/PlaygamaBridge.js"
    click Bundle "https://github.com/playgama/bridge/blob/main/src/index.js"

    %% Core Services Layer
    subgraph CoreServices
        MessageBroker["Message Broker"]
        PromiseManager["Promise Management"]
        Timer["Timer Services"]
        Utils["Utility Functions"]
    end
    click MessageBroker "https://github.com/playgama/bridge/blob/main/src/common/MessageBroker.js"
    click PromiseManager "https://github.com/playgama/bridge/blob/main/src/common/PromiseDecorator.js"
    click Timer "https://github.com/playgama/bridge/blob/main/src/common/Timer.js"
    click Utils "https://github.com/playgama/bridge/blob/main/src/common/utils.js"

    %% Functional Modules Layer
    subgraph FunctionalModules
        ModuleBase["Module Base"]
        Achievements["Achievements"]
        Ads["Advertisements"]
        Clipboard["Clipboard"]
        Device["Device"]
        Game["Game"]
        Leaderboard["Leaderboard"]
        Payments["Payments"]
        Platform["Platform"]
        Player["Player"]
        RemoteConfig["Remote Config"]
        Social["Social"]
        Storage["Storage"]
    end
    click ModuleBase "https://github.com/playgama/bridge/blob/main/src/modules/ModuleBase.js"
    click Achievements "https://github.com/playgama/bridge/blob/main/src/modules/AchievementsModule.js"
    click Ads "https://github.com/playgama/bridge/blob/main/src/modules/AdvertisementModule.js"
    click Clipboard "https://github.com/playgama/bridge/blob/main/src/modules/ClipboardModule.js"
    click Device "https://github.com/playgama/bridge/blob/main/src/modules/DeviceModule.js"
    click Game "https://github.com/playgama/bridge/blob/main/src/modules/GameModule.js"
    click Leaderboard "https://github.com/playgama/bridge/blob/main/src/modules/LeaderboardModule.js"
    click Payments "https://github.com/playgama/bridge/blob/main/src/modules/PaymentsModule.js"
    click Platform "https://github.com/playgama/bridge/blob/main/src/modules/PlatformModule.js"
    click Player "https://github.com/playgama/bridge/blob/main/src/modules/PlayerModule.js"
    click RemoteConfig "https://github.com/playgama/bridge/blob/main/src/modules/RemoteConfigModule.js"
    click Social "https://github.com/playgama/bridge/blob/main/src/modules/SocialModule.js"
    click Storage "https://github.com/playgama/bridge/blob/main/src/modules/StorageModule.js"

    %% Platform Bridge Layer
    subgraph PlatformBridges
        BridgeBase["Platform Bridge Base"]
        Facebook["Facebook Bridge"]
        Telegram["Telegram Bridge"]
        Yandex["Yandex Bridge"]
        VK["VK Bridge"]
    end
    click BridgeBase "https://github.com/playgama/bridge/blob/main/src/platform-bridges/PlatformBridgeBase.js"
    click Facebook "https://github.com/playgama/bridge/blob/main/src/platform-bridges/FacebookPlatformBridge.js"
    click Telegram "https://github.com/playgama/bridge/blob/main/src/platform-bridges/TelegramPlatformBridge.js"
    click Yandex "https://github.com/playgama/bridge/blob/main/src/platform-bridges/YandexPlatformBridge.js"
    click VK "https://github.com/playgama/bridge/blob/main/src/platform-bridges/VkPlatformBridge.js"

    %% Relationships
    Entry --> MessageBroker
    Bundle --> Entry
    GameEngines --> Entry
    MessageBroker <--> ModuleBase
    ModuleBase <--> BridgeBase
    BridgeBase --> Facebook & Telegram & Yandex & VK

    %% Module Relationships
    ModuleBase --> Achievements & Ads & Clipboard & Device & Game & Leaderboard & Payments & Platform & Player & RemoteConfig & Social & Storage

    %% Core Service Relationships
    MessageBroker --> PromiseManager
    MessageBroker --> Timer
    MessageBroker --> Utils

    %% Styling
    class Entry,Bundle,GameEngines core
    class MessageBroker,PromiseManager,Timer,Utils core
    class ModuleBase,Achievements,Ads,Clipboard,Device,Game,Leaderboard,Payments,Platform,Player,RemoteConfig,Social,Storage module
    class BridgeBase,Facebook,Telegram,Yandex,VK platform

    %% Legend
    subgraph Legend
        CoreComponent["Core Component"]:::core
        ModuleComponent["Module Component"]:::module
        PlatformComponent["Platform Component"]:::platform
    end
```
