# augmentos-community/smartglassesmanager architecture

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

- Interactive diagram: https://gitdiagram.com/augmentos-community/smartglassesmanager
- Repository: https://github.com/augmentos-community/smartglassesmanager

## Overview

##### Main Components
- Mobile Platforms:
– Android SmartGlassesManager (SGM_android): This is a full Android app that includes native C++ audio processing (via ogg/opus encoder libraries, JNI bridges, etc.), Android services (SmartGlassesAndroidService), event bus handlers, and multiple packages for communications, speech recognition (Google, Azure, Deepgram, Vosk), and device-specific adaptations.
– iOS SGM Module (SGM_iOS): A Swift-based implementation that provides similar functionality for the iOS platform.
– Android Frontend (android_smart_glasses_frontend) and Example App (example_smart_glasses_app): These projects appear to be front-facing applications and sample implementations that use the SmartGlassesManager middleware.
- Connectivity & Communication Layer:
– WebSocket Servers/Clients (e.g., AspWebsocketServer on the phone side, AsgWebSocketClient in the frontend) used for data streaming between devices.
– Underlying communication channels: WiFi (the phone’s hotspot), Bluetooth, and MCU/glasses-specific networking.
- Audio and Sensor Data Processing:
– Native C++ modules (found under src/main/cpp) for audio encoding with ogg/opus and related third-party libraries.
– JNI bridges allowing Java components (or Swift for iOS) to call into these native libraries.
- Speech Recognition Subsystem:
– Multiple integration modules for Google Cloud Speech, Azure, Deepgram, Vosk, etc., including dedicated packages and helper classes.
- UI and User Interaction:
– Android UI components containing activities, fragments, and layouts (such as MainActivity, various UI package classes, and layout XML resources).
– Smart glasses’ minimal UI or “heads-up display” components abstracted by the middleware.
- Utility and Support Modules:
– Utility classes (AES encryption, bitmap manipulation, network utils, etc.), event bus message definitions, and configuration files.
- Third-Party Libraries:
– Bundled and compiled native libraries (libogg, libopus, opus_tools) and included build scripts (CMakeLists, gradle files).

##### Relationships and Data Flows
- From the UI layer to the Communication layer representing user actions (e.g., “Connect Smart Glasses”, “Start Hotspot”).
- From the Communication layer to the Native Audio Processing and Speech Recognition subsystems, illustrating the flow of audio and sensor data.
- Between the mobile device and smart glasses hardware – label connections such as “WiFi Hotspot”, “Bluetooth”, or “Direct IP”.
- Integration with external services (Google Cloud, Azure, etc.) from the Speech Recognition subsystem.

##### Architectural Patterns and Design Principles
– Modular design: Separate modules for connectivity, audio processing, and speech recognition.
– Abstraction: The middleware “abstracts” hardware differences from different smart glasses models.
– Cross-platform support: Parallel implementations for Android and iOS.
– Use of native libraries: Integration via JNI for performance-critical C++ code (ogg/opus encoder and related tools).
– Event-driven architecture: Presence of event bus messages to communicate among different components (e.g., audio events, connection status events).

##### Details About Key Technologies
– Android SDK and Gradle for Android builds; Xcode/Swift Package Manager for iOS.
– C/C++ for native audio encoding and processing (with CMake build scripts).
– WebSocket and network communication components.
– Third-party libraries: libogg, libopus, opus_tools.
– Integration with cloud-based speech-to-text APIs.
– Standard UI components and layouts (XML) for Android presentation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Android SmartGlassesManager Subsystem
    subgraph "Android SmartGlassesManager"
        ACore["SmartGlassesManager Core Middleware"]:::mobile
        subgraph "UI Layer"
            UI["UI Components & Layouts"]:::ui
        end
        subgraph "Service/Communication Layer"
            SGService["SmartGlassesAndroidService"]:::service
            WS["AspWebsocketServer"]:::service
        end
        subgraph "Native Audio Processing"
            OggEnc["Ogg/Opus Encoder"]:::native
            JNIBridge["JNI Bridge"]:::native
        end
        subgraph "Speech Recognition Subsystem"
            Speech["Speech Recognition"]:::speech
        end
        subgraph "Utility and Support"
            Utils["Utility Modules & EventBus"]:::utility
        end
    end

    %% iOS SGM Module
    subgraph "iOS Module"
        iOSSGM["SGM (iOS)"]:::mobile
    end

    %% Companion Apps
    subgraph "Companion Apps"
        AndroidFE["Android Frontend"]:::companion
        ExampleApp["Example Smart Glasses App"]:::companion
    end

    %% External Systems
    ExtHardware["Smart Glasses Hardware"]:::external
    Cloud["Cloud Speech Services (Google/Azure/Deepgram/Vosk)"]:::external

    %% Data Flow Connections within Android SmartGlassesManager
    UI -->|"triggers"| SGService
    SGService -->|"initiates"| WS
    SGService -->|"calls"| JNIBridge
    WS -->|"streams audio/sensor data"| OggEnc
    OggEnc -->|"encodes audio"| Speech
    JNIBridge -->|"bridges native calls"| OggEnc
    Speech -->|"sends transcription"| Cloud
    Cloud -->|"returns transcription"| Speech
    SGService ---|"accesses"| Utils

    %% Connections from Companion Apps
    AndroidFE -->|"connects via WebSocket"| WS
    ExampleApp -->|"connects via WebSocket"| WS

    %% Connections to External Hardware
    WS -->|"WiFi/Bluetooth"| ExtHardware
    iOSSGM -->|"WiFi/Bluetooth"| ExtHardware

    %% Click Events for Component Mapping
    click ACore "https://github.com/augmentos-community/smartglassesmanager/tree/master/SGM_android/SmartGlassesManager"
    click SGService "https://github.com/augmentos-community/smartglassesmanager/blob/master/SGM_android/SmartGlassesManager/src/main/java/com/teamopensmartglasses/smartglassesmanager/SmartGlassesAndroidService.java"
    click WS "https://github.com/augmentos-community/smartglassesmanager/blob/master/SGM_android/SmartGlassesManager/src/main/java/com/teamopensmartglasses/smartglassesmanager/comms/AspWebsocketServer.java"
    click OggEnc "https://github.com/augmentos-community/smartglassesmanager/tree/master/SGM_android/SmartGlassesManager/src/main/cpp"
    click JNIBridge "https://github.com/augmentos-community/smartglassesmanager/tree/master/SGM_android/SmartGlassesManager/src/main/cpp/jni"
    click Speech "https://github.com/augmentos-community/smartglassesmanager/tree/master/SGM_android/SmartGlassesManager/src/main/java/com/teamopensmartglasses/smartglassesmanager/speechrecognition"
    click UI "https://github.com/augmentos-community/smartglassesmanager/tree/master/SGM_android/SmartGlassesManager/src/main/res/layout"
    click Utils "https://github.com/augmentos-community/smartglassesmanager/tree/master/SGM_android/SmartGlassesManager/src/main/java/com/teamopensmartglasses/smartglassesmanager/utils"
    click iOSSGM "https://github.com/augmentos-community/smartglassesmanager/blob/master/SGM_iOS/SGM/Sources/SGM/SGM.swift"
    click AndroidFE "https://github.com/augmentos-community/smartglassesmanager/blob/master/android_smart_glasses_frontend/main/app/src/main/java/com/wearableintelligencesystem/androidsmartglasses/comms/AsgWebSocketClient.java"
    click ExampleApp "https://github.com/augmentos-community/smartglassesmanager/blob/master/example_smart_glasses_app/app/src/main/java/com/teamopensmartglasses/example_smart_glasses_app/MainActivity.java"

    %% Styles
    classDef mobile fill:#c3e6cb,stroke:#2d572c,stroke-width:2px;
    classDef ui fill:#b3cde0,stroke:#264f78,stroke-width:2px;
    classDef service fill:#ccebc5,stroke:#357a38,stroke-width:2px;
    classDef native fill:#fbb4ae,stroke:#a63723,stroke-width:2px;
    classDef speech fill:#decbe4,stroke:#6a3d9a,stroke-width:2px;
    classDef utility fill:#ffffcc,stroke:#b5b53a,stroke-width:2px;
    classDef companion fill:#ffebcc,stroke:#d46a2e,stroke-width:2px;
    classDef external fill:#fddaec,stroke:#a64d79,stroke-width:2px;
```
