How antomanc/simple-calorie-tracker works
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