# home-assistant/mobile-apps-fcm-push architecture

> Architecture diagram of the GitHub repository home-assistant/mobile-apps-fcm-push, 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/home-assistant/mobile-apps-fcm-push
- Repository: https://github.com/home-assistant/mobile-apps-fcm-push

## Overview

##### Main Components
- Firebase Cloud Functions: Represent the main backend logic found in the “functions” folder. Note the individual modules such as index.js (which likely serves as the entry point), android.js and ios.js (platform-specific logic), and legacy.js (handling legacy protocols or formats).
- Mobile Push Clients: Illustrate mobile devices (Android, iOS) that will receive push notifications sent via Firebase.
- Firebase Configuration and Deployment: Include configuration files like .firebaserc and firebase.json, and the integration with the Firebase CLI, which is used to deploy and manage the functions.
- Testing and Fixtures: Although not “runtime” components, include a section for the testing framework, showing the test suite in the “functions/test” directory and the extensive legacy fixture files. These verify that the functions work correctly with a variety of payloads.

##### Relationships and Interactions
- Logical Separation: Show that platform-specific logic branches out into separate sub-components (android.js, ios.js) and that legacy notifications are handled by separate logic (legacy.js, along with its extensive test fixtures).
- Deployment Flow: Represent the role of Firebase CLI and the configuration files (.firebaserc, firebase.json) that help deploy the functions to the correct regions (like “us-central1” or “europe-west1”).

##### Architectural Patterns and Design Principles
- Modular Design: The code is clearly modularized (separate files for different platforms, distinct test fixtures) which can be shown by grouping related functions into modules.
- Environment-driven Configurations: The presence of runtime configuration files (like .runtimeconfig.json generated via firebase functions:config commands) indicates that the system relies on external configuration, showing a separation between code and environment specifics.
- Test-Driven Development: The organized test and fixture directories suggest a strong testing methodology, supporting the robustness of the notification logic across various payload types.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Push Notification Request"]:::external

    subgraph "Firebase Config & Deployment"
        FB_RC[".firebaserc"]:::config
        FB_JSON["firebase.json"]:::config
        CLI["Firebase CLI"]:::config
    end

    subgraph "Firebase Cloud Functions"
        CF_index["index.js"]:::runtime
        CF_android["android.js"]:::runtime
        CF_ios["ios.js"]:::runtime
        CF_legacy["legacy.js"]:::runtime
    end

    subgraph "Testing and Fixtures"
        TestSuite["Test Suite"]:::test
    end

    subgraph "Public Access"
        Static["index.html"]:::static
    end

    subgraph "Mobile Devices"
        Android["Android Device"]:::mobile
        iOS["iOS Device"]:::mobile
    end

    A -->|"triggers"| CF_index
    CF_index -->|"routes_to_Android"| CF_android
    CF_index -->|"routes_to_iOS"| CF_ios
    CF_index -->|"routes_to_Legacy"| CF_legacy

    CF_android -->|"push_notification"| Android
    CF_ios -->|"push_notification"| iOS

    CLI -->|"deploys_to"| CF_index
    FB_RC -->|"configures"| CLI
    FB_JSON -->|"configures"| CLI

    CF_legacy -->|"verified_by"| TestSuite

    %% Click Events
    click CF_index "https://github.com/home-assistant/mobile-apps-fcm-push/blob/main/functions/index.js"
    click CF_android "https://github.com/home-assistant/mobile-apps-fcm-push/blob/main/functions/android.js"
    click CF_ios "https://github.com/home-assistant/mobile-apps-fcm-push/blob/main/functions/ios.js"
    click CF_legacy "https://github.com/home-assistant/mobile-apps-fcm-push/blob/main/functions/legacy.js"
    click FB_RC "https://github.com/home-assistant/mobile-apps-fcm-push/blob/main/.firebaserc"
    click FB_JSON "https://github.com/home-assistant/mobile-apps-fcm-push/blob/main/firebase.json"
    click TestSuite "https://github.com/home-assistant/mobile-apps-fcm-push/tree/main/functions/test/"
    click Static "https://github.com/home-assistant/mobile-apps-fcm-push/blob/main/public/index.html"

    %% Styles
    classDef external fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef runtime fill:#bbdefb,stroke:#1e88e5,stroke-width:2px;
    classDef config fill:#c8e6c9,stroke:#43a047,stroke-width:2px;
    classDef test fill:#ffcdd2,stroke:#e53935,stroke-width:2px;
    classDef mobile fill:#ffe082,stroke:#ffa000,stroke-width:2px;
    classDef static fill:#b2ebf2,stroke:#00acc1,stroke-width:2px;
```
