# kavindudissanayake/liveactivitysample-swiftui architecture

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

- Interactive diagram: https://gitdiagram.com/kavindudissanayake/liveactivitysample-swiftui
- Repository: https://github.com/kavindudissanayake/liveactivitysample-swiftui

## Overview

Based on our analysis of the file tree and README, this project is an iOS application focused on implementing Apple Live Activities with a dedicated backend for push notifications. It is composed of several key components:

##### Main Components
- iOS Frontend: The Xcode project “LiveActivity-Sample” (and the “LiveActivity” folder) represents the iOS part. This includes:
- The primary application (LiveActivity_SampleApp.swift, AppDelegate.swift), UI views (in the Views folder such as MainView, PassengerView, RiderDetailsView, and RiderListView), view models (MVVM-style architecture as seen in the ViewModel folder for ride tracking and rider views), assets, and utility functions (ActivityManager and extensions).
- A separate module (the “LiveActivity” folder) which likely contains the widget or live activity-specific components (for example, PassengerLiveActivityView and ProgressBarView) that interface with the live activity service.

- Backend: The “live-activity-backend” directory is a Node.js/Firebase Functions based service. Its role is to manage push notifications and live activity updates by plugging into the Apple Push Notification (APN) infrastructure. It is configured using the “Auth.p8” key and associated parameters (teamID, keyID, bundleID). This backend communicates with Apple’s servers to send updates (start, update, end) as defined by the live activity lifecycle.

- Testing/Utility Module: The “TestingJsonCreate” package (Swift-based) provides tools to generate sample JSON payloads (start, update, and end) that can be tested against the Apple Push Notification Console. This tool assists in verifying the format and timing of payloads used in the live activity updates.

##### Relationships and Interactions
- The iOS app interacts with Apple’s Live Activities and APNs – it uses the tokens (start token, update token) generated and updated through communication with the backend service.
- The backend (Firebase functions) handles critical data for push notification requests. It takes configuration parameters like teamID, keyID, and p8FilePath to properly authenticate with APNs before sending notifications.
- The TestingJsonCreate module simulates backend JSON payloads which are sent to or received by the iOS app, ensuring end-to-end validation.

##### Architectural Patterns
- MVVM Pattern: Evident in the separation of Views, ViewModels, and Models within the iOS app. This separation helps maintain clear data flows and user interface interactions.
- Separation of Concerns: The project clearly isolates the iOS client (UI, view models, utilities, and live activity view) from the backend server (Firebase functions for push notifications), and further includes a specialized tool for testing JSON payloads.
- Integration with External Services: The backend’s communication with Apple’s APNs demonstrates the use of external service integration and secure communication using keys/configurations.

## Diagram (Mermaid)

```mermaid
graph TD
    %% iOS Mobile App
    subgraph "iOS Mobile App"
        direction TB
        subgraph "Core Application & MVVM"
            direction TB
            A1("Main App (LiveActivity_SampleApp.swift, AppDelegate.swift)"):::ui
            A2("Views (MainView, PassengerView, RiderDetailsView, RiderListView)"):::ui
            A3("ViewModels (MVVM Architecture)"):::ui
            A4("Assets & Utils (ActivityManager, extensions)"):::utils
        end
        subgraph "Live Activity Widget/Extension"
            direction TB
            B1("Live Activity Module"):::ui
            B2("Widget Components (PassengerLiveActivityView, ProgressBarView)"):::ui
            B3("Attributes Config (RideTrackingAttributes.swift)"):::ui
        end
    end

    %% Backend Service
    subgraph "Backend Service (Firebase Functions)"
        direction TB
        C1("Firebase Functions"):::backend
        C2("Configurations (Auth.p8, firebase.json, .firebaserc, teamID, keyID)"):::backend
    end

    %% JSON Payload Generator
    subgraph "JSON Payload Generator"
        direction TB
        D1("TestingJsonCreate Module"):::testing
        D2("Sample JSON Payloads (start, update, end)"):::testing
    end

    %% External Service
    E("Apple Push Notification Service (APNs)"):::external

    %% Data Flows
    A1 -->|"APIRequest"| C1
    A1 -->|"UpdateToken"| C1
    C1 -->|"PushNotification"| E
    E -->|"DeliveredNotification"| A1
    D1 -->|"GeneratesJSON"| C1
    D1 -->|"TestPayloads"| A1

    %% Click Events for Component Mapping
    click A1 "https://github.com/kavindudissanayake/liveactivitysample-swiftui/tree/master/LiveActivity-Sample/App"
    click A2 "https://github.com/kavindudissanayake/liveactivitysample-swiftui/tree/master/LiveActivity-Sample/Views"
    click A3 "https://github.com/kavindudissanayake/liveactivitysample-swiftui/tree/master/LiveActivity-Sample/ViewModel"
    click A4 "https://github.com/kavindudissanayake/liveactivitysample-swiftui/blob/master/LiveActivity-Sample/Assets.xcassets"
    click B1 "https://github.com/kavindudissanayake/liveactivitysample-swiftui/tree/master/LiveActivity"
    click B2 "https://github.com/kavindudissanayake/liveactivitysample-swiftui/tree/master/LiveActivity"
    click B3 "https://github.com/kavindudissanayake/liveactivitysample-swiftui/tree/master/LiveActivity"
    click C1 "https://github.com/kavindudissanayake/liveactivitysample-swiftui/tree/master/live-activity-backend/functions"
    click D1 "https://github.com/kavindudissanayake/liveactivitysample-swiftui/tree/master/TestingJsonCreate"

    %% Styling
    classDef ui fill:#9ad1f5,stroke:#333,stroke-width:2px;
    classDef utils fill:#a9dfbf,stroke:#333,stroke-width:2px;
    classDef backend fill:#f5b7b1,stroke:#333,stroke-width:2px;
    classDef testing fill:#D2B4DE,stroke:#333,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#333,stroke-width:2px;
```
