# lefuhengqi/bluetoothkit-iosdemo architecture

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

- Interactive diagram: https://gitdiagram.com/lefuhengqi/bluetoothkit-iosdemo
- Repository: https://github.com/lefuhengqi/bluetoothkit-iosdemo

## Overview

##### Main Components
- Application Entry & Core Framework: Start with the AppDelegate.swift and Main.storyboard. These form the bootstrap of the application.
- UI / View Layer: Map out the various View Controllers listed under the “Classes” directory. For example:
- DemoIndexViewController, FoundedViewController, and UserInfoViewController.
- The “calcute” subdirectory contains several controllers (e.g., CalcuteInfoViewController, CalcuelateResultViewController, etc.), views (like DeviceView controllers for Apple, Banana, etc.) and even test views (under Test) that indicate the modular UI logic for different device interactions.
- The Scale subdirectory shows specific controllers dealing with device scales.
- Business Logic & Tools: The Tools directory (with files like CommonTool.swift, Constant.swift, DemoExtensions.swift) contains utility functions that support the UI and core functionality.
- Device Communication & SDK Integration:
- PPBluetoothKit module is used for Bluetooth scanning and connection, as the README emphasizes device scanning and Bluetooth logic.
- Resources & Configurations:
- Assets.xcassets for the visual assets.
- Info.plist and lefu.config, plus additional configuration files.
- Testing Components: The existence of PPBluetoothKitDemoTests and PPBluetoothKitDemoUITests directories show unit and UI testing layers.

##### Relationships and Interactions
- The AppDelegate initializes the program and loads the initial storyboard.
- User actions in the UI (through various view controllers) trigger:
- Bluetooth scanning and device connection via the PPBluetoothKit SDK (for selecting and interacting with the scales);
- Once data is received, it is forwarded to the PPCalculateKit.
- The calculation module (PPCalculateKit) processes input data using its multiple algorithms and returns results that are shown through the corresponding view controllers.
- The Tools and Utility classes support both the UI and the business logic.
- Testing components run parallel to the application to verify functionality.

##### Architectural Patterns and Design Principles
- MVC Pattern: The structure clearly indicates a Model-View-Controller separation, with storyboards and multiple controllers handling view logic, while utility classes provide shared functionalities.
- Modularization: Different aspects such as device connection, calculation algorithms, and UI components have been separated into distinct directories.
- Integration via SDKs: Emphasis on packaging core SDK functionalities (Bluetooth operations and calculation logic) for reuse in client apps.

##### Technologies, Frameworks, and Libraries
- iOS Frameworks and Swift: All application logic is in Swift with standard file structure used by Xcode.
- CocoaPods: The Podfile and podspec (bluetooth-kit-iosdemo.podspec) signal external dependency management.
- Testing: XCTest is used for both unit and UI tests.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Core
    subgraph "Application Core"
        A1["AppDelegate.swift"]:::app
        A2["Main.storyboard"]:::app
    end

    %% UI / View Layer
    subgraph "UI / View Layer"
        UI1["DemoIndexViewController"]:::ui
        UI2["FoundedViewController"]:::ui
        UI3["UserInfoViewController"]:::ui
        UI4["CalcuteInfoViewController"]:::ui
        UI5["CalcuelateResultViewController"]:::ui
        UI6["CalcuteSelectDeviceViewController"]:::ui
        UI7["Device Views (calcute/DeviceView)"]:::ui
        UI8["Scale Controllers (calcute/Scale)"]:::ui
        UI9["WifiConfigViewController"]:::ui
        UI10["SearchDeviceViewController"]:::ui
    end

    %% SDK Service Layer
    subgraph "SDK Service Layer"
        S1["Bluetooth Module (PPBluetoothKit)"]:::sdk
        S2["Calculation Module (PPCalculateKit)"]:::sdk
    end

    %% Business Logic & Tools
    T["Tools/Utility (CommonTool.swift, Constant.swift, DemoExtensions.swift)"]:::tools

    %% Resources & Configurations
    R["Assets & Configurations (Assets.xcassets, Info.plist, lefu.config, body_lang_en.json)"]:::resources

    %% Testing Components
    subgraph "Testing Layer"
        Test1["Unit Tests (PPBluetoothKitDemoTests)"]:::tests
        Test2["UI Tests (PPBluetoothKitDemoUITests)"]:::tests
    end

    %% Connections: Application Core to UI Layer
    A1 --> UI1
    A2 --> UI1

    %% UI triggering SDK interactions
    UI1 -->|"triggerScan"| S1
    S1 -->|"sendData"| S2
    S2 -->|"displayResult"| UI5

    %% Tools support UI and SDK layers
    T --> UI1
    T --> S1

    %% Resources support Application Core and Tools
    R --> A1
    R --> T

    %% Testing verifies UI and SDK functionality
    Test1 --> UI1
    Test1 --> S1
    Test2 --> UI1

    %% Additional internal UI relationships (aggregated view)
    UI1 --> UI2
    UI2 --> UI3
    UI3 --> UI4
    UI4 --> UI6
    UI6 --> UI7
    UI7 --> UI8
    UI8 --> UI9
    UI9 --> UI10

    %% Click Events
    click A1 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/AppDelegate.swift"
    click A2 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/Main.storyboard"
    click UI1 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/Classes/DemoIndexViewController.swift"
    click UI2 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/Classes/FoundedViewController.swift"
    click UI3 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/Classes/UserInfoViewController.swift"
    click UI4 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/Classes/calcute/CalcuteInfoViewController.swift"
    click UI5 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/Classes/calcute/CalcuelateResultViewController.swift"
    click UI6 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/Classes/calcute/CalcuteSelectDeviceViewController.swift"
    click UI7 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/tree/main/PPBluetoothKitDemo/Classes/calcute/DeviceView/"
    click UI8 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/tree/main/PPBluetoothKitDemo/Classes/calcute/Scale"
    click UI9 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/Classes/calcute/WifiConfigViewController.swift"
    click UI10 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/Classes/calcute/SearchDeviceViewController.swift"
    click T "https://github.com/lefuhengqi/bluetoothkit-iosdemo/tree/main/PPBluetoothKitDemo/Classes/Tools"
    click R "https://github.com/lefuhengqi/bluetoothkit-iosdemo/blob/main/PPBluetoothKitDemo/Assets.xcassets"
    click Test1 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/tree/main/PPBluetoothKitDemoTests"
    click Test2 "https://github.com/lefuhengqi/bluetoothkit-iosdemo/tree/main/PPBluetoothKitDemoUITests"

    %% Styles
    classDef app fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef ui fill:#66ccff,stroke:#333,stroke-width:2px;
    classDef sdk fill:#FF9999,stroke:#333,stroke-width:2px;
    classDef tools fill:#99FF99,stroke:#333,stroke-width:2px;
    classDef resources fill:#CCCCCC,stroke:#333,stroke-width:2px;
    classDef tests fill:#FFCCFF,stroke:#333,stroke-width:2px;
```
