# akm0012/beachbuddy_android_2 architecture

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

- Interactive diagram: https://gitdiagram.com/akm0012/beachbuddy_android_2
- Repository: https://github.com/akm0012/beachbuddy_android_2

## Overview

a. Presentation/UI Layer:
- Activities (MainActivity, TvActivity) and Fragments (DashboardFragment, RequestedItemsFragment, ScoreManagementFragment, etc.).
- Custom Views and UI widgets, including compound views (e.g., BeachConditionsView, CurrentWeatherView) and view models (e.g., DashboardViewModel, CurrentUvViewModel).
b. Domain/Business Logic Layer:
- ViewModels: Separate classes for each UI component logic (found in both ui/viewmodels and viewmodels directories).
- Repositories: Classes that encapsulate data operations (DashboardRepository, FirebaseRepository, RequestedItemRepository, ScoreRepository).
c. Data Layer:
- Local persistence: Room-based database with AppDatabase, DAOs, and data models (e.g., BeachConditions, CurrentWeather, and related entities).
- Network module: Includes DTOs, API service interfaces (e.g., ApiService, ApiServiceEndpointInterface), network interceptors (ErrorInterceptor, SecretHeaderInterceptor), and request objects.
d. Dependency Injection:
- Modules such as DatabaseModule and NetworkModule, which provide the wiring of dependencies using Hilt/Dagger.
e. Work Manager / Background Services:
- Workers like PruneDatabaseWorker that manage background tasks.
f. External Services / Integrations:
- Firebase Messaging Service (MyFirebaseMessagingService).
- The .NET Core backend (hinted in the README) along with Twilio, external API calls, and caching. These external services should be represented as separate components interacting with the Network Layer.

##### Flow and interactions between components
- Synchronous interactions (such as calling repository functions from ViewModels) and asynchronous data flows (using Kotlin coroutines/Flows).
- A connection from the FirebaseMessagingService to the backend components if push notifications are being triggered.

##### Distinguish layers and protocols
- Yet another shade for the Data Layer (e.g., orange) where you include both Room (database with DAOs) and Network communications (DTOs, API Service, interceptors).
- A separate set of elements for external integrations (e.g., gray or red) showing Firebase, .NET backend, Twilio, and external APIs.
- Dependency injection used by modules (DatabaseModule, NetworkModule) to show the inversion of control pattern.

##### Architectural patterns and key technologies
- That the project is built using an MVVM pattern. Clearly illustrate how the UI (Activity/Fragment) binds to the ViewModel, which in turn interacts with repositories.
- Point out the use of dependency injection (Hilt/Dagger) and the separation of concerns between network, persistence, and presentation.
- Mention the use of Android’s Room for local storage and Kotlin Coroutines/Flows for asynchronous operations.
- If applicable, detail how WorkManager (PruneDatabaseWorker) is scheduled to clean or prune the database.

##### Final checklist
- Notes for any significant inter-layer interactions, such as asynchronous data fetching and dependency injection configurations.

This thorough representation will ensure the essential architectural elements—ranging from the UI components to repository abstraction and network/database integration along with external services—are clearly captured. This level of detail will be invaluable for both understanding the current design and planning further development or enhancements.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation/UI Layer
    subgraph "Presentation/UI Layer"
        UI1["MainActivity"]:::uiStyle
        UI2["TvActivity"]:::uiStyle
        UI3["DashboardFragment"]:::uiStyle
        UI4["RequestedItemsFragment"]:::uiStyle
        UI5["ScoreManagementFragment"]:::uiStyle
        UI6["BeachConditionsView"]:::uiStyle
        UI7["CurrentWeatherView"]:::uiStyle
    end

    %% Domain/Business Logic Layer
    subgraph "Domain/Business Logic Layer"
        D1["DashboardViewModel"]:::domainStyle
        D2["RequestedItemViewModel"]:::domainStyle
        D3["ScoreManagementViewModel"]:::domainStyle
        D4["CurrentWeatherViewModel"]:::domainStyle
        D5["CurrentUvViewModel"]:::domainStyle
        D6["DashboardRepository"]:::domainStyle
        D7["FirebaseRepository"]:::domainStyle
        D8["RequestedItemRepository"]:::domainStyle
        D9["ScoreRepository"]:::domainStyle
    end

    %% Data Layer
    subgraph "Data Layer"
        subgraph "Local Persistence (Room)"
            DL1["AppDatabase"]:::dataStyle
            DL2["DAOs"]:::dataStyle
        end
        subgraph "Network Module"
            DN1["DTOs"]:::dataStyle
            DN2["API Service"]:::dataStyle
            DN3["Interceptors"]:::dataStyle
            DN4["Request Objects"]:::dataStyle
        end
    end

    %% Dependency Injection
    subgraph "Dependency Injection"
        DI1["DatabaseModule"]:::diStyle
        DI2["NetworkModule"]:::diStyle
    end

    %% Background Services
    subgraph "Background Services"
        W1["PruneDatabaseWorker"]:::workStyle
    end

    %% External Services / Integrations
    subgraph "External Services / Integrations"
        EX1["Firebase Messaging Service"]:::externalStyle
        EX2["Backend Integration (.NET Core, Twilio, external APIs)"]:::externalStyle
    end

    %% UI Layer to Domain Connections
    UI1 -->|"binds"| D1
    UI3 -->|"binds"| D1
    UI4 -->|"binds"| D2
    UI5 -->|"binds"| D3
    UI7 -->|"binds"| D4
    UI6 -->|"binds"| D1

    %% Domain to Repository Connections
    D1 -->|"calls"| D6
    D2 -->|"calls"| D8
    D3 -->|"calls"| D9
    D4 -->|"calls"| D6
    D5 -->|"calls"| D6

    %% Repository to Data Layer Connections
    D6 -->|"accesses"| DL1
    D6 -->|"communicates"| DN2
    D7 -->|"communicates"| DN2
    D8 -->|"accesses"| DL1
    D8 -->|"communicates"| DN2
    D9 -->|"accesses"| DL1
    D9 -->|"communicates"| DN2

    %% Dependency Injection Wiring
    DI1 -->|"provides"| DL1
    DI2 -->|"provides"| DN2
    DI2 -->|"provides"| DN3
    DI2 -->|"provides"| DN4

    %% Work Manager Interaction
    W1 -->|"works with"| DL1

    %% External Services Interaction
    DN2 -->|"calls"| EX2
    EX1 -->|"triggers"| EX2

    %% Click Events for Presentation/UI Layer
    click UI1 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/ui/MainActivity.kt"
    click UI2 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/ui/TvActivity.kt"
    click UI3 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/ui/fragments/DashboardFragment.kt"
    click UI4 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/ui/fragments/RequestedItemsFragment.kt"
    click UI5 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/ui/fragments/ScoreManagementFragment.kt"
    click UI6 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/ui/views/BeachConditionsView.kt"
    click UI7 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/ui/views/CurrentWeatherView.kt"

    %% Click Events for Domain/Business Logic Layer
    click D1 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/viewmodels/DashboardViewModel.kt"
    click D2 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/viewmodels/RequestedItemViewModel.kt"
    click D3 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/viewmodels/ScoreManagementViewModel.kt"
    click D4 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/ui/views/viewmodels/CurrentWeatherViewModel.kt"
    click D5 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/ui/views/viewmodels/CurrentUvViewModel.kt"
    click D6 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/repository/DashboardRepository.kt"
    click D7 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/repository/FirebaseRepository.kt"
    click D8 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/repository/RequestedItemRepository.kt"
    click D9 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/repository/ScoreRepository.kt"

    %% Click Events for Data Layer
    click DL1 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/database/AppDatabase.kt"
    click DL2 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/database/dao/BeachConditionsDao.kt"
    click DN2 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/network/service/ApiService.kt"
    click DN3 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/network/interceptors/SecretHeaderInterceptor.kt"
    click DN4 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/network/requests/AddDeviceRequest.kt"

    %% Click Events for Dependency Injection
    click DI1 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/inject/DatabaseModule.kt"
    click DI2 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/inject/NetworkModule.kt"

    %% Click Event for Background Services
    click W1 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/work/PruneDatabaseWorker.kt"

    %% Click Event for External Services
    click EX1 "https://github.com/akm0012/beachbuddy_android_2/blob/master/app/src/main/java/com/andrewkingmarshall/beachbuddy2/MyFirebaseMessagingService.kt"

    %% Styles
    classDef uiStyle fill:#ADD8E6,stroke:#1E90FF,stroke-width:2px,font-size:12px;
    classDef domainStyle fill:#90EE90,stroke:#228B22,stroke-width:2px,font-size:12px;
    classDef dataStyle fill:#FFD580,stroke:#FF8C00,stroke-width:2px,font-size:12px;
    classDef diStyle fill:#E6E6FA,stroke:#9370DB,stroke-width:2px,font-size:12px;
    classDef workStyle fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px,font-size:12px;
    classDef externalStyle fill:#F08080,stroke:#DC143C,stroke-width:2px,font-size:12px;
```
