# tomsk-smart-tech/smart-alarm architecture

> Architecture diagram of the GitHub repository tomsk-smart-tech/smart-alarm, 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/tomsk-smart-tech/smart-alarm
- Repository: https://github.com/tomsk-smart-tech/smart-alarm

## Overview

##### Project Type and Purpose
- This is an Android mobile application built to manage “Smart Alarm” functionality.
- Its main purpose is to allow users to create and manage alarms with flexible schedules and settings, backed by IoT integration (via MQTT and HiveMQ) and a modern UI built with Jetpack Compose.
- The app also incorporates features such as calendar events and multimedia playback controls.

##### File Structure for Architectural Clues
- The project is organized under an “app” directory typical for Android projects.
- There are clear separations for different features:
- UI components (layouts and theming under ui/theme, several Screen classes such as HomeScreen, MusicScreen, AlarmScreen, PlaybackControlScreen).
- Domain/logic layers (alarm, calendar, mqtt, shared data).
- Test directories for unit and instrumentation tests indicating a separation of concerns and testing strategy.
- Specific modules inside the package include:
- Alarm module: Contains classes like Alarm, AlarmReceiver, AlarmService, MqttCheckService, and SingleAlarmManager.
- MQTT module: Hosts MqttService, MqttObserver, and AlarmObserver to manage IoT communication.
- Calendar module: Contains CalendarEvents for scheduling integration.
- HTTP integration: The presence of an HttpController hints at additional network interactions.
- There is configuration support for build and dependency management (build.gradle.kts, gradle wrapper files).

##### Instructing the Principal Software Engineer
- As much detail as possible by separating the core functions into distinct components:
- One block each for Alarm Management, MQTT Communication, Calendar Events, and UI Rendering.
- A connection to a potential HTTP integration module if applicable.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Mobile Application Shell
    subgraph "Mobile Application Shell"
        MA1["AndroidManifest.xml"]:::mobile
        MA2["MainActivity.kt"]:::mobile
    end

    %% UI Layer
    subgraph "UI Layer"
        UI1["HomeScreen"]:::ui
        UI2["AlarmScreen"]:::ui
        UI3["MusicScreen"]:::ui
        UI4["PlaybackControlScreen"]:::ui
        UI5["Color.kt"]:::ui
        UI6["Theme.kt"]:::ui
        UI7["Type.kt"]:::ui
    end

    %% Business Logic / Controller Layer
    subgraph "Business Logic / Controller Layer"
        BL1["SharedData"]:::logic
        BL2["HttpController"]:::logic
    end

    %% Service Modules
    subgraph "Service Modules"
        %% Alarm Management Module
        subgraph "Alarm Management"
            AM1["Alarm"]:::service
            AM2["AlarmReceiver"]:::service
            AM3["AlarmService"]:::service
            AM4["MqttCheckService"]:::service
            AM5["SingleAlarmManager"]:::service
        end
        %% Calendar Management Module
        subgraph "Calendar Management"
            CM1["CalendarEvents"]:::service
        end
        %% MQTT Communication Module
        subgraph "MQTT Communication"
            MQ1["MqttService"]:::service
            MQ2["MqttObserver"]:::service
            MQ3["AlarmObserver"]:::service
        end
    end

    %% External System
    EX["External HiveMQ Platform"]:::external

    %% Connections between layers
    MA2 -->|"launches"| UI1
    UI1 -->|"triggers"| BL1
    UI2 -->|"triggers"| BL1
    UI3 -->|"triggers"| BL1
    UI4 -->|"triggers"| BL1
    BL1 -->|"sets alarm"| AM1
    BL1 -->|"schedules"| CM1
    BL2 -->|"initiates"| MQ1

    %% Internal Alarm Management Flow
    AM1 -->|"triggers"| AM2
    AM2 -->|"starts"| AM3
    AM3 -->|"manages"| AM5
    AM3 -->|"checksMQTT"| AM4

    %% Internal MQTT Communication Flow
    MQ1 -->|"notifies"| MQ2
    MQ2 -->|"alerts"| MQ3

    %% External Communication
    MQ1 <==>|"sync"| EX

    %% Styles
    classDef mobile fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef ui fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef logic fill:#D6EAF8,stroke:#2980B9,stroke-width:2px;
    classDef service fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#F39C12,stroke-width:2px;

    %% Click Events
    click MA1 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/AndroidManifest.xml"
    click MA2 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/MainActivity.kt"
    click UI1 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/home/HomeScreen.kt"
    click UI2 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/alarm/AlarmScreen.kt"
    click UI3 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/MusicScreen.kt"
    click UI4 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/playback/PlaybackControlScreen.kt"
    click UI5 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/ui/theme/Color.kt"
    click UI6 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/ui/theme/Theme.kt"
    click UI7 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/ui/theme/Type.kt"
    click BL1 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/SharedData.kt"
    click BL2 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/HttpController.kt"
    click AM1 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/alarm/Alarm.kt"
    click AM2 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/alarm/AlarmReceiver.kt"
    click AM3 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/alarm/AlarmService.kt"
    click AM4 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/alarm/MqttCheckService.kt"
    click AM5 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/alarm/SingleAlarmManager.kt"
    click CM1 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/calendar/CalendarEvents.kt"
    click MQ1 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/mqtt/MqttService.kt"
    click MQ2 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/mqtt/MqttObserver.kt"
    click MQ3 "https://github.com/tomsk-smart-tech/smart-alarm/blob/main/app/src/main/java/com/tomsksmarttech/smart_alarm_mobile/mqtt/AlarmObserver.kt"
```
