# muesly/calories architecture

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

- Interactive diagram: https://gitdiagram.com/muesly/calories
- Repository: https://github.com/muesly/calories

## Overview

##### Key Architectural Patterns to Highlight

- MVVM Architecture (evident from the *View/*ViewModel pattern throughout)
- Core Data for persistence (shown in Model.xcdatamodeld)
- Feature-based modular structure

##### Component Organization

a. Feature Modules (Group these together):
- Food Module
- Exercise Module
- Plant Module
- Record Weight Module
- Weekly Chart Module
- Meal Items Module

b. Core Components:
- HealthStore Integration
- Companion Communication
- Data Models
- Shared Resources

Following interactions:
- ViewModel ↔ Model
- View ↔ ViewModel
- HealthStore ↔ Apple HealthKit
- Companion ↔ Watch App
- Widget ↔ Main App Data

##### Important Details

- CoreData Model Entities:
- FoodEntry
- ExerciseEntry
- PlantEntry
- WeightEntry
- Day
- Meal

- Key Services:
- HealthStore
- NotificationSender
- SuggestionFetcher
- NetworkClient

##### Testing Coverage

A section showing test coverage for:
- ViewModel Tests
- View Tests
- Integration Tests

##### The modular feature-based architecture

Keep the abstraction level high enough to show the overall architecture but detailed enough to show the relationships between major components and the data flow through the system.

- Component relationships
- Testing coverage indicators

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Legend"
        UI[UI Component]:::ui
        VM[ViewModel]:::viewmodel
        DL[(Data Layer)]:::data
        EI{External Integration}:::external
        SM[[Support Module]]:::support
        style Legend fill:#f5f5f5,stroke:#333
    end

    subgraph "iOS Application"
        subgraph "Core Components"
            Model[(CoreData Model)]:::data
            click Model "https://github.com/Muesly/Calories/blob/main/Calories/Model/Model.xcdatamodeld"
            HealthKit{HealthKit Integration}:::external
            click HealthKit "https://github.com/Muesly/Calories/blob/main/Calories/HealthStore/HealthStore.swift"
            Companion[[Companion Service]]:::support
            click Companion "https://github.com/Muesly/Calories/blob/main/Calories/Companion/Companion.swift"
            MainApp[Main App View]:::ui
            click MainApp "https://github.com/Muesly/Calories/blob/main/Calories/App/CaloriesView.swift"
        end

        subgraph "Feature Modules"
            subgraph "Food Management"
                AddFoodView[Add Food View]:::ui
                click AddFoodView "https://github.com/Muesly/Calories/blob/main/Calories/AddFood/AddFoodView.swift"
                AddFoodVM[Add Food ViewModel]:::viewmodel
                click AddFoodVM "https://github.com/Muesly/Calories/blob/main/Calories/AddFood/AddFoodViewModel.swift"
                MealItemsView[Meal Items View]:::ui
                click MealItemsView "https://github.com/Muesly/Calories/blob/main/Calories/MealItems/MealItemsView.swift"
            end

            subgraph "Exercise Management"
                AddExerciseView[Add Exercise View]:::ui
                click AddExerciseView "https://github.com/Muesly/Calories/blob/main/Calories/AddExercise/AddExerciseView.swift"
                AddExerciseVM[Add Exercise ViewModel]:::viewmodel
                click AddExerciseVM "https://github.com/Muesly/Calories/blob/main/Calories/AddExercise/AddExerciseViewModel.swift"
            end

            subgraph "Plant Management"
                AddPlantView[Add Plant View]:::ui
                click AddPlantView "https://github.com/Muesly/Calories/blob/main/Calories/Add Plant/AddPlantView.swift"
                AddPlantVM[Add Plant ViewModel]:::viewmodel
                click AddPlantVM "https://github.com/Muesly/Calories/blob/main/Calories/Add Plant/AddPlantViewModel.swift"
            end

            subgraph "Weight Management"
                RecordWeightView[Record Weight View]:::ui
                click RecordWeightView "https://github.com/Muesly/Calories/blob/main/Calories/RecordWeight/RecordWeightView.swift"
                RecordWeightVM[Record Weight ViewModel]:::viewmodel
                click RecordWeightVM "https://github.com/Muesly/Calories/blob/main/Calories/RecordWeight/RecordWeightViewModel.swift"
            end

            subgraph "Analytics"
                WeeklyChartView[Weekly Chart View]:::ui
                click WeeklyChartView "https://github.com/Muesly/Calories/blob/main/Calories/WeeklyChart/WeeklyChartView.swift"
                WeeklyChartVM[Weekly Chart ViewModel]:::viewmodel
                click WeeklyChartVM "https://github.com/Muesly/Calories/blob/main/Calories/WeeklyChart/WeeklyChartViewModel.swift"
            end
        end
    end

    subgraph "Watch App"
        WatchApp[Watch UI]:::ui
        click WatchApp "https://github.com/Muesly/Calories/tree/main/Calories Watch App"
        WatchSync[[Watch Sync]]:::support
    end

    subgraph "Widget Extension"
        Widget[Calories Widget]:::ui
        click Widget "https://github.com/Muesly/Calories/blob/main/CaloriesWidget/CaloriesWidget.swift"
        WidgetData[[Widget Data Access]]:::support
    end

    %% Relationships
    MainApp --> Model
    AddFoodView --> AddFoodVM
    AddFoodVM --> Model
    AddExerciseView --> AddExerciseVM
    AddExerciseVM --> Model
    AddPlantView --> AddPlantVM
    AddPlantVM --> Model
    RecordWeightView --> RecordWeightVM
    RecordWeightVM --> Model
    WeeklyChartView --> WeeklyChartVM
    WeeklyChartVM --> Model
    MealItemsView --> Model
    Model <--> HealthKit
    Model <--> Companion
    Companion <--> WatchSync
    WatchSync --> WatchApp
    Model --> WidgetData
    WidgetData --> Widget

    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:#fff
    classDef viewmodel fill:#e67e22,stroke:#d35400,color:#fff
    classDef data fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef external fill:#9b59b6,stroke:#8e44ad,color:#fff
    classDef support fill:#95a5a6,stroke:#7f8c8d,color:#fff
```
