# tencentcloud/tcmpp-demo-ios architecture

> Architecture diagram of the GitHub repository tencentcloud/tcmpp-demo-ios, 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/tencentcloud/tcmpp-demo-ios
- Repository: https://github.com/tencentcloud/tcmpp-demo-ios

## Overview

##### Main Components
- User Interface (UI) Layer: Represented by the AppDelegate, storyboards (LaunchScreen, Main), and various view controllers (e.g., TCMPPMainVC, TCMPPLoginVC, TCMPPMenuView, TCMPPPayView). This layer handles user interaction.
- Configuration Manager: In the AppDelegate you see the initialization of TMAServerConfig by loading a JSON configuration file (tcmpp-ios-configurations.json). This component provides the app with runtime configuration.
- Mini Program SDK Manager: The TMFMiniAppSDKManager (a shared instance) is responsible for bootstrapping the mini program engine, utilizing the configuration, and managing startup operations (including checking for updates or caching behavior).
- Custom API and Utilities: The “CustomApi” folder and “Utils” directory offer utility classes and custom APIs (e.g., PayRequestJsApi, StateEventTest) that extend or interact with the SDK.
- External Remote Server: Although not directly part of the codebase, the README explains that the mini program is first loaded from a local cache and then verified/updated by connecting to a remote server. This external service is a critical part of the overall system.

##### Out the Relationships and Interactions
- The UI layer (invoked via the AppDelegate during application launch) acts as the entry point.
- The Custom API and Utility modules act as supporting services for payment processing, language management, and event handling, aiding the UI or SDK integration components.

##### Architectural Patterns and Design Principles
- The design follows a separation of concerns – the UI is clearly separated from the business logic (configuration and SDK management) and support utilities.
- Use of singletons (for the shared instance of TMFMiniAppSDKManager) centralizes the mini program management.
- The application follows standard MVC patterns common in iOS development, with View Controllers (and storyboards) handling UI, while managers and utility classes manage data and external interactions.

##### Technologies and Frameworks
- iOS native frameworks (UIKit, Storyboards).
- CocoaPods is used for dependency management, as seen in the Podfile instructions.
- The project leverages configuration management via JSON and uses a custom SDK (TCMPPSDK) for mini program integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer (Objective-C)
    subgraph "UI Layer (Objective-C)"
        A_Obj("AppDelegate (Objective-C)"):::ui
        B_Obj("Storyboards (Objective-C)"):::ui
        C_Obj("View Controllers (Objective-C)"):::ui
    end

    %% UI Layer (Swift)
    subgraph "UI Layer (Swift)"
        A_Sw("AppDelegate (Swift)"):::ui
        B_Sw("Storyboards (Swift)"):::ui
        C_Sw("View Controllers (Swift)"):::ui
    end

    %% Configuration Manager
    subgraph "Configuration Manager"
        D_Obj("TMAServerConfig (Obj-C)"):::config
        D_Sw("TMAServerConfig (Swift)"):::config
    end

    %% Mini Program SDK Manager
    subgraph "Mini Program SDK Manager"
        E_Obj("Mini Program SDK Manager (Obj-C)"):::config
        E_Sw("Mini Program SDK Manager (Swift)"):::config
    end

    %% Custom API Modules & Utilities
    subgraph "Custom Modules & Utilities"
        F_Obj("Custom API Modules (Obj-C)"):::util
        G_Obj("Utilities (Obj-C)"):::util
        F_Sw("Utilities & Custom API (Swift)"):::util
    end

    %% External Remote Server/Cache
    H("External Remote Server/Cache"):::external

    %% CocoaPods dependency note (integration with SDK Manager)
    I("CocoaPods (TCMPPSDK dependency)"):::config

    %% Connections for Objective-C flow
    A_Obj -->|"loads_config"| D_Obj
    D_Obj -->|"initializes"| E_Obj
    C_Obj -->|"user_triggers_MiniApp"| E_Obj
    E_Obj -->|"checks_updates"| H
    C_Obj -->|"calls_API"| F_Obj
    C_Obj -->|"uses_utilities"| G_Obj
    A_Obj -->|"manages"| B_Obj

    %% Connections for Swift flow
    A_Sw -->|"loads_config"| D_Sw
    D_Sw -->|"initializes"| E_Sw
    C_Sw -->|"user_triggers_MiniApp"| E_Sw
    E_Sw -->|"checks_updates"| H
    C_Sw -->|"calls_API"| F_Sw
    A_Sw -->|"manages"| B_Sw

    %% CocoaPods integration connection
    E_Obj ---|"integrates"| I
    E_Sw ---|"integrates"| I

    %% Styles
    classDef ui fill:#AEDFF7,stroke:#1f78b4,stroke-width:2px;
    classDef config fill:#C3F7AE,stroke:#3D9970,stroke-width:2px;
    classDef util fill:#D3D3D3,stroke:#696969,stroke-width:2px;
    classDef external fill:#F7D6AE,stroke:#E67E22,stroke-width:2px;

    %% Click Events for Objective-C UI Layer
    click A_Obj "https://github.com/tencentcloud/tcmpp-demo-ios/blob/main/Objective-C/TCMPPDemo/AppDelegate.m"
    click B_Obj "https://github.com/tencentcloud/tcmpp-demo-ios/blob/main/Objective-C/TCMPPDemo/Base.lproj/LaunchScreen.storyboard"
    click C_Obj "https://github.com/tencentcloud/tcmpp-demo-ios/blob/main/Objective-C/TCMPPDemo/TCMPPMainVC.m"

    %% Click Events for Swift UI Layer
    click A_Sw "https://github.com/tencentcloud/tcmpp-demo-ios/blob/main/Swift/TCMPPDemo-Swift/AppDelegate.swift"
    click B_Sw "https://github.com/tencentcloud/tcmpp-demo-ios/blob/main/Swift/TCMPPDemo-Swift/Base.lproj/LaunchScreen.storyboard"
    click C_Sw "https://github.com/tencentcloud/tcmpp-demo-ios/blob/main/Swift/TCMPPDemo-Swift/Class/TCMPPMainVC.swift"

    %% Click Events for Configuration Manager
    click D_Obj "https://github.com/tencentcloud/tcmpp-demo-ios/blob/main/Objective-C/TCMPPDemo/tcsas-ios-configurations.json"
    click D_Sw "https://github.com/tencentcloud/tcmpp-demo-ios/blob/main/Swift/TCMPPDemo-Swift/Res/tcsas-ios-configurations.json"

    %% Click Events for Mini Program SDK Manager
    click E_Obj "https://github.com/tencentcloud/tcmpp-demo-ios/blob/main/Objective-C/TCMPPDemo/MIniAppDemoSDKDelegateImpl.m"
    click E_Sw "https://github.com/tencentcloud/tcmpp-demo-ios/blob/main/Swift/TCMPPDemo-Swift/Class/MIniAppDemoSDKDelegateImpl.swift"

    %% Click Events for Custom API Modules & Utilities
    click F_Obj "https://github.com/tencentcloud/tcmpp-demo-ios/tree/main/Objective-C/TCMPPDemo/CustomApi"
    click G_Obj "https://github.com/tencentcloud/tcmpp-demo-ios/tree/main/Objective-C/TCMPPDemo/Utils"
    click F_Sw "https://github.com/tencentcloud/tcmpp-demo-ios/tree/main/Swift/TCMPPDemo-Swift/Class/Utils"
```
