# bakigoal/android_kotlin-notifications architecture

> Architecture diagram of the GitHub repository bakigoal/android_kotlin-notifications, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bakigoal/android_kotlin-notifications
- Repository: https://github.com/bakigoal/android_kotlin-notifications

## Overview

##### Main Components

a. UI Layer:
- MainActivity (Entry point)
- EggTimerFragment (Main UI component)
- EggTimerViewModel (Business logic and state management)

b. Service Layer:
- AlarmService (Background timer service)

c. Broadcast Receivers:
- AlarmReceiver (Handles timer completion)
- SnoozeReceiver (Handles snooze functionality)

d. Utility Components:
- NotificationUtils (Notification management)
- BindingUtils (Data binding utilities)

**┌─ Presentation Layer ─────────────────┐**
- MainActivity                         │
- EggTimerFragment                 │
- EggTimerViewModel             │
- Service Layer ────────────────────┐
- AlarmService                       │
- Broadcast Receivers ──────────────┐
- AlarmReceiver                      │
- SnoozeReceiver                     │
- Utility Layer ───────────────────┐
- NotificationUtils                  │
- BindingUtils                      │

##### Data Flow Representation

Following interactions:
- EggTimerViewModel → AlarmService (Timer initialization)
- AlarmService → AlarmReceiver (Timer completion)
- AlarmReceiver → NotificationUtils (Notification creation)
- SnoozeReceiver → AlarmService (Reset timer)

##### Important Architectural Patterns to Highlight

a. MVVM Pattern:
- Clear separation between View (Fragment) and ViewModel
- Data binding connections

b. Observer Pattern:
- LiveData/Observable connections between ViewModel and Fragment

c. Service Pattern:
- Background service communication

##### Additional Elements

- Android System Components (AlarmManager, NotificationManager)
- Data binding connections
- Lifecycle awareness indicators
- Permission requirements
- Notification channels

##### Specific Implementation Notes

- Notification channel setup
- Timer state management flow
- Background processing constraints
- Foreground service components

This system design should effectively communicate both the static structure and dynamic behavior of the EggTimer application, with particular emphasis on the timer and notification mechanisms that are central to the app's functionality.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef ui fill:#90EE90,stroke:#333,stroke-width:2px
    classDef service fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef receiver fill:#FFD700,stroke:#333,stroke-width:2px
    classDef util fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef system fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef layout fill:#DDA0DD,stroke:#333,stroke-width:2px

    %% UI Layer
    subgraph Presentation
        MA[MainActivity]:::ui
        ETF[EggTimerFragment]:::ui
        ETVM[EggTimerViewModel]:::ui
        MAL["activity_main.xml"]:::layout
        ETFL["fragment_egg_timer.xml"]:::layout
        
        MA --> ETF
        ETF --> ETVM
        MA --> MAL
        ETF --> ETFL
    end

    %% Service Layer
    subgraph Service
        AS[AlarmService]:::service
        AM[AlarmManager]:::system
        
        AS --> AM
    end

    %% Broadcast Receivers
    subgraph Receivers
        AR[AlarmReceiver]:::receiver
        SR[SnoozeReceiver]:::receiver
    end

    %% Utility Layer
    subgraph Utilities
        NU[NotificationUtils]:::util
        BU[BindingUtils]:::util
        NM[NotificationManager]:::system
        
        NU --> NM
    end

    %% Relationships
    ETVM -.->|Timer Init| AS
    AS -.->|Timer Complete| AR
    AR -->|Create Notification| NU
    SR -->|Reset Timer| AS
    ETF -->|Data Binding| BU

    %% Click Events
    click MA "https://github.com/bakigoal/android_kotlin-notifications/blob/main/app/src/main/java/com/example/android/eggtimernotifications/MainActivity.kt"
    click ETF "https://github.com/bakigoal/android_kotlin-notifications/blob/main/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt"
    click ETVM "https://github.com/bakigoal/android_kotlin-notifications/blob/main/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerViewModel.kt"
    click AS "https://github.com/bakigoal/android_kotlin-notifications/blob/main/app/src/main/java/com/example/android/eggtimernotifications/service/AlarmService.kt"
    click AR "https://github.com/bakigoal/android_kotlin-notifications/blob/main/app/src/main/java/com/example/android/eggtimernotifications/receiver/AlarmReceiver.kt"
    click SR "https://github.com/bakigoal/android_kotlin-notifications/blob/main/app/src/main/java/com/example/android/eggtimernotifications/receiver/SnoozeReceiver.kt"
    click NU "https://github.com/bakigoal/android_kotlin-notifications/blob/main/app/src/main/java/com/example/android/eggtimernotifications/util/NotificationUtils.kt"
    click BU "https://github.com/bakigoal/android_kotlin-notifications/blob/main/app/src/main/java/com/example/android/eggtimernotifications/util/BindingUtils.kt"
    click MAL "https://github.com/bakigoal/android_kotlin-notifications/blob/main/app/src/main/res/layout/activity_main.xml"
    click ETFL "https://github.com/bakigoal/android_kotlin-notifications/blob/main/app/src/main/res/layout/fragment_egg_timer.xml"

    %% Legend
    subgraph Legend
        L1[UI Components]:::ui
        L2[Services]:::service
        L3[Receivers]:::receiver
        L4[Utilities]:::util
        L5[System Services]:::system
        L6[Layouts]:::layout
    end
```
