# nerorebel/smartpantry architecture

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

- Interactive diagram: https://gitdiagram.com/nerorebel/smartpantry
- Repository: https://github.com/nerorebel/smartpantry

## Overview

SmartPantry is an offline-first household pantry app. The main workflow is adding or scanning food, looking up barcode details when available, saving products locally, and using pantry contents to discover recipes or manage shopping; product outcomes also feed history, statistics, and expiration reminders. Authentication and synchronization extend the local experience with account-specific cloud data, while appearance and localization provide cross-cutting settings. The README documents several capabilities whose individual implementations were not sampled, so those branches are represented at subsystem level; edges are limited to documented relationships or visible source references.

Main entry points: [`src/db/products.ts`](https://github.com/nerorebel/smartpantry/blob/main/src/db/products.ts) (Product management), [`src/auth/auth-context.tsx`](https://github.com/nerorebel/smartpantry/blob/main/src/auth/auth-context.tsx) (Authentication), [`src/sync/sync-context.tsx`](https://github.com/nerorebel/smartpantry/blob/main/src/sync/sync-context.tsx) (Cloud sync), [`src/api/recipes.ts`](https://github.com/nerorebel/smartpantry/blob/main/src/api/recipes.ts) (Recipe discovery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pantry["Pantry workflow"]
  node_pantry_screens["Pantry screens<br/>[index.tsx]"]
  node_product_management["Product management<br/>[products.ts]"]
  node_local_database[("Local SQLite<br/>[database.ts]")]
  node_history_stats["History and statistics<br/>[statistics.ts]"]
  node_expiration_reminders["Expiration reminders<br/>[notifications.ts]"]
end

subgraph group_food["Food discovery"]
  node_scanner_search["Scan and search<br/>[search.tsx]"]
  node_barcode_lookup["Barcode lookup<br/>[open-food-facts.ts]"]
  node_open_food_facts{{"Open Food Facts"}}
  node_recipe_discovery["Recipe discovery<br/>[recipes.ts]"]
  node_mealdb{{"TheMealDB"}}
  node_recipe_matching["Pantry matching"]
  node_shopping_list[("Shopping list<br/>[shopping-list.ts]")]
end

subgraph group_account["Accounts and sync"]
  node_authentication["Authentication<br/>[auth-context.tsx]"]
  node_auth_service["Auth service<br/>[auth.ts]"]
  node_supabase{{"Supabase<br/>[supabase.ts]"}}
  node_sync_provider["Cloud sync<br/>[sync-context.tsx]"]
  node_sync_service["Sync orchestration<br/>[sync-service.ts]"]
  node_cloud_store["Cloud data store<br/>[cloud-store.ts]"]
  node_profile_avatars["Profile and avatars<br/>[user-avatar.tsx]"]
end

subgraph group_platform["App services"]
end

subgraph group_experience["App experience"]
  node_appearance["Appearance settings<br/>[theme-context.tsx]"]
  node_localization["Localization<br/>[index.ts]"]
  node_settings_storage[("App settings storage<br/>[app-settings.ts]")]
end

node_household(("Household user"))

node_household -->|"manages pantry"| node_pantry_screens
node_pantry_screens -->|"loads products"| node_product_management
node_product_management -->|"stores products"| node_local_database
node_household -->|"scans or searches"| node_scanner_search
node_scanner_search -->|"uses search hook"| node_barcode_lookup
node_barcode_lookup -->|"looks up barcode"| node_open_food_facts
node_household -->|"discovers recipes"| node_recipe_discovery
node_recipe_discovery -->|"fetches recipes"| node_mealdb
node_recipe_discovery -->|"matches ingredients"| node_recipe_matching
node_recipe_matching -->|"adds missing items"| node_shopping_list
node_household -->|"manages list"| node_shopping_list
node_product_management -->|"records outcomes"| node_history_stats
node_product_management -->|"schedules reminders"| node_expiration_reminders
node_household -->|"signs in"| node_authentication
node_authentication -->|"delegates auth"| node_auth_service
node_auth_service -->|"uses client"| node_supabase
node_authentication -->|"provides avatar state"| node_profile_avatars
node_authentication -->|"provides session"| node_sync_provider
node_sync_provider -->|"activates and schedules"| node_sync_service
node_sync_service -.->|"syncs account data"| node_cloud_store
node_sync_provider -->|"configures cloud sync"| node_supabase
node_sync_provider -->|"reconciles reminders"| node_expiration_reminders
node_household -->|"sets preferences"| node_appearance
node_appearance -->|"loads and saves"| node_settings_storage
node_appearance -->|"changes language"| node_localization

click node_pantry_screens "https://github.com/nerorebel/smartpantry/blob/main/src/app/(tabs)/index.tsx"
click node_product_management "https://github.com/nerorebel/smartpantry/blob/main/src/db/products.ts"
click node_local_database "https://github.com/nerorebel/smartpantry/blob/main/src/db/database.ts"
click node_history_stats "https://github.com/nerorebel/smartpantry/blob/main/src/utils/statistics.ts"
click node_expiration_reminders "https://github.com/nerorebel/smartpantry/blob/main/src/services/notifications.ts"
click node_scanner_search "https://github.com/nerorebel/smartpantry/blob/main/src/app/product/search.tsx"
click node_barcode_lookup "https://github.com/nerorebel/smartpantry/blob/main/src/api/open-food-facts.ts"
click node_recipe_discovery "https://github.com/nerorebel/smartpantry/blob/main/src/api/recipes.ts"
click node_recipe_matching "https://github.com/nerorebel/smartpantry/blob/main/src/utils/ingredient-matching.ts"
click node_shopping_list "https://github.com/nerorebel/smartpantry/blob/main/src/db/shopping-list.ts"
click node_authentication "https://github.com/nerorebel/smartpantry/blob/main/src/auth/auth-context.tsx"
click node_auth_service "https://github.com/nerorebel/smartpantry/blob/main/src/services/auth.ts"
click node_supabase "https://github.com/nerorebel/smartpantry/blob/main/src/lib/supabase.ts"
click node_sync_provider "https://github.com/nerorebel/smartpantry/blob/main/src/sync/sync-context.tsx"
click node_sync_service "https://github.com/nerorebel/smartpantry/blob/main/src/sync/sync-service.ts"
click node_cloud_store "https://github.com/nerorebel/smartpantry/blob/main/src/sync/cloud-store.ts"
click node_profile_avatars "https://github.com/nerorebel/smartpantry/blob/main/src/components/user-avatar.tsx"
click node_appearance "https://github.com/nerorebel/smartpantry/blob/main/src/theme/theme-context.tsx"
click node_localization "https://github.com/nerorebel/smartpantry/blob/main/src/i18n/index.ts"
click node_settings_storage "https://github.com/nerorebel/smartpantry/blob/main/src/db/app-settings.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pantry_screens,node_product_management,node_local_database,node_history_stats,node_expiration_reminders,node_household toneBlue
class node_scanner_search,node_barcode_lookup,node_open_food_facts,node_recipe_discovery,node_mealdb,node_recipe_matching,node_shopping_list toneAmber
class node_authentication,node_auth_service,node_supabase,node_sync_provider,node_sync_service,node_cloud_store,node_profile_avatars toneMint
class node_appearance,node_localization,node_settings_storage toneIndigo
```

## Components

### Pantry workflow

- [Pantry screens](https://github.com/nerorebel/smartpantry/blob/main/src/app/(tabs)/index.tsx): `src/app/(tabs)/index.tsx`
- [Product management](https://github.com/nerorebel/smartpantry/blob/main/src/db/products.ts): `src/db/products.ts`
- [Local SQLite](https://github.com/nerorebel/smartpantry/blob/main/src/db/database.ts): `src/db/database.ts`
- [History and statistics](https://github.com/nerorebel/smartpantry/blob/main/src/utils/statistics.ts): `src/utils/statistics.ts`
- [Expiration reminders](https://github.com/nerorebel/smartpantry/blob/main/src/services/notifications.ts): `src/services/notifications.ts`

### Food discovery

- [Scan and search](https://github.com/nerorebel/smartpantry/blob/main/src/app/product/search.tsx): `src/app/product/search.tsx`
- [Barcode lookup](https://github.com/nerorebel/smartpantry/blob/main/src/api/open-food-facts.ts): `src/api/open-food-facts.ts`
- **Open Food Facts**
- [Recipe discovery](https://github.com/nerorebel/smartpantry/blob/main/src/api/recipes.ts): `src/api/recipes.ts`
- **TheMealDB**
- [Pantry matching](https://github.com/nerorebel/smartpantry/blob/main/src/utils/ingredient-matching.ts): `src/utils/ingredient-matching.ts`
- [Shopping list](https://github.com/nerorebel/smartpantry/blob/main/src/db/shopping-list.ts): `src/db/shopping-list.ts`

### Accounts and sync

- [Authentication](https://github.com/nerorebel/smartpantry/blob/main/src/auth/auth-context.tsx): `src/auth/auth-context.tsx`
- [Auth service](https://github.com/nerorebel/smartpantry/blob/main/src/services/auth.ts): `src/services/auth.ts`
- [Supabase](https://github.com/nerorebel/smartpantry/blob/main/src/lib/supabase.ts): `src/lib/supabase.ts`
- [Cloud sync](https://github.com/nerorebel/smartpantry/blob/main/src/sync/sync-context.tsx): `src/sync/sync-context.tsx`
- [Sync orchestration](https://github.com/nerorebel/smartpantry/blob/main/src/sync/sync-service.ts): `src/sync/sync-service.ts`
- [Cloud data store](https://github.com/nerorebel/smartpantry/blob/main/src/sync/cloud-store.ts): `src/sync/cloud-store.ts`
- [Profile and avatars](https://github.com/nerorebel/smartpantry/blob/main/src/components/user-avatar.tsx): `src/components/user-avatar.tsx`

### App experience

- [Appearance settings](https://github.com/nerorebel/smartpantry/blob/main/src/theme/theme-context.tsx): `src/theme/theme-context.tsx`
- [Localization](https://github.com/nerorebel/smartpantry/blob/main/src/i18n/index.ts): `src/i18n/index.ts`
- [App settings storage](https://github.com/nerorebel/smartpantry/blob/main/src/db/app-settings.ts): `src/db/app-settings.ts`

### Other components

- **Household user**

## Connections

- Household user → Pantry screens: manages pantry (evidence: `README.md`)
- Pantry screens → Product management: loads products (evidence: `src/app/(tabs)/index.tsx`)
- Product management → Local SQLite: stores products (evidence: `src/db/database.ts`)
- Household user → Scan and search: scans or searches (evidence: `README.md`)
- Scan and search → Barcode lookup: uses search hook (evidence: `src/app/product/search.tsx`)
- Barcode lookup → Open Food Facts: looks up barcode (evidence: `README.md`)
- Household user → Recipe discovery: discovers recipes (evidence: `README.md`)
- Recipe discovery → TheMealDB: fetches recipes (evidence: `README.md`)
- Recipe discovery → Pantry matching: matches ingredients (evidence: `README.md`)
- Pantry matching → Shopping list: adds missing items (evidence: `README.md`)
- Household user → Shopping list: manages list (evidence: `README.md`)
- Product management → History and statistics: records outcomes (evidence: `README.md`)
- Product management → Expiration reminders: schedules reminders (evidence: `README.md`)
- Household user → Authentication: signs in (evidence: `README.md`)
- Authentication → Auth service: delegates auth (evidence: `src/auth/auth-context.tsx`)
- Auth service → Supabase: uses client (evidence: `src/services/auth.ts`)
- Authentication → Profile and avatars: provides avatar state (evidence: `src/components/user-avatar.tsx`)
- Authentication → Cloud sync: provides session (evidence: `src/sync/sync-context.tsx`)
- Cloud sync → Sync orchestration: activates and schedules (evidence: `src/sync/sync-context.tsx`)
- Sync orchestration → Cloud data store: syncs account data
- Cloud sync → Supabase: configures cloud sync (evidence: `src/sync/sync-context.tsx`)
- Cloud sync → Expiration reminders: reconciles reminders (evidence: `src/sync/sync-context.tsx`)
- Household user → Appearance settings: sets preferences (evidence: `README.md`)
- Appearance settings → App settings storage: loads and saves (evidence: `src/theme/theme-context.tsx`)
- Appearance settings → Localization: changes language (evidence: `src/theme/theme-context.tsx`)
