# ujizin/leafy architecture

> Architecture diagram of the GitHub repository ujizin/leafy, 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/ujizin/leafy
- Repository: https://github.com/ujizin/leafy

## Overview

##### Primary Modules/Components
- App Module: This is the main Android entry point (with MainActivity and the Application class) that bootstraps the app. It ties together the UI layer and orchestrates the high-level configuration.
- Domain Layer: Encapsulated within the “domain” module, this layer includes:
– Business models (e.g., Alarm, Plant, User, Ringtone)
– Repository interfaces and use cases (for adding, updating, deleting, or loading plants, alarms, files, etc.)
- Data/Local Modules: These are found in “core/local” and “core/repository”, where:
– Room’s DAOs and database implementations are provided
– Local data sources, mappers, and conversion logic connect the persistent storage to domain models
- Core Modules: Such as “core/navigation”, “core/themes”, and “core/ui” that supply common infrastructure:
– Navigation definitions (using Navigation Compose)
– Reusable UI components, including animated buttons, card components, and scaffold structures
- Features Modules: Each feature (alarm, camera, home, plant, preferences, publish, search, tasks, etc.) is implemented in its own module:
– They encapsulate UI screens, view models, and feature-specific logic
– They interact with the domain layer (via use cases) as well as with the UI components and navigation modules

##### Interactions and Data Flow
- The App Module (or “driving adapters”) calls into the UI built with Jetpack Compose.
- UI Components in the Core and Features modules use ViewModels that in turn call Use Cases provided by the Domain module.
- Use Cases (domain logic) rely on repositories (injected via Hilt) provided by the Repository module to access data from the Local (Room) layer.
- The Navigation and Themes modules provide additional cross-cutting concerns (routing and styling) to ensure consistency across the user interfaces.
- Hilt is used for Dependency Injection, binding modules and enabling loose coupling between layers.
- The hexagonal design is evident in the separation of “inward” adapters (UI, features) and “outward” adapters (data persistence, local repositories) where the core domain logic sits in the center.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        AppModule["App Module\n(Android Entry Point)"]:::presentation
        CoreUI["Core UI Module\n(Reusable UI Components)"]:::presentation
        FeatureAlarm["Feature – Alarm"]:::presentation
        FeatureCamera["Feature – Camera"]:::presentation
        FeatureHome["Feature – Home"]:::presentation
        FeaturePlant["Feature – Plant Management"]:::presentation
        FeaturePreferences["Feature – Preferences"]:::presentation
        FeaturePublish["Feature – Publish"]:::presentation
        FeatureSearch["Feature – Search"]:::presentation
        FeatureTasks["Feature – Tasks"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        Domain["Domain Layer\n(Business Logic, Use Cases, Models)"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        Repository["Repository Module\n(Repository Interfaces)"]:::infrastructure
        LocalData["Local Data Module\n(Room, DAOs)"]:::infrastructure
    end

    %% Cross-Cutting Services
    subgraph "Cross-Cutting Services"
        Navigation["Navigation Module\n(Navigation Compose)"]:::crosscut
        Themes["Themes Module\n(Styling, Colors)"]:::crosscut
    end

    %% Connections from Presentation to Domain
    AppModule -->|"bootstraps"| Domain
    CoreUI -->|"calls"| Domain
    FeatureAlarm -->|"triggers"| Domain
    FeatureCamera -->|"triggers"| Domain
    FeatureHome -->|"triggers"| Domain
    FeaturePlant -->|"triggers"| Domain
    FeaturePreferences -->|"triggers"| Domain
    FeaturePublish -->|"triggers"| Domain
    FeatureSearch -->|"triggers"| Domain
    FeatureTasks -->|"triggers"| Domain

    %% Connections from Domain to Infrastructure
    Domain -->|"calls"| Repository
    Repository -->|"fetch/store"| LocalData

    %% Connections from Cross-Cutting Services to Presentation
    Navigation -->|"routing"| AppModule
    Themes -->|"theming"| CoreUI

    %% Click Events
    click AppModule "https://github.com/ujizin/leafy/tree/main/app/"
    click Domain "https://github.com/ujizin/leafy/tree/main/domain/"
    click LocalData "https://github.com/ujizin/leafy/tree/main/core/local/"
    click Repository "https://github.com/ujizin/leafy/tree/main/core/repository/"
    click Navigation "https://github.com/ujizin/leafy/tree/main/core/navigation/"
    click Themes "https://github.com/ujizin/leafy/tree/main/core/themes/"
    click CoreUI "https://github.com/ujizin/leafy/tree/main/core/ui/"
    click FeatureAlarm "https://github.com/ujizin/leafy/tree/main/features/alarm/"
    click FeatureCamera "https://github.com/ujizin/leafy/tree/main/features/camera/"
    click FeatureHome "https://github.com/ujizin/leafy/tree/main/features/home/"
    click FeaturePlant "https://github.com/ujizin/leafy/tree/main/features/plant/"
    click FeaturePreferences "https://github.com/ujizin/leafy/tree/main/features/preferences/"
    click FeaturePublish "https://github.com/ujizin/leafy/tree/main/features/publish/"
    click FeatureSearch "https://github.com/ujizin/leafy/tree/main/features/search/"
    click FeatureTasks "https://github.com/ujizin/leafy/tree/main/features/tasks/"

    %% Styles
    classDef presentation fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef domain fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef infrastructure fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef crosscut fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
```
