# civil31dot5/fitness-diary architecture

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

- Interactive diagram: https://gitdiagram.com/civil31dot5/fitness-diary
- Repository: https://github.com/civil31dot5/fitness-diary

## Overview

##### Project Type and Purpose
- The README confirms that the app helps users review their dietary intake, track exercise routines (by interfacing with Strava), and monitor changes in body statistics with photo records.

##### File Structure
- The project is organized into multiple Gradle modules: “app” (main Android application module), “common” (possibly shared utilities or functionality), “data” (handling database access, network calls, and repository implementations), “domain” (contains business models, use cases, repository interfaces, and domain logic), and “testing” (module for unit and instrumentation tests).
- The “app” module holds the UI components; you see extensive use of Jetpack Compose with navigation, view models (MVVM pattern), dependency injection (Hilt set up in di packages), and other typical Android resources.
- The “data” module includes implementation details such as Room database setup, network models using ktor and serialization, data mappers, and background workers for tasks like backup and syncing Strava data.
- The “domain” layer houses the core business logic with use cases (e.g., GetMonthRecordStatusUseCase, BackupDataUseCase, ConnectStravaUseCase), domain models, and repository interfaces ensuring a clean separation between presentation and data logic.
- Additionally, there is a “common” module for shared functionalities and a “testing” module dedicated to tests across the system.

a. Main Components:
- UI Layer: Presented in the “app” module. It includes components like MainActivity, various Jetpack Compose screens (HomeScreen, BackupRestoreDataScreen, AddRecordScreen, etc.), and corresponding ViewModels which follow MVVM.
- Domain Layer: Found in the “domain” module, containing business models, repository interfaces, and use cases for handling core business logic (diet, sport, bodyshape, backup/restore, report generation).
- Data Layer: Located in the “data” module. This module provides data handling through database entities (with Room), network services for Strava integration, repository implementations (RecordRepositoryImpl, StravaRepositoryImpl, BackupRestoreDataRepositoryImpl), data mappers, and background workers.
- Common Module: Likely contains utilities and shared components used by multiple modules across the application.
- External Services: Integration with Strava for fetching exercise records. The network layer handles OAuth and JSON parsing.
- Dependency Injection: Implemented through Hilt as seen in various “di” packages, ensuring dependencies are managed across the UI, domain, and data layers.

b. Relationships and Interactions:
- The UI layer (app) interacts with the Domain layer via ViewModels that call use cases.
- The Domain layer communicates with the Data layer through repository interfaces to abstract data source details.
- The Data layer retrieves data from local databases (via Room) and external APIs (via ktor for Strava), then maps it to domain models.
- DI (using Hilt) ties these components together, ensuring that ViewModels, use cases, and repository implementations are properly injected.
- Background workers in the Data layer handle data synchronization tasks and notifications.

c. Architectural Patterns & Design Principles:
- MVVM Architecture: Clearly separated UI (View & ViewModel) and business logic (use cases in the domain layer).
- Clean Architecture: Separation between presentation, domain, and data layers.
- Dependency Injection (Hilt) is used to manage component dependencies.
- Modular architecture is evident from the separation into app, data, domain, common, and testing modules.

d. Relevant Technologies, Frameworks, and Libraries:
- Jetpack Compose for the UI.
- Kotlin with Coroutines and Flow for asynchronous programming.
- Hilt for dependency injection.
- Room for local data persistence.
- ktor & Serialization for network operations.
- Timber for logging.
- MPAndroidChart and Coil for charting and image loading.
- Various testing tools and frameworks as supported by the “testing” module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI (app)"
        A1["MainActivity"]:::ui
        A2["Compose Screens"]:::ui
        A3["ViewModels(MVVM)"]:::ui
    end

    %% Domain Layer
    subgraph "Domain"
        D1["Use Cases"]:::domain
        D2["Repository Interfaces"]:::domain
    end

    %% Data Layer
    subgraph "Data"
        DT1["Repository Implementations"]:::data
        DT2["Room Database"]:::data
        DT3["Network Services(Strava API)"]:::data
        DT4["Background Workers"]:::data
    end

    %% Dependency Injection
    subgraph "Dependency Injection(Hilt)"
        DI1["AppModule"]:::di
        DI2["DataModule"]:::di
    end

    %% Common Module
    subgraph "Common"
        C1["Shared Utilities"]:::common
    end

    %% External Services
    subgraph "External Services"
        E1["Strava API"]:::external
        E2["Strava Account Manager"]:::external
    end

    %% Testing Module
    subgraph "Testing"
        T1["Testing Module"]:::testing
    end

    %% Connections between layers
    A1 -->|"triggers"| A3
    A2 -->|"renders"| A3
    A3 -->|"calls"| D1
    D1 -->|"invokes"| D2
    D2 -->|"delegatesTo"| DT1
    D2 -->|"delegatesTo"| DT3
    DT1 -->|"reads/writes"| DT2
    DT1 -->|"notifies"| DT4
    DT3 -->|"fetches"| E1
    DT3 -->|"manages"| E2

    %% Dependency Injection ties
    DI1 --- A3
    DI1 --- D1
    DI2 --- DT1
    DI2 --- DT3
    DI2 --- DT4

    %% Common utilities connected to core layers
    C1 --- A3
    C1 --- D1
    C1 --- DT1

    %% Testing relationships (dashed lines)
    A1 -.->|"tests"| T1
    A2 -.->|"tests"| T1
    D1 -.->|"tests"| T1

    %% Click Events for UI Layer
    click A1 "https://github.com/civil31dot5/fitness-diary/blob/main/app/src/main/java/com/civil31dot5/fitnessdiary/ui/main/MainActivity.kt"
    click A2 "https://github.com/civil31dot5/fitness-diary/tree/main/app/src/main/java/com/civil31dot5/fitnessdiary/ui"

    %% Click Events for Domain Layer
    click D1 "https://github.com/civil31dot5/fitness-diary/tree/main/domain/src/main/java/com/civil31dot5/fitnessdiary/domain/usecase"
    click D2 "https://github.com/civil31dot5/fitness-diary/tree/main/domain/src/main/java/com/civil31dot5/fitnessdiary/domain/repository"
    click D1 "https://github.com/civil31dot5/fitness-diary/tree/main/domain/src/main/java/com/civil31dot5/fitnessdiary/domain"

    %% Click Events for Data Layer
    click DT1 "https://github.com/civil31dot5/fitness-diary/tree/main/data/src/main/java/com/civil31dot5/fitnessdiary/data/repository"
    click DT2 "https://github.com/civil31dot5/fitness-diary/tree/main/data/src/main/java/com/civil31dot5/fitnessdiary/data/database"
    click DT3 "https://github.com/civil31dot5/fitness-diary/tree/main/data/src/main/java/com/civil31dot5/fitnessdiary/data/network"
    click DT4 "https://github.com/civil31dot5/fitness-diary/tree/main/data/src/main/java/com/civil31dot5/fitnessdiary/data/worker"
    click DT3 "https://github.com/civil31dot5/fitness-diary/tree/main/data/src/main/java/com/civil31dot5/fitnessdiary/data"

    %% Click Events for Dependency Injection
    click DI1 "https://github.com/civil31dot5/fitness-diary/blob/main/app/src/main/java/com/civil31dot5/fitnessdiary/di/AppModule.kt"
    click DI2 "https://github.com/civil31dot5/fitness-diary/blob/main/data/src/main/java/com/civil31dot5/fitnessdiary/data/di/DataModule.kt"

    %% Click Event for Common Module
    click C1 "https://github.com/civil31dot5/fitness-diary/tree/main/common/src/main"

    %% Click Events for External Services
    click E1 "https://github.com/civil31dot5/fitness-diary/blob/main/data/src/main/java/com/civil31dot5/fitnessdiary/data/network/StravaApi.kt"
    click E2 "https://github.com/civil31dot5/fitness-diary/blob/main/data/src/main/java/com/civil31dot5/fitnessdiary/data/StravaAccountManagerImpl.kt"

    %% Click Event for Testing Module
    click T1 "https://github.com/civil31dot5/fitness-diary/tree/main/testing/src"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef domain fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef di fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef common fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef external fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef testing fill:#fefefe,stroke:#6c757d,stroke-width:2px;
```
