# felixqaq/calorie_snap architecture

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

- Interactive diagram: https://gitdiagram.com/felixqaq/calorie_snap
- Repository: https://github.com/felixqaq/calorie_snap

## Overview

##### Main Components
- User Interface (UI) Layer: Represented by the Flutter frontend code in the “lib” directory (pages, dialogs, widgets). This includes pages such as the login, home, food entry, settings, and detail pages.
- State Management Layer: The “providers” folder (e.g., calorie_provider.dart) handles application state and business logic.
- Services Layer: Under “lib/services” (e.g., auth_service.dart, food_service.dart, storage_service.dart). These components encapsulate different functionalities such as authentication, food data retrieval, and local storage.
- Data Persistence Layer: The “lib/db” folder contains the food_db.dart, which is used for local database operations related to food data and calorie information.
- Domain / Models: The “lib/models” folder which includes detailed classes for food, composite food items, and nutritional information.
- External Systems / ML Model Integration: The system also makes use of the Gemini model for food recognition. This should be depicted as an external service or API that the Food Service interacts with.

##### Relationships and Interactions
- The UI components interact with state providers which in turn call on the services.
- The services layer interfaces with the local database for persisting food records, and with the external Gemini-based food recognition API for analyzing images.
- The authentication service manages user login and registration flows.
- Components (charts, dialogs, etc.) then display calorie information provided through the provider layer.
- Platform wrappers (Android, iOS, etc.) serve as hosts for the Flutter engine and glue the mobile or desktop OS with your Flutter code.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The application is split between presentation (pages/widgets), state management/providers, services, and data (models, database).
- Cross-Platform Abstraction: The project’s structure lets Flutter handle most logic universally, while platform-specific directories manage runtime differences.
- Extensibility: Through services and providers, new features such as additional food recognition methods or enhanced analytics can be integrated without affecting the UI directly.

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Layer
    subgraph "UI Layer"
        Pages("Pages"):::ui
        Dialogs("Dialogs"):::ui
        Widgets("Widgets"):::ui
    end

    %% State Management Layer
    subgraph "State Management"
        Providers("Providers (State Management)"):::state
    end

    %% Services Layer
    subgraph "Services Layer"
        Auth("Auth Service"):::service
        Food("Food Service"):::service
        Storage("Storage Service"):::service
    end

    %% Data Persistence and Domain Models
    subgraph "Data Layer"
        DB("Local Database (food_db)"):::database
        Models("Domain Models"):::model
    end

    %% External API Integration
    External("Gemini API (Food Recognition)"):::external

    %% Platform-specific Integrations
    subgraph "Platform-specific"
        Android("Android"):::platform
        iOS("iOS"):::platform
        Web("Web"):::platform
        Linux("Linux"):::platform
        MacOS("MacOS"):::platform
        Windows("Windows"):::platform
    end

    %% Connections between layers
    Pages -->|"triggers_update"| Providers
    Dialogs -->|"triggers_update"| Providers
    Widgets -->|"triggers_update"| Providers

    Providers -->|"calls"| Auth
    Providers -->|"calls"| Food
    Providers -->|"calls"| Storage
    Providers -->|"uses"| Models

    Food -->|"fetches_from"| DB
    Food -->|"sends_image_to"| External
    Food -->|"uses"| Models

    Storage -->|"persists_to"| DB
    Storage -->|"uses"| Models

    %% Styles
    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef state fill:#A9DFBF,stroke:#1D8348,stroke-width:2px;
    classDef service fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#943126,stroke-width:2px;
    classDef model fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef external fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef platform fill:#D6EAF8,stroke:#2E86C1,stroke-width:2px;

    %% Click Events for UI Layer
    click Pages "https://github.com/felixqaq/calorie_snap/tree/main/lib/pages"
    click Dialogs "https://github.com/felixqaq/calorie_snap/tree/main/lib/dialogs"
    click Widgets "https://github.com/felixqaq/calorie_snap/tree/main/lib/widgets"

    %% Click Event for State Management
    click Providers "https://github.com/felixqaq/calorie_snap/blob/main/lib/providers/calorie_provider.dart"

    %% Click Events for Services Layer
    click Auth "https://github.com/felixqaq/calorie_snap/blob/main/lib/services/auth_service.dart"
    click Food "https://github.com/felixqaq/calorie_snap/blob/main/lib/services/food_service.dart"
    click Storage "https://github.com/felixqaq/calorie_snap/blob/main/lib/services/storage_service.dart"

    %% Click Event for Data Persistence
    click DB "https://github.com/felixqaq/calorie_snap/blob/main/lib/db/food_db.dart"

    %% Click Event for Domain Models
    click Models "https://github.com/felixqaq/calorie_snap/tree/main/lib/models"

    %% Click Events for Platform-specific Integrations
    click Android "https://github.com/felixqaq/calorie_snap/tree/main/android"
    click iOS "https://github.com/felixqaq/calorie_snap/tree/main/ios"
    click Web "https://github.com/felixqaq/calorie_snap/tree/main/web"
    click Linux "https://github.com/felixqaq/calorie_snap/tree/main/linux"
    click MacOS "https://github.com/felixqaq/calorie_snap/tree/main/macos"
    click Windows "https://github.com/felixqaq/calorie_snap/tree/main/windows"
```
