# faamaral/medtime architecture

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

- Interactive diagram: https://gitdiagram.com/faamaral/medtime
- Repository: https://github.com/faamaral/medtime

## Overview

##### Main Components
- Mobile Client/UI Layer: Represent the user interface built with Jetpack Compose. This layer consists of various screens (HomeScreen, Login, Signup, CreateEditMedicamentoScreen, etc.) and UI components (e.g., AppBar, Custom TextFields, DatePicker, TimePicker).
- ViewModel/Presentation Layer: Include the viewmodels (AuthViewModel, MedicamentoViewModel, UserViewModel) that encapsulate the UI logic and interact with the underlying services and repositories.
- Data Layer: This layer comprises the database modules and local storage functionalities including:
- Room database (MedtimeDatabase)
- DAOs (MedicamentoDao, HorariosDao)
- Repositories (MedicamentoRepository, UserRepository)
- Data models/entities (Medicamento, MedicamentoEntity, User, etc.)
- Service/Background Work Layer: Represent the notification services responsible for scheduling alarms and sending reminders. Components include:
- Notification-related services (AlarmScheduler, NotificationServices, Notifier, etc.)
- Notification workers and receivers (MedicamentoNotificationWorker, AlarmReceiver, MedicamentoNotificationReceiver)
- External Services: Display external dependencies like Firebase Cloud Firestore (and integration via google-services.json) which handle authentication and possibly remote data syncing.

##### Dependencies and Interactions
- Similarly, present a notification flow where the Notification or Alarm services (AlarmScheduler, NotificationWorker) are triggered either by the ViewModel logic or by time-based events, and then they interact with the system’s receivers to display notifications.

##### Architectural Patterns and Design Principles
- MVVM (Model-View-ViewModel) as the core architectural approach:
- Model = Data layer (database/entities, network if applicable)
- ViewModel = Business logic (viewmodels and services)
- View = UI components and screens.
- Separation of concerns by clearly differentiating the responsibilities of UI, data, and background processing.

##### Relevant Technologies
- Kotlin: Main programming language.
- Jetpack Compose: UI layer framework.
- Room: For local database operations.
- Firebase Cloud Firestore: For authentication and remote data storage.
- Android WorkManager/AlarmManager: For scheduling notifications.
- Gradle (Kotlin DSL): Build tool and dependency management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Mobile Client/UI Layer"
        A["Screens"]:::ui
        B["UI Components"]:::ui
    end

    subgraph "ViewModel/Presentation Layer"
        C["ViewModels"]:::viewmodel
    end

    subgraph "Data Layer"
        D["Room Database"]:::database
        E["DAOs"]:::database
        F["Repositories"]:::database
        G["Data Models"]:::database
    end

    subgraph "Service/Background Work Layer"
        H["Notification Services/Workers"]:::service
        I["Receivers"]:::service
    end

    subgraph "External Services"
        J["Firebase Integration"]:::external
    end

    %% Relationships
    A -->|"toViewModel"| C
    B -->|"usedByScreens"| A
    C -->|"accessRepository"| F
    F -->|"callsDAO"| E
    E -->|"persistedIn"| D
    F -->|"usesModel"| G
    C -->|"scheduleNotification"| H
    H -->|"triggers"| I
    A -->|"authRequest"| J
    C -->|"authProcess"| J

    %% Click Events
    click A "https://github.com/faamaral/medtime/tree/main/app/src/main/java/com/digitaldose/medtime/ui/screens"
    click B "https://github.com/faamaral/medtime/tree/main/app/src/main/java/com/digitaldose/medtime/ui/components"
    click C "https://github.com/faamaral/medtime/tree/main/app/src/main/java/com/digitaldose/medtime/viewmodels"
    click D "https://github.com/faamaral/medtime/blob/main/app/src/main/java/com/digitaldose/medtime/database/MedtimeDatabase.kt"
    click E "https://github.com/faamaral/medtime/tree/main/app/src/main/java/com/digitaldose/medtime/database/dao"
    click F "https://github.com/faamaral/medtime/tree/main/app/src/main/java/com/digitaldose/medtime/database/repositories"
    click G "https://github.com/faamaral/medtime/tree/main/app/src/main/java/com/digitaldose/medtime/database/models"
    click H "https://github.com/faamaral/medtime/tree/main/app/src/main/java/com/digitaldose/medtime/services/notification"
    click I "https://github.com/faamaral/medtime/tree/main/app/src/main/java/com/digitaldose/medtime/services/receiver"
    click J "https://github.com/faamaral/medtime/blob/main/app/src/debug/google-services.json"

    %% Styles
    classDef ui fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef viewmodel fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
    classDef database fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef service fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
    classDef external fill:#f0f4c3,stroke:#827717,stroke-width:2px;
```
