# antomanc/simple-calorie-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/antomanc/simple-calorie-tracker
- Repository: https://github.com/antomanc/simple-calorie-tracker

## Overview

##### Project Type and Purpose
- This is a cross‐platform mobile application (React Native + Expo) for tracking daily calories, macros, and meals.
- It uses local storage (SQLite DB), remote food‐data APIs (OpenFoodFacts, USDA), and a context/provider pattern for state management.

##### File Structure Analysis
- Top-level “android” and “ios” folders: native wrappers generated by Expo.
- “app” folder: screen definitions and routing via Expo Router
- “components”: reusable UI widgets
- “hooks”: data-access and business-logic hooks (useDatabase, useDiary, useSearchFood, etc.)
- “providers”: React Context providers (DatabaseProvider, SettingsProvider, SelectionProvider)
- “api”: modules encapsulating HTTP calls to OpenFoodFacts and USDA
- “assets/databases”: bundled SQLite database (usda_sr_food.db)
- “constants”, “interfaces”, “utils”: cross-cutting types and helpers

##### Key Architecture Insights from README
- React Native + Expo stack
- Client-only app (no proprietary backend)
- External dependencies: OpenFoodFacts API, USDA API
- Local SQLite for fast on-device lookups and offline entries

##### Main Components
a. **UI Layer**
- Screens (Diary, Search, Settings, FoodInfo, Meal)
- Components (BottomButton, Header, FoodSearchCard, etc.)
- Expo Router handles navigation/layout.
b. **State Management**
- Context Providers wrap the app at entry (in _layout.tsx)
- Providers expose state & dispatch (Selection, Settings, Database)
c. **Data Access Layer**
- Hooks consume Providers and coordinate:
- Local DB queries via useDatabase
- Remote API calls via OpenFoodFactsAPI.ts / UsdaApi.ts
- In-memory caching (e.g., recent/favorites)
d. **Local Data Store**
- SQLite database (assets/databases/usda_sr_food.db) managed by expo-sqlite
e. **External Services**
- OpenFoodFacts REST API
- USDA FoodData Central API
f. **Native Modules / Platform**
- Android and iOS projects (barcode scanner, file system, native UI)
- Expo prebuild & native code (MainActivity.kt, AppDelegate.mm)

##### Relationships and Data Flows
- UI → Hooks: user interactions trigger hook functions (e.g., searchFood).
- Hooks → Local DB or External API: data requests → responses.
- API → Hooks → Providers: results fed into context state.
- Providers → UI: components re-render with updated state.
- Native modules (barcodeScanner.tsx) → platform camera/native.

##### Architectural Patterns & Principles
- Provider/Context for global state
- Hook abstraction for side effects and data fetching
- Feature-based folder structure (screens vs. components vs. hooks)
- Separation of concerns: UI vs. data vs. business logic

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% App Entry
    A["Expo Router (_layout.tsx)"]:::state
    click A "https://github.com/antomanc/simple-calorie-tracker/blob/main/app/_layout.tsx"

    %% Providers Layer
    subgraph "Context Providers"
        direction TB
        P1["DatabaseProvider"]:::state
        P2["SettingsProvider"]:::state
        P3["SelectionProvider"]:::state
        click P1 "https://github.com/antomanc/simple-calorie-tracker/blob/main/providers/DatabaseProvider.tsx"
        click P2 "https://github.com/antomanc/simple-calorie-tracker/blob/main/providers/SettingsProvider.tsx"
        click P3 "https://github.com/antomanc/simple-calorie-tracker/blob/main/providers/SelectionProvider.tsx"
    end

    A --> P1
    A --> P2
    A --> P3

    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        subgraph Screens
            direction TB
            S1["Diary Screen"]:::ui
            S2["Settings Screen"]:::ui
            S3["Search Food Screen"]:::ui
            S4["Food Info Screen"]:::ui
            S5["Meal Screen"]:::ui
            S6["Add Food Screen"]:::ui
            S7["Barcode Scanner Screen"]:::ui
            S8["Not Found Screen"]:::ui
            click S1 "https://github.com/antomanc/simple-calorie-tracker/blob/main/app/(tabs)/diary.tsx"
            click S2 "https://github.com/antomanc/simple-calorie-tracker/blob/main/app/(tabs)/settings.tsx"
            click S3 "https://github.com/antomanc/simple-calorie-tracker/blob/main/app/searchFood.tsx"
            click S4 "https://github.com/antomanc/simple-calorie-tracker/blob/main/app/foodInfo.tsx"
            click S5 "https://github.com/antomanc/simple-calorie-tracker/blob/main/app/meal.tsx"
            click S6 "https://github.com/antomanc/simple-calorie-tracker/blob/main/app/addFood.tsx"
            click S7 "https://github.com/antomanc/simple-calorie-tracker/blob/main/app/barcodeScanner.tsx"
            click S8 "https://github.com/antomanc/simple-calorie-tracker/blob/main/app/+not-found.tsx"
        end
        subgraph Components
            direction TB
            C1["BottomButton"]:::ui
            C2["Header"]:::ui
            C3["FoodSearchCard"]:::ui
            click C1 "https://github.com/antomanc/simple-calorie-tracker/blob/main/components/BottomButton.tsx"
            click C2 "https://github.com/antomanc/simple-calorie-tracker/blob/main/components/Header.tsx"
            click C3 "https://github.com/antomanc/simple-calorie-tracker/blob/main/components/FoodSearchCard.tsx"
        end
    end

    P1 --> S1
    P1 --> S2
    P1 --> S3
    P1 --> S4
    P1 --> S5
    P1 --> S6
    P1 --> S7
    P1 --> S8

    %% Hooks Layer
    subgraph "Hooks Layer"
        direction TB
        H1["useDatabase"]:::data
        H2["useDiary"]:::data
        H3["useSearchFood"]:::data
        H4["useFoods"]:::data
        click H1 "https://github.com/antomanc/simple-calorie-tracker/blob/main/hooks/useDatabase.ts"
        click H2 "https://github.com/antomanc/simple-calorie-tracker/blob/main/hooks/useDiary.ts"
        click H3 "https://github.com/antomanc/simple-calorie-tracker/blob/main/hooks/useSearchFood.ts"
        click H4 "https://github.com/antomanc/simple-calorie-tracker/blob/main/hooks/useFoods.ts"
    end

    S1 --> H2
    S3 --> H3
    S4 --> H4
    S5 --> H1
    S7 --> H1

    P1 --> H1
    P1 --> H2
    P1 --> H3

    %% Data Stores & Services
    subgraph "Data Storage & External Services"
        direction TB
        DB["SQLite Database"]:::data
        click DB "https://github.com/antomanc/simple-calorie-tracker/blob/main/assets/databases/usda_sr_food.db"
        E1["OpenFoodFacts API"]:::external
        E2["USDA API"]:::external
        click E1 "https://github.com/antomanc/simple-calorie-tracker/blob/main/api/OpenFoodFactsAPI.ts"
        click E2 "https://github.com/antomanc/simple-calorie-tracker/blob/main/api/UsdaApi.ts"
    end

    H1 --> DB
    H2 --> DB
    H3 --> E1
    H3 --> E2
    E1 --> H3
    E2 --> H3
    DB --> H1

    %% Native Platform
    subgraph "Mobile Platform (Native Modules)" 
        direction TB
        N1["Android Wrapper"]:::platform
        N2["iOS Wrapper"]:::platform
        click N1 "https://github.com/antomanc/simple-calorie-tracker/blob/main/android/app/src/main/java/com/antomanc/simplecalorietracker/MainActivity.kt"
        click N2 "https://github.com/antomanc/simple-calorie-tracker/blob/main/ios/SimpleCalorieTracker/AppDelegate.mm"
    end

    S7 --> N1
    S7 --> N2

    %% Build Pipeline
    BP["Build Pipeline\n(bun install → expo prebuild → native)"]:::platform

    A --> BP

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef state fill:#DFF7D8,stroke:#22863a,color:#22863a;
    classDef data fill:#FFE5B4,stroke:#D87614,color:#D87614;
    classDef external fill:#E6D0F1,stroke:#6F42C1,color:#6F42C1;
    classDef platform fill:#EDEDED,stroke:#6A737D,color:#6A737D;
```
