# adrcotfas/goodtime architecture

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

- Interactive diagram: https://gitdiagram.com/adrcotfas/goodtime
- Repository: https://github.com/adrcotfas/goodtime

## Overview

##### Project type and purpose
- Goodtime is a Kotlin Multiplatform Mobile (KMM) productivity timer app with two native frontends (Android + iOS) that share a common business-logic and data layer.
- Its goal is to provide a minimalist Pomodoro-style timer, local data persistence, backup/restore, notifications, and in-app billing (Google Play & F-Droid).

##### File structure
- Top-level modules:
- androidApp — Android UI (Jetpack Compose), platform services, build config, flavors (Google vs. F-Droid billing).
- iosApp — iOS UI (SwiftUI), Xcode project, Info.plist, assets.
- shared — commonMain, androidMain, iosMain, plus test sources, schemas — contains domain, data, DI, and expect/actual platform bindings.
- CI/CD/Localization: .circleci/config.yml (build pipeline), crowdin.yml (translations).
- Build tooling: Gradle (libs.versions.toml), Gradle Wrapper, Kotlin DSL.

##### README
- Confirms it’s a minimalist productivity timer for Android & iOS.
- Mentions background alarms (AlarmManager), battery-optimization workarounds, and links to Android OEM considerations.

##### Main components & relationships
A. Native Frontends
- Android App
– UI layer (Compose screens, Activities)
– Platform services: AlarmManagerHandler, TimerServiceStarter, NotificationArchManager, AutoBackupWorker, BillingAbstract → GoogleBilling/FdroidBilling
– AndroidManifest, flavour-specific modules (FlavorModule.kt)
- iOS App
– SwiftUI view (ContentView.swift), App entry point (iOSApp.swift)
– expect/actual implementations for TimeProvider, Database, DI modules
– Local notifications, background tasks, AppSettings via DataStore

B. Shared Module (commonMain)
- ViewModels (TimerViewModel, SettingsViewModel, StatisticsViewModel, etc.)
- Business Logic (TimerManager, FinishedSessionsHandler, SessionResetHandler)
- Data Layer
– LocalDataRepository (implements CRUD via DAOs)
– DAOs & database schema (expect Database.kt + actual Database.android.kt / Database.ios.kt)
– SettingsRepository (.proto DataStore or similar)
– BackupManager (export/import JSON)
- DI Modules (AppModule, ViewModelModule, LocalDataModule, TimerManagerModule)
- Common utilities (TimeUtils, DurationExtension)

C. External Services
- Google Play Billing, F-Droid billing
- Local database storage (Room on Android; SQLite/CoreData on iOS)
- File system for backup/restore
- Localization via Crowdin
- CI/CD via CircleCI

D. Build & Deployment
- Gradle for shared + Android
- Xcode for iOS
- Flavor configurations for billing implementations
- Continuous Integration pipeline triggering tests on shared + Android

##### Architectural patterns and design principles
- MVVM: UI → ViewModel → Business Logic → Data Repository
- Layering: UI (Compose/SwiftUI), Presentation (ViewModels), Domain (TimerManager), Data (Repository, DAOs), Platform (expect/actual)
- Dependency Injection: manual modules loaded at runtime per platform
- KMM expect/actual pattern for platform abstractions
- Flavor-based builds for billing strategies

##### Final advice
- Be exhaustive: every package/folder can be grouped into one of the layers above.
- Don’t overcomplicate: separate by logical responsibility, not individual classes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Android App Layer
    subgraph "Android App" 
        direction TB
        AndroidUI["Android App UI Layer"]:::ui
        PlatformServices["Android Platform Services"]:::platform
        Backup["Android Backup Components"]:::platform
        BillingAbstract["BillingAbstract"]:::platform
        GoogleBilling["GoogleBilling"]:::platform
        FdroidBilling["FdroidBilling"]:::platform
    end

    %% iOS App Layer
    subgraph "iOS App"
        direction TB
        iOSUI["iOS App UI Layer"]:::ui
        iOSBindings["iOS Actual Platform Bindings"]:::platform
    end

    %% Shared Module
    subgraph "Shared Module"
        direction TB
        subgraph "Presentation (ViewModels)"
            SharedPresentation["ViewModels"]:::presentation
        end
        subgraph "Domain Logic"
            Domain["TimerManager & Handlers"]:::domain
        end
        subgraph "Data Layer"
            Data["Repository, DAOs, BackupManager"]:::data
        end
        subgraph "Dependency Injection"
            DI["DI Modules"]:::injection
        end
        subgraph "Android Bindings"
            AndroidBindings["Android Actual Platform Bindings"]:::platform
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GooglePlay["Google Play Billing"]:::external
        FDroidService["F-Droid Billing"]:::external
        DB["Local Database Storage"]:::external
        FileSys["File System (Backup/Restore)"]:::external
        Localization["Localization (Crowdin)"]:::external
        CICD["CI/CD (CircleCI)"]:::external
    end

    %% Connections
    AndroidUI -->|"uses"| SharedPresentation
    iOSUI -->|"uses"| SharedPresentation

    SharedPresentation -->|"interacts with"| Domain
    Domain -->|"persists via"| Data
    Data -->|"stores in"| DB
    Data -->|"exports via"| FileSys

    SharedPresentation -->|"injected by"| DI
    DI -->|"provides to"| Domain
    DI -->|"provides to"| Data

    PlatformServices -->|"binds to"| AndroidBindings
    iOSBindings -->|"binds to"| Domain

    BillingAbstract -->|"implemented by"| GoogleBilling
    BillingAbstract -->|"implemented by"| FdroidBilling
    GoogleBilling -->|"connects to"| GooglePlay
    FdroidBilling -->|"connects to"| FDroidService

    Backup -->|"schedules via"| Backup
    Backup -->|"reads/writes"| FileSys

    Localization -->|"feeds strings to"| SharedPresentation
    CICD -->|"builds/tests"| SharedPresentation
    CICD -->|"builds/tests"| AndroidUI

    %% Click Events
    click AndroidUI "https://github.com/adrcotfas/goodtime/tree/master/androidApp/src/main/java/com/apps/adrcotfas/goodtime/main"
    click PlatformServices "https://github.com/adrcotfas/goodtime/tree/master/androidApp/src/main/java/com/apps/adrcotfas/goodtime/bl"
    click Backup "https://github.com/adrcotfas/goodtime/blob/master/androidApp/src/main/java/com/apps/adrcotfas/goodtime/backup/AutoBackupManager.kt"
    click Backup "https://github.com/adrcotfas/goodtime/blob/master/androidApp/src/main/java/com/apps/adrcotfas/goodtime/backup/AutoBackupWorker.kt"
    click BillingAbstract "https://github.com/adrcotfas/goodtime/blob/master/androidApp/src/main/java/com/apps/adrcotfas/goodtime/billing/BillingAbstract.kt"
    click GoogleBilling "https://github.com/adrcotfas/goodtime/blob/master/androidApp/src/google/java/com/apps/adrcotfas/goodtime/billing/GoogleBilling.kt"
    click FdroidBilling "https://github.com/adrcotfas/goodtime/blob/master/androidApp/src/fdroid/java/com/apps/adrcotfas/goodtime/billing/FdroidBilling.kt"
    click SharedPresentation "https://github.com/adrcotfas/goodtime/tree/master/shared/src/commonMain/kotlin/com/apps/adrcotfas/goodtime/main"
    click Domain "https://github.com/adrcotfas/goodtime/blob/master/shared/src/commonMain/kotlin/com/apps/adrcotfas/goodtime/bl/TimerManager.kt"
    click Data "https://github.com/adrcotfas/goodtime/blob/master/shared/src/commonMain/kotlin/com/apps/adrcotfas/goodtime/data/local/LocalDataRepository.kt"
    click DI "https://github.com/adrcotfas/goodtime/blob/master/shared/src/commonMain/kotlin/com/apps/adrcotfas/goodtime/di/AppModule.kt"
    click AndroidBindings "https://github.com/adrcotfas/goodtime/tree/master/shared/src/androidMain/kotlin/com/apps/adrcotfas/goodtime"
    click iOSUI "https://github.com/adrcotfas/goodtime/blob/master/iosApp/iosApp/ContentView.swift"
    click iOSBindings "https://github.com/adrcotfas/goodtime/tree/master/shared/src/iosMain/kotlin/com/apps/adrcotfas/goodtime"
    click CICD "https://github.com/adrcotfas/goodtime/blob/master/.circleci/config.yml"
    click Localization "https://github.com/adrcotfas/goodtime/blob/master/shared/src/main/res/values-*/strings_*.xml"

    %% Styles
    classDef ui fill:#D0E6FF,stroke:#0366D6,color:#0366D6
    classDef presentation fill:#E6F7D0,stroke:#3C763D,color:#3C763D
    classDef domain fill:#FFE6D0,stroke:#D2691E,color:#D2691E
    classDef data fill:#FFF5D0,stroke:#E6A800,color:#E6A800
    classDef injection fill:#F0D0FF,stroke:#6A0DAD,color:#6A0DAD
    classDef platform fill:#E0E0E0,stroke:#666666,color:#666666
    classDef external fill:#F5D0D0,stroke:#A00000,color:#A00000
```
