From 6537863696144f67691fbb5a3734fcf8adee3ad1 Mon Sep 17 00:00:00 2001 From: Till-JS <101404291+Till-JS@users.noreply.github.com> Date: Tue, 25 Nov 2025 17:52:14 +0100 Subject: [PATCH] feat(nutriphi): migrate from Supabase to PostgreSQL + Hetzner S3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add nutriphi-database package with Drizzle ORM - meals and nutrition_goals schemas - PostgreSQL 16 Docker setup - Drizzle Kit configuration - Migrate backend from Supabase to Drizzle - Add DatabaseModule with connection pooling - Add StorageService for Hetzner Object Storage (S3-compatible) - Update MealsService with Drizzle queries - Add /api/meals/upload endpoint for image upload + analysis - Update web app to use backend for uploads - Remove Supabase Storage direct upload - Update uploadService to send images to backend - Remove Supabase dependencies from package.json - Simplify hooks.server.ts - Add Coolify deployment configuration - Dockerfile for production build - docker-compose.coolify.yml đŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- nutriphi/.gitignore | 25 + nutriphi/CLAUDE.md | 171 ++++ nutriphi/DoneSteps.md | 381 +++++++++ nutriphi/Plan.md | 357 ++++++++ nutriphi/ReadMes/Expo-ImagePicker.md | 799 ++++++++++++++++++ nutriphi/apps/landing/astro.config.mjs | 11 + nutriphi/apps/landing/package.json | 26 + .../apps/landing/src/components/Footer.astro | 78 ++ .../landing/src/components/Navigation.astro | 84 ++ .../apps/landing/src/layouts/Layout.astro | 47 ++ nutriphi/apps/landing/src/pages/index.astro | 287 +++++++ nutriphi/apps/landing/src/styles/global.css | 103 +++ nutriphi/apps/landing/tailwind.config.mjs | 39 + nutriphi/apps/landing/tsconfig.json | 9 + nutriphi/apps/mobile/app-env.d.ts | 2 + nutriphi/apps/mobile/app.json | 79 ++ nutriphi/apps/mobile/app/(tabs)/_layout.tsx | 45 + nutriphi/apps/mobile/app/+html.tsx | 46 + nutriphi/apps/mobile/app/+not-found.tsx | 24 + nutriphi/apps/mobile/app/_layout.tsx | 63 ++ nutriphi/apps/mobile/app/index.tsx | 52 ++ nutriphi/apps/mobile/app/meal/[id].tsx | 253 ++++++ nutriphi/apps/mobile/app/modal.tsx | 13 + nutriphi/apps/mobile/app/settings.tsx | 296 +++++++ nutriphi/apps/mobile/assets/adaptive-icon.png | Bin 0 -> 17547 bytes nutriphi/apps/mobile/assets/favicon.png | Bin 0 -> 1466 bytes nutriphi/apps/mobile/assets/icon.png | Bin 0 -> 22380 bytes nutriphi/apps/mobile/assets/splash.png | Bin 0 -> 47346 bytes nutriphi/apps/mobile/babel.config.js | 10 + nutriphi/apps/mobile/cesconfig.json | 44 + nutriphi/apps/mobile/components/Button.tsx | 24 + nutriphi/apps/mobile/components/Container.tsx | 9 + .../apps/mobile/components/EditScreenInfo.tsx | 29 + .../apps/mobile/components/HeaderButton.tsx | 33 + .../apps/mobile/components/ScreenContent.tsx | 25 + .../apps/mobile/components/TabBarIcon.tsx | 26 + .../mobile/components/camera/CameraModal.tsx | 420 +++++++++ .../mobile/components/camera/PhotoButton.tsx | 75 ++ .../mobile/components/camera/PhotoPreview.tsx | 63 ++ .../location/LocationPermissionModal.tsx | 87 ++ .../meals/AnalysisStatusIndicator.tsx | 103 +++ .../mobile/components/meals/EditMealModal.tsx | 154 ++++ .../mobile/components/meals/FoodItemCard.tsx | 161 ++++ .../mobile/components/meals/FoodItemList.tsx | 162 ++++ .../apps/mobile/components/meals/MealCard.tsx | 190 +++++ .../components/meals/MealCardContextMenu.tsx | 186 ++++ .../apps/mobile/components/meals/MealItem.tsx | 149 ++++ .../apps/mobile/components/meals/MealList.tsx | 100 +++ .../mobile/components/meals/NutritionBar.tsx | 199 +++++ nutriphi/apps/mobile/components/ui/Card.tsx | 30 + .../components/ui/FloatingActionButton.tsx | 154 ++++ nutriphi/apps/mobile/components/ui/Header.tsx | 32 + .../mobile/components/ui/LoadingOverlay.tsx | 31 + .../mobile/components/ui/LoadingSpinner.tsx | 32 + .../apps/mobile/components/ui/SFSymbol.tsx | 54 ++ nutriphi/apps/mobile/eas.json | 21 + nutriphi/apps/mobile/eslint.config.js | 15 + nutriphi/apps/mobile/global.css | 3 + nutriphi/apps/mobile/hooks/useCamera.ts | 105 +++ nutriphi/apps/mobile/hooks/useDatabase.ts | 76 ++ nutriphi/apps/mobile/hooks/useTheme.ts | 62 ++ nutriphi/apps/mobile/metro.config.js | 17 + nutriphi/apps/mobile/nativewind-env.d.ts | 3 + nutriphi/apps/mobile/package.json | 68 ++ nutriphi/apps/mobile/prettier.config.js | 10 + .../mobile/services/DataClearingService.ts | 145 ++++ .../apps/mobile/services/LocationService.ts | 217 +++++ .../mobile/services/UserPreferencesService.ts | 207 +++++ .../apps/mobile/services/api/GeminiService.ts | 540 ++++++++++++ .../services/database/MigrationService.ts | 214 +++++ .../mobile/services/database/SQLiteService.ts | 403 +++++++++ .../mobile/services/storage/PhotoService.ts | 201 +++++ nutriphi/apps/mobile/store/AppStore.ts | 118 +++ nutriphi/apps/mobile/store/MealStore.ts | 190 +++++ nutriphi/apps/mobile/store/store.ts | 3 + nutriphi/apps/mobile/tailwind.config.js | 10 + nutriphi/apps/mobile/tsconfig.json | 13 + nutriphi/apps/mobile/types/API.ts | 97 +++ nutriphi/apps/mobile/types/Database.ts | 116 +++ nutriphi/apps/mobile/utils/supabase.ts | 14 + nutriphi/apps/web/.env.example | 18 + nutriphi/apps/web/package.json | 40 + nutriphi/apps/web/src/app.css | 1 + nutriphi/apps/web/src/app.d.ts | 21 + nutriphi/apps/web/src/app.html | 12 + nutriphi/apps/web/src/hooks.server.ts | 9 + .../lib/components/meals/FoodItemList.svelte | 67 ++ .../src/lib/components/meals/MealCard.svelte | 104 +++ .../lib/components/meals/MealEditModal.svelte | 164 ++++ .../src/lib/components/meals/MealGrid.svelte | 27 + .../lib/components/meals/NutritionBar.svelte | 162 ++++ nutriphi/apps/web/src/lib/config/env.ts | 42 + nutriphi/apps/web/src/lib/services/api.ts | 116 +++ .../apps/web/src/lib/services/authService.ts | 413 +++++++++ .../web/src/lib/services/exportService.ts | 204 +++++ .../apps/web/src/lib/services/goalsService.ts | 91 ++ .../apps/web/src/lib/services/mealService.ts | 154 ++++ .../apps/web/src/lib/services/statsService.ts | 222 +++++ .../apps/web/src/lib/services/tokenManager.ts | 342 ++++++++ .../web/src/lib/services/uploadService.ts | 204 +++++ nutriphi/apps/web/src/lib/stores/auth.ts | 243 ++++++ .../apps/web/src/lib/stores/goals.svelte.ts | 143 ++++ .../apps/web/src/lib/stores/meals.svelte.ts | 169 ++++ .../apps/web/src/lib/stores/navigation.ts | 4 + nutriphi/apps/web/src/lib/stores/theme.ts | 24 + nutriphi/apps/web/src/lib/types/goal.ts | 39 + nutriphi/apps/web/src/lib/types/meal.ts | 77 ++ nutriphi/apps/web/src/lib/types/stats.ts | 56 ++ .../web/src/routes/(protected)/+layout.svelte | 155 ++++ .../routes/(protected)/export/+page.svelte | 169 ++++ .../src/routes/(protected)/goals/+page.svelte | 208 +++++ .../src/routes/(protected)/meals/+page.svelte | 67 ++ .../(protected)/meals/[id]/+page.svelte | 273 ++++++ .../routes/(protected)/settings/+page.svelte | 152 ++++ .../src/routes/(protected)/stats/+page.svelte | 107 +++ .../(protected)/subscription/+page.svelte | 132 +++ .../routes/(protected)/upload/+page.svelte | 239 ++++++ .../web/src/routes/(public)/+layout.svelte | 7 + .../src/routes/(public)/login/+page.svelte | 102 +++ .../src/routes/(public)/register/+page.svelte | 143 ++++ nutriphi/apps/web/src/routes/+layout.svelte | 24 + nutriphi/apps/web/src/routes/+page.svelte | 40 + nutriphi/apps/web/svelte.config.js | 13 + nutriphi/apps/web/tsconfig.json | 14 + nutriphi/apps/web/vite.config.ts | 6 + nutriphi/backend/.env.example | 20 + nutriphi/backend/Dockerfile | 49 ++ nutriphi/backend/docker-compose.coolify.yml | 31 + nutriphi/backend/nest-cli.json | 8 + nutriphi/backend/package.json | 46 + nutriphi/backend/src/app.module.ts | 22 + .../backend/src/database/database.module.ts | 28 + nutriphi/backend/src/gemini/gemini.module.ts | 8 + nutriphi/backend/src/gemini/gemini.service.ts | 128 +++ .../backend/src/health/health.controller.ts | 13 + nutriphi/backend/src/health/health.module.ts | 7 + nutriphi/backend/src/main.ts | 36 + .../backend/src/meals/dto/analyze-meal.dto.ts | 93 ++ .../backend/src/meals/meals.controller.ts | 79 ++ nutriphi/backend/src/meals/meals.module.ts | 11 + nutriphi/backend/src/meals/meals.service.ts | 281 ++++++ .../backend/src/storage/storage.module.ts | 9 + .../backend/src/storage/storage.service.ts | 166 ++++ nutriphi/backend/tsconfig.json | 21 + nutriphi/package.json | 6 + packages/nutriphi-database/.env.example | 5 + packages/nutriphi-database/docker-compose.yml | 36 + packages/nutriphi-database/drizzle.config.ts | 12 + packages/nutriphi-database/package.json | 54 ++ packages/nutriphi-database/src/client.ts | 97 +++ packages/nutriphi-database/src/index.ts | 32 + .../nutriphi-database/src/schema/goals.ts | 21 + .../nutriphi-database/src/schema/index.ts | 5 + .../nutriphi-database/src/schema/meals.ts | 67 ++ packages/nutriphi-database/tsconfig.json | 21 + pnpm-lock.yaml | 235 ++---- 156 files changed, 15236 insertions(+), 170 deletions(-) create mode 100644 nutriphi/.gitignore create mode 100644 nutriphi/CLAUDE.md create mode 100644 nutriphi/DoneSteps.md create mode 100644 nutriphi/Plan.md create mode 100644 nutriphi/ReadMes/Expo-ImagePicker.md create mode 100644 nutriphi/apps/landing/astro.config.mjs create mode 100644 nutriphi/apps/landing/package.json create mode 100644 nutriphi/apps/landing/src/components/Footer.astro create mode 100644 nutriphi/apps/landing/src/components/Navigation.astro create mode 100644 nutriphi/apps/landing/src/layouts/Layout.astro create mode 100644 nutriphi/apps/landing/src/pages/index.astro create mode 100644 nutriphi/apps/landing/src/styles/global.css create mode 100644 nutriphi/apps/landing/tailwind.config.mjs create mode 100644 nutriphi/apps/landing/tsconfig.json create mode 100644 nutriphi/apps/mobile/app-env.d.ts create mode 100644 nutriphi/apps/mobile/app.json create mode 100644 nutriphi/apps/mobile/app/(tabs)/_layout.tsx create mode 100644 nutriphi/apps/mobile/app/+html.tsx create mode 100644 nutriphi/apps/mobile/app/+not-found.tsx create mode 100644 nutriphi/apps/mobile/app/_layout.tsx create mode 100644 nutriphi/apps/mobile/app/index.tsx create mode 100644 nutriphi/apps/mobile/app/meal/[id].tsx create mode 100644 nutriphi/apps/mobile/app/modal.tsx create mode 100644 nutriphi/apps/mobile/app/settings.tsx create mode 100644 nutriphi/apps/mobile/assets/adaptive-icon.png create mode 100644 nutriphi/apps/mobile/assets/favicon.png create mode 100644 nutriphi/apps/mobile/assets/icon.png create mode 100644 nutriphi/apps/mobile/assets/splash.png create mode 100644 nutriphi/apps/mobile/babel.config.js create mode 100644 nutriphi/apps/mobile/cesconfig.json create mode 100644 nutriphi/apps/mobile/components/Button.tsx create mode 100644 nutriphi/apps/mobile/components/Container.tsx create mode 100644 nutriphi/apps/mobile/components/EditScreenInfo.tsx create mode 100644 nutriphi/apps/mobile/components/HeaderButton.tsx create mode 100644 nutriphi/apps/mobile/components/ScreenContent.tsx create mode 100644 nutriphi/apps/mobile/components/TabBarIcon.tsx create mode 100644 nutriphi/apps/mobile/components/camera/CameraModal.tsx create mode 100644 nutriphi/apps/mobile/components/camera/PhotoButton.tsx create mode 100644 nutriphi/apps/mobile/components/camera/PhotoPreview.tsx create mode 100644 nutriphi/apps/mobile/components/location/LocationPermissionModal.tsx create mode 100644 nutriphi/apps/mobile/components/meals/AnalysisStatusIndicator.tsx create mode 100644 nutriphi/apps/mobile/components/meals/EditMealModal.tsx create mode 100644 nutriphi/apps/mobile/components/meals/FoodItemCard.tsx create mode 100644 nutriphi/apps/mobile/components/meals/FoodItemList.tsx create mode 100644 nutriphi/apps/mobile/components/meals/MealCard.tsx create mode 100644 nutriphi/apps/mobile/components/meals/MealCardContextMenu.tsx create mode 100644 nutriphi/apps/mobile/components/meals/MealItem.tsx create mode 100644 nutriphi/apps/mobile/components/meals/MealList.tsx create mode 100644 nutriphi/apps/mobile/components/meals/NutritionBar.tsx create mode 100644 nutriphi/apps/mobile/components/ui/Card.tsx create mode 100644 nutriphi/apps/mobile/components/ui/FloatingActionButton.tsx create mode 100644 nutriphi/apps/mobile/components/ui/Header.tsx create mode 100644 nutriphi/apps/mobile/components/ui/LoadingOverlay.tsx create mode 100644 nutriphi/apps/mobile/components/ui/LoadingSpinner.tsx create mode 100644 nutriphi/apps/mobile/components/ui/SFSymbol.tsx create mode 100644 nutriphi/apps/mobile/eas.json create mode 100644 nutriphi/apps/mobile/eslint.config.js create mode 100644 nutriphi/apps/mobile/global.css create mode 100644 nutriphi/apps/mobile/hooks/useCamera.ts create mode 100644 nutriphi/apps/mobile/hooks/useDatabase.ts create mode 100644 nutriphi/apps/mobile/hooks/useTheme.ts create mode 100644 nutriphi/apps/mobile/metro.config.js create mode 100644 nutriphi/apps/mobile/nativewind-env.d.ts create mode 100644 nutriphi/apps/mobile/package.json create mode 100644 nutriphi/apps/mobile/prettier.config.js create mode 100644 nutriphi/apps/mobile/services/DataClearingService.ts create mode 100644 nutriphi/apps/mobile/services/LocationService.ts create mode 100644 nutriphi/apps/mobile/services/UserPreferencesService.ts create mode 100644 nutriphi/apps/mobile/services/api/GeminiService.ts create mode 100644 nutriphi/apps/mobile/services/database/MigrationService.ts create mode 100644 nutriphi/apps/mobile/services/database/SQLiteService.ts create mode 100644 nutriphi/apps/mobile/services/storage/PhotoService.ts create mode 100644 nutriphi/apps/mobile/store/AppStore.ts create mode 100644 nutriphi/apps/mobile/store/MealStore.ts create mode 100644 nutriphi/apps/mobile/store/store.ts create mode 100644 nutriphi/apps/mobile/tailwind.config.js create mode 100644 nutriphi/apps/mobile/tsconfig.json create mode 100644 nutriphi/apps/mobile/types/API.ts create mode 100644 nutriphi/apps/mobile/types/Database.ts create mode 100644 nutriphi/apps/mobile/utils/supabase.ts create mode 100644 nutriphi/apps/web/.env.example create mode 100644 nutriphi/apps/web/package.json create mode 100644 nutriphi/apps/web/src/app.css create mode 100644 nutriphi/apps/web/src/app.d.ts create mode 100644 nutriphi/apps/web/src/app.html create mode 100644 nutriphi/apps/web/src/hooks.server.ts create mode 100644 nutriphi/apps/web/src/lib/components/meals/FoodItemList.svelte create mode 100644 nutriphi/apps/web/src/lib/components/meals/MealCard.svelte create mode 100644 nutriphi/apps/web/src/lib/components/meals/MealEditModal.svelte create mode 100644 nutriphi/apps/web/src/lib/components/meals/MealGrid.svelte create mode 100644 nutriphi/apps/web/src/lib/components/meals/NutritionBar.svelte create mode 100644 nutriphi/apps/web/src/lib/config/env.ts create mode 100644 nutriphi/apps/web/src/lib/services/api.ts create mode 100644 nutriphi/apps/web/src/lib/services/authService.ts create mode 100644 nutriphi/apps/web/src/lib/services/exportService.ts create mode 100644 nutriphi/apps/web/src/lib/services/goalsService.ts create mode 100644 nutriphi/apps/web/src/lib/services/mealService.ts create mode 100644 nutriphi/apps/web/src/lib/services/statsService.ts create mode 100644 nutriphi/apps/web/src/lib/services/tokenManager.ts create mode 100644 nutriphi/apps/web/src/lib/services/uploadService.ts create mode 100644 nutriphi/apps/web/src/lib/stores/auth.ts create mode 100644 nutriphi/apps/web/src/lib/stores/goals.svelte.ts create mode 100644 nutriphi/apps/web/src/lib/stores/meals.svelte.ts create mode 100644 nutriphi/apps/web/src/lib/stores/navigation.ts create mode 100644 nutriphi/apps/web/src/lib/stores/theme.ts create mode 100644 nutriphi/apps/web/src/lib/types/goal.ts create mode 100644 nutriphi/apps/web/src/lib/types/meal.ts create mode 100644 nutriphi/apps/web/src/lib/types/stats.ts create mode 100644 nutriphi/apps/web/src/routes/(protected)/+layout.svelte create mode 100644 nutriphi/apps/web/src/routes/(protected)/export/+page.svelte create mode 100644 nutriphi/apps/web/src/routes/(protected)/goals/+page.svelte create mode 100644 nutriphi/apps/web/src/routes/(protected)/meals/+page.svelte create mode 100644 nutriphi/apps/web/src/routes/(protected)/meals/[id]/+page.svelte create mode 100644 nutriphi/apps/web/src/routes/(protected)/settings/+page.svelte create mode 100644 nutriphi/apps/web/src/routes/(protected)/stats/+page.svelte create mode 100644 nutriphi/apps/web/src/routes/(protected)/subscription/+page.svelte create mode 100644 nutriphi/apps/web/src/routes/(protected)/upload/+page.svelte create mode 100644 nutriphi/apps/web/src/routes/(public)/+layout.svelte create mode 100644 nutriphi/apps/web/src/routes/(public)/login/+page.svelte create mode 100644 nutriphi/apps/web/src/routes/(public)/register/+page.svelte create mode 100644 nutriphi/apps/web/src/routes/+layout.svelte create mode 100644 nutriphi/apps/web/src/routes/+page.svelte create mode 100644 nutriphi/apps/web/svelte.config.js create mode 100644 nutriphi/apps/web/tsconfig.json create mode 100644 nutriphi/apps/web/vite.config.ts create mode 100644 nutriphi/backend/.env.example create mode 100644 nutriphi/backend/Dockerfile create mode 100644 nutriphi/backend/docker-compose.coolify.yml create mode 100644 nutriphi/backend/nest-cli.json create mode 100644 nutriphi/backend/package.json create mode 100644 nutriphi/backend/src/app.module.ts create mode 100644 nutriphi/backend/src/database/database.module.ts create mode 100644 nutriphi/backend/src/gemini/gemini.module.ts create mode 100644 nutriphi/backend/src/gemini/gemini.service.ts create mode 100644 nutriphi/backend/src/health/health.controller.ts create mode 100644 nutriphi/backend/src/health/health.module.ts create mode 100644 nutriphi/backend/src/main.ts create mode 100644 nutriphi/backend/src/meals/dto/analyze-meal.dto.ts create mode 100644 nutriphi/backend/src/meals/meals.controller.ts create mode 100644 nutriphi/backend/src/meals/meals.module.ts create mode 100644 nutriphi/backend/src/meals/meals.service.ts create mode 100644 nutriphi/backend/src/storage/storage.module.ts create mode 100644 nutriphi/backend/src/storage/storage.service.ts create mode 100644 nutriphi/backend/tsconfig.json create mode 100644 nutriphi/package.json create mode 100644 packages/nutriphi-database/.env.example create mode 100644 packages/nutriphi-database/docker-compose.yml create mode 100644 packages/nutriphi-database/drizzle.config.ts create mode 100644 packages/nutriphi-database/package.json create mode 100644 packages/nutriphi-database/src/client.ts create mode 100644 packages/nutriphi-database/src/index.ts create mode 100644 packages/nutriphi-database/src/schema/goals.ts create mode 100644 packages/nutriphi-database/src/schema/index.ts create mode 100644 packages/nutriphi-database/src/schema/meals.ts create mode 100644 packages/nutriphi-database/tsconfig.json diff --git a/nutriphi/.gitignore b/nutriphi/.gitignore new file mode 100644 index 000000000..1861e0868 --- /dev/null +++ b/nutriphi/.gitignore @@ -0,0 +1,25 @@ +node_modules/ +.expo/ +dist/ +npm-debug.* +*.jks +*.p8 +*.p12 +*.key +*.mobileprovision +*.orig.* +web-build/ +# expo router +expo-env.d.ts + +# firebase/supabase/vexo +.env + +ios +android + +# macOS +.DS_Store + +# Temporary files created by Metro to check the health of the file watcher +.metro-health-check* \ No newline at end of file diff --git a/nutriphi/CLAUDE.md b/nutriphi/CLAUDE.md new file mode 100644 index 000000000..6614de662 --- /dev/null +++ b/nutriphi/CLAUDE.md @@ -0,0 +1,171 @@ +# Nutriphi Project Guide + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +Nutriphi is a KI-gestĂŒtzter ErnĂ€hrungs-Tracker (AI-powered nutrition tracker) that uses Google Gemini Vision API to analyze food photos and provide detailed nutritional information. + +## Project Structure + +``` +nutriphi/ +├── apps/ +│ ├── mobile/ # Expo/React Native mobile app (@nutriphi/mobile) +│ ├── web/ # SvelteKit web application (@nutriphi/web) +│ └── landing/ # Astro marketing landing page (@nutriphi/landing) +├── backend/ # NestJS API server (@nutriphi/backend) +└── package.json +``` + +## Commands + +### Root Level (from monorepo root) +```bash +pnpm nutriphi:dev # Run all nutriphi apps +pnpm dev:nutriphi:mobile # Start mobile app +pnpm dev:nutriphi:web # Start web app +pnpm dev:nutriphi:landing # Start landing page +pnpm dev:nutriphi:backend # Start backend server +``` + +### Mobile App (nutriphi/apps/mobile) +```bash +pnpm dev # Start Expo dev server +pnpm ios # Run on iOS simulator +pnpm android # Run on Android emulator +pnpm build:dev # Build development version +pnpm build:preview # Build preview version +pnpm build:prod # Build production version +pnpm type-check # Run TypeScript checks +``` + +### Backend (nutriphi/backend) +```bash +pnpm start:dev # Start with hot reload +pnpm build # Build for production +pnpm start:prod # Start production server +pnpm type-check # Run TypeScript checks +``` + +### Web App (nutriphi/apps/web) +```bash +pnpm dev # Start dev server +pnpm build # Build for production +pnpm preview # Preview production build +pnpm type-check # Run type checks +``` + +### Landing Page (nutriphi/apps/landing) +```bash +pnpm dev # Start dev server +pnpm build # Build for production +pnpm preview # Preview production build +pnpm type-check # Run Astro checks +``` + +## Technology Stack + +- **Mobile**: React Native 0.79 + Expo SDK 53, NativeWind, Expo Router, Zustand +- **Web**: SvelteKit 2.x, Svelte 5, Tailwind CSS 4 +- **Landing**: Astro 5.x, Tailwind CSS +- **Backend**: NestJS 10, Google Gemini Vision API, Supabase +- **Authentication**: Mana Core Auth (shared with ecosystem) + +## Architecture + +### Backend API Endpoints + +| Endpoint | Method | Description | +|----------|--------|-------------| +| `/api/health` | GET | Health check | +| `/api/meals/analyze/image` | POST | Analyze food image with AI | +| `/api/meals/analyze/text` | POST | Analyze food description | +| `/api/meals` | POST | Create new meal entry | +| `/api/meals/user/:userId` | GET | Get user's meals | +| `/api/meals/user/:userId/summary` | GET | Get daily nutrition summary | +| `/api/meals/:id` | GET | Get meal by ID | +| `/api/meals/:id` | PUT | Update meal | +| `/api/meals/:id` | DELETE | Delete meal | + +### Environment Variables + +#### Backend (.env) +``` +GEMINI_API_KEY=your-gemini-api-key +SUPABASE_URL=https://your-project.supabase.co +SUPABASE_SERVICE_KEY=your-service-key +MANACORE_AUTH_URL=https://auth.manacore.de +PORT=3002 +``` + +#### Mobile (.env) +``` +EXPO_PUBLIC_SUPABASE_URL=https://your-project.supabase.co +EXPO_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key +EXPO_PUBLIC_BACKEND_URL=http://localhost:3002 +``` + +#### Web (.env) +``` +PUBLIC_SUPABASE_URL=https://your-project.supabase.co +PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key +PUBLIC_BACKEND_URL=http://localhost:3002 +``` + +## Key Features + +1. **AI Food Analysis**: Upload a photo of your meal and get instant nutritional information +2. **Manual Entry**: Enter food descriptions for text-based analysis +3. **Daily Tracking**: View daily summaries of calories, protein, carbs, fat, fiber +4. **Meal History**: Browse and edit past meal entries +5. **Health Tips**: Receive personalized nutrition recommendations + +## Mobile App Architecture + +### File Structure (apps/mobile) +- `app/` - Expo Router pages and layouts + - `(tabs)/` - Tab-based navigation screens + - `_layout.tsx` - Root layout with Stack navigation +- `components/` - Reusable UI components +- `store/` - Zustand state management +- `services/` - API and database services +- `hooks/` - Custom React hooks +- `utils/` - Utility functions + +### Styling +- NativeWind (Tailwind for React Native) +- Components use `className` prop with Tailwind utility classes + +### State Management +- Zustand stores for meals, user settings +- SQLite for local offline storage +- Supabase for cloud sync + +## Shared Packages Used + +- `@manacore/shared-auth-ui` - Authentication UI components +- `@manacore/shared-branding` - Branding assets +- `@manacore/shared-i18n` - Internationalization +- `@manacore/shared-icons` - Icon library +- `@manacore/shared-supabase` - Supabase client utilities +- `@manacore/shared-tailwind` - Tailwind configuration +- `@manacore/shared-theme` - Theme tokens +- `@manacore/shared-theme-ui` - Theme UI components +- `@manacore/shared-ui` - Common UI components +- `@manacore/shared-utils` - Utility functions + +## Code Style Guidelines + +- **TypeScript**: Strict typing with interfaces +- **Mobile**: Functional components with hooks +- **Web**: Svelte 5 runes mode +- **Styling**: Tailwind CSS everywhere +- **Formatting**: 100 char line limit, 2 space tabs, single quotes + +## Important Notes + +1. **Security**: API keys are stored in the backend only - never in client apps +2. **Authentication**: Uses Mana Core Auth, shared with ecosystem +3. **Database**: Supabase PostgreSQL with RLS policies +4. **Deployment**: Backend runs on port 3002 by default diff --git a/nutriphi/DoneSteps.md b/nutriphi/DoneSteps.md new file mode 100644 index 000000000..60c5ebd48 --- /dev/null +++ b/nutriphi/DoneSteps.md @@ -0,0 +1,381 @@ +# DoneSteps.md - Implementierungsfortschritt Nutriphi + +## Überblick +Dieses Dokument beschreibt alle erledigten Schritte bei der Implementierung der Nutriphi KI-Kalorien Tracker App basierend auf dem detaillierten Plan in `Plan.md`. + +## ✅ Phase 1: Foundations & Database (KOMPLETT) + +### 1.1 Projekt-Setup +- **Expo-Projekt mit TypeScript und NativeWind** ✅ + - Bestehende Basis-Konfiguration erweitert + - ZusĂ€tzliche Dependencies installiert: `expo-sqlite`, `expo-camera`, `expo-file-system`, `@google/generative-ai`, `react-native-uuid` + - Ordnerstruktur nach Plan erstellt: `services/`, `types/`, `hooks/` + +### 1.2 Erweiterte SQLite-Datenbank +- **VollstĂ€ndige Datenbankarchitektur implementiert** ✅ + - `meals` Tabelle mit allen geplanten Feldern (35+ Spalten) + - `food_items` Tabelle fĂŒr detaillierte Lebensmittel-Analyse + - `sync_metadata` Tabelle fĂŒr zukĂŒnftige Cloud-Sync + - Performance-Indizes fĂŒr optimierte Abfragen + - Dual-kompatible Struktur (lokal + Cloud-ready) + +### 1.3 Database Services & Migration System +- **SQLiteService.ts** ✅ + - Singleton-Pattern fĂŒr Datenbankzugriff + - VollstĂ€ndige CRUD-Operationen fĂŒr Meals und FoodItems + - Erweiterte Funktionen: Suche, Statistiken, Aggregationen + - Typsichere Implementierung mit TypeScript + +- **MigrationService.ts** ✅ + - Robustes Schema-Update-System + - Transaktionale Migrationen mit Rollback-FĂ€higkeit + - Versionierung und Konfliktlösung + - Bereits 3 Migrationen definiert fĂŒr zukĂŒnftige Updates + +### 1.4 TypeScript-Typdefinitionen +- **Database.ts** ✅ + - VollstĂ€ndige Interface-Definitionen fĂŒr alle DB-Tabellen + - Input/Output-Typen fĂŒr API-Operationen + - Union-Types fĂŒr Enums (meal_type, analysis_status, etc.) + +- **API.ts** ✅ + - Gemini API Response-Strukturen + - Error-Handling-Typen + - Prompt-Context-Definitionen + +## ✅ Phase 2: Core UI & Camera (KOMPLETT) + +### 2.1 UI-Komponenten-Bibliothek +- **Basis-UI-Komponenten** ✅ + - `Card.tsx`: Wiederverwendbare Card-Komponente mit Varianten + - `LoadingSpinner.tsx`: Zentralisierte Loading-States + - `FloatingActionButton.tsx`: Erweitert mit `size` und `position` Props fĂŒr flexible Positionierung + +### 2.2 MealList mit NativeWind +- **MealList.tsx** ✅ + - VollstĂ€ndige Liste mit Pull-to-Refresh + - Integrierte Suchfunktion + - Überarbeiteter Empty State ohne redundanten Button + - Error-Handling mit Retry-Mechanismus + +- **MealItem.tsx** ✅ + - Rich Meal Cards mit Foto-Preview + - Nutrition Summary (kompakt) + - Status-Badges fĂŒr Analyse-Status + - Benutzer-Bewertungen und Notizen + - Relative Zeitanzeigen ("2h ago") + +- **NutritionBar.tsx** ✅ + - Detaillierte und kompakte Modi + - Visuell ansprechende MakronĂ€hrstoff-Darstellung + - Gesundheitsscore mit Farbkodierung + - Responsive Progress-Bars + +### 2.3 Camera & Gallery Integration +- **Erweiterte Photo-Services** ✅ + - `PhotoService.ts`: Foto-Management mit lokaler Speicherung + - `useCamera.ts`: Hook erweitert um `pickImageFromGallery()` Funktion + - Automatische Temp-File-Cleanup + - Storage-Statistiken + - `expo-image-picker` Integration mit Permission-Handling + +- **Camera-UI-Komponenten** ✅ + - `CameraModal.tsx`: Vollscreen-Kamera mit mode-based FunktionalitĂ€t + - `PhotoButton.tsx`: Animierter Auslöse-Button mit Capturing-States + - `PhotoPreview.tsx`: Foto-Vorschau mit Benutzer-Feedback + - Native Kamera-Controls (Flip, Close) + - Auto-Gallery-Picker fĂŒr Gallery-Modus + +### 2.4 State Management mit Zustand +- **MealStore.ts** ✅ + - VollstĂ€ndige Meal-CRUD-Operationen + - Optimistische Updates + - Error-Handling mit User-Feedback + - Search-Integration + +- **AppStore.ts** ✅ + - Globaler App-Zustand + - UI-State-Management (Modals, Processing) + - User-Preferences-Struktur + - Stats-Caching-System + - `cameraMode` State fĂŒr Kamera/Galerie-Modi + +### 2.5 App-Integration +- **Database-Initialisierung** ✅ + - `useDatabase.ts`: Hook fĂŒr DB-Setup mit Loading-States + - Integration in `_layout.tsx` mit User-Feedback + - Migration-AusfĂŒhrung beim App-Start + +- **Navigation & Layout** ✅ + - Tab-Navigation mit FontAwesome Icons (cutlery, bar-chart) + - CameraModal-Integration mit mode-based Rendering + - Konsistente Header-Styles + - Dual Floating Action Buttons (Camera + Gallery) + +## ✅ Phase 2.5: Gallery Integration & UX Enhancement (KOMPLETT) + +### 2.6 Gallery-FunktionalitĂ€t +- **expo-image-picker Integration** ✅ + - Native Galerie-Zugriff mit automatischen Permissions + - Image-Editing mit 4:3 Aspect Ratio Cropping + - QualitĂ€ts-Optimierung (0.8) fĂŒr Performance + - Identische PhotoService-Integration wie Kamera + +### 2.7 Streamlined User Experience +- **Dual Floating Action Button System** ✅ + - đŸ“· **Kamera-Button**: GrĂ¶ĂŸer (80x80px), zentriert positioniert + - đŸ–Œïž **Galerie-Button**: Normal (64x64px), rechts positioniert + - Direkter Workflow ohne Auswahl-MenĂŒ + - Smooth Animationen mit React Native Reanimated + +- **Vereinfachter UI-Flow** ✅ + - "Add Your First Meal" Button entfernt fĂŒr cleaner Design + - Empty State Text ĂŒberarbeitet + - PhotoSourceSelector Komponente entfernt + - Mode-based CameraModal (camera/gallery) + +### 2.8 App-Konfiguration +- **Permissions Setup** ✅ + - Camera Permission: "Allow Nutriphi to access your camera to take photos of your meals for nutritional analysis." + - Photos Permission: "Allow Nutriphi to access your photo library to select existing meal photos." + - Automatische Permission-Requests mit Fallback-Handling + +## 🔄 Aktueller Status + +### Was funktioniert: +1. **VollstĂ€ndige lokale Datenpersistierung** - Alle Mahlzeiten werden in SQLite gespeichert +2. **Dual Photo Input** - Fotos können sowohl per Kamera aufgenommen als auch aus Galerie gewĂ€hlt werden +3. **Streamlined UX-Flow** - Direkter Zugang zu beiden Modi ohne Umwege +4. **UI/UX-Flow** - Kompletter Benutzerflow von Foto bis Datenbankpeicherung +5. **Responsive Design** - Alle Komponenten mit NativeWind/Tailwind optimiert +6. **State Management** - Reaktive Updates zwischen allen Komponenten +7. **Error Handling** - Robuste Fehlerbehandlung auf allen Ebenen + +### Bereit fĂŒr nĂ€chste Phase: +- Datenbank und Services sind vollstĂ€ndig KI-Integration-ready +- Photo-Service kann Base64-Konvertierung fĂŒr Gemini API +- Meal-Records haben alle notwendigen Felder fĂŒr AI-Analyse +- UI zeigt bereits Analysis-Status und kann AI-Ergebnisse darstellen + +## 🎯 Technische Highlights + +### Architektur-QualitĂ€t: +- **Typsicherheit**: 100% TypeScript mit strikten Typen +- **Separation of Concerns**: Klare Trennung zwischen UI, Business Logic und Data Layer +- **Skalierbarkeit**: Modulare Struktur fĂŒr einfache Erweiterungen +- **Performance**: Optimierte DB-Indizes und React-Patterns + +### Code-QualitĂ€t: +- **Linting**: Alle ESLint-Regeln befolgt +- **Formatting**: Konsistente Prettier-Formatierung +- **Patterns**: React Hooks, Custom Hooks, Singleton Services +- **Error Boundaries**: Graceful Error-Handling ĂŒberall + +### UX-Features: +- **Smooth Animations**: React Native Reanimated fĂŒr 60fps +- **Dual Input Methods**: Kamera + Galerie fĂŒr maximale FlexibilitĂ€t +- **Intuitive UI**: Große, zentrale Kamera-Button fĂŒr Hauptfunktion +- **Loading States**: Benutzer wird immer ĂŒber App-Status informiert +- **Offline-First**: Funktioniert komplett ohne Internet +- **Progressive Enhancement**: Bereit fĂŒr Cloud-Features + +## ✅ Phase 3: Gemini AI Integration (KOMPLETT) + +### 3.1 Gemini API Service +- **GeminiService.ts** ✅ + - VollstĂ€ndige Integration mit Google Generative AI + - Optimierte Multi-Shot Prompts fĂŒr ErnĂ€hrungsanalyse + - Strukturierte JSON-Responses mit Validation + - Retry-Mechanismen mit exponential backoff + - Timeout-Handling (60s) fĂŒr API-StabilitĂ€t + - Base64-Bildkonvertierung mit FileSystem + +### 3.2 AI-Analyse-Features +- **Intelligente Lebensmittel-Erkennung** ✅ + - Automatische Erkennung von Mahlzeiten und Zutaten + - PortionsgrĂ¶ĂŸen-SchĂ€tzung + - NĂ€hrwert-Berechnung (Kalorien, Protein, Kohlenhydrate, Fett, etc.) + - Gesundheitsscore-Bewertung (0-100) + - Allergen-Erkennung + - Bio/Verarbeitet-Klassifizierung + +### 3.3 Background Processing +- **Asynchrone Foto-Analyse** ✅ + - Foto-Upload und sofortige UI-RĂŒckkehr + - Background-Verarbeitung mit Gemini API + - Automatische Datenbank-Updates nach Analyse + - Status-Updates (pending → completed/failed) + +### 3.4 UI-Integration +- **AnalysisStatusIndicator.tsx** ✅ + - Visueller Status-Indikator mit Loading-Animation + - Mini und Normal Modi fĂŒr verschiedene UI-Kontexte + - Farbkodierte Status (gelb=pending, grĂŒn=completed, rot=failed) + +- **Meal Detail Enhancements** ✅ + - Auto-Polling wĂ€hrend Analyse lĂ€uft (alle 2 Sekunden) + - Dynamische UI-Updates nach Analyse-Completion + - Detaillierte NĂ€hrwert-Anzeige + - Food-Item-Liste mit Confidence-Scores + +## ✅ Phase 3.5: Performance & Stability (KOMPLETT) + +### 3.5 Bug Fixes & Optimierungen +- **Kritische Fehler behoben** ✅ + - Text-Rendering-Error in FoodItemCard (Allergen-Array-Handling) + - Bildpfad-Problem nach temp→permanent Konvertierung + - Doppeltes `file://` PrĂ€fix entfernt + - Error-Handling fĂŒr fehlende Bilder mit Fallback-UI + +- **Performance-Optimierungen** ✅ + - Batch-Insert fĂŒr Food Items (createFoodItemsBatch) + - Transaktionale DB-Updates + - Intelligentes State-Management mit selective Reloads + - Optimierte Meal-Updates nach Analyse + +- **Cleanup & Maintenance** ✅ + - PhotoService prĂŒft Verzeichnis-Existenz + - Graceful Handling von nicht-existierenden Ordnern + - Verbesserte Temp-File-Cleanup-Logik + - Console-Logs fĂŒr besseres Debugging + +### 3.6 Technische Verbesserungen +- **Database Layer** ✅ + - SQLite-Transaktionen fĂŒr Batch-Operations + - Rollback-FĂ€higkeit bei Fehlern + - Optimierte Queries mit Indizes + +- **State Management** ✅ + - Automatisches Reload von MealWithItems nach Analyse + - Konsistente Updates zwischen Liste und Detail-View + - Optimistische UI-Updates + +- **Error Resilience** ✅ + - Retry-Mechanismen fĂŒr Gemini API + - Graceful Degradation bei API-Fehlern + - User-freundliche Fehlermeldungen + +## ✅ Phase 4: Advanced Features (KOMPLETT) + +### 4.1 Context Menu Integration +- **Native Context Menu** ✅ + - Long-Press auf MealCard aktiviert natives Context Menu + - iOS/Android native Look & Feel mit `react-native-context-menu-view` + - Haptic Feedback bei Aktionen + - Conditional Actions basierend auf Meal-Status + +- **Context Menu Actions** ✅ + - 📝 **Bearbeiten**: Öffnet Edit Modal fĂŒr Notizen/Rating/Location + - ⭐ **Bewerten**: Schnellbewertung mit Sub-Menu (1-5 Sterne) + - đŸ“€ **Teilen**: System Share Sheet fĂŒr NĂ€hrwerte + - 📋 **Kopieren**: NĂ€hrwerte in Zwischenablage + - 🔄 **Erneut analysieren**: Bei fehlgeschlagener Analyse + - đŸ—‘ïž **Löschen**: Mit BestĂ€tigungsdialog (destruktive Action) + +- **EditMealModal.tsx** ✅ + - Modal fĂŒr Meal-Bearbeitung + - Sterne-Bewertung mit Touch-Feedback + - Location-Bearbeitung + - Notizen-Eingabe mit Multiline-Support + - Optimistisches UI-Update + +### 4.2 Location Tracking +- **Automatische GPS-Erfassung** ✅ + - GPS-Koordinaten werden beim Foto-Capture erfasst + - Reverse Geocoding fĂŒr lesbare Adressen + - Smart Location-Formatting (Name > Street > City) + - Distanz-Berechnungen mit Haversine-Formel + +- **LocationService.ts** ✅ + - Permission Handling (Check & Request) + - getCurrentLocation() mit High Accuracy + - reverseGeocode() fĂŒr Adress-Konvertierung + - isNearLocation() fĂŒr Geofencing-Features + +- **Location Privacy** ✅ + - LocationPermissionModal beim ersten Mal + - UserPreferencesService fĂŒr persistente Settings + - Location On/Off Toggle in Settings + - Opt-in Ansatz - Privacy by Design + +### 4.3 Enhanced Settings +- **Erweiterte Settings-Seite** ✅ + - Neue "PrivatsphĂ€re & Standort" Sektion + - Location-Toggle mit Echtzeit-Updates + - Link zu System-Einstellungen + - UserPreferences mit Cache-Layer + +- **UserPreferencesService.ts** ✅ + - Zentrale Verwaltung aller PrĂ€ferenzen + - SQLite-basierte Persistierung + - Type-safe Interface + - Batch-Update-FĂ€higkeit + +### 4.4 Database Enhancements +- **Location-Felder in Meals** ✅ + - latitude, longitude, location_accuracy + - Migration #4 fĂŒr bestehende DBs + - Geo-Index fĂŒr Location-Queries + - RĂŒckwĂ€rtskompatibel + +### 4.5 Critical Bug Fixes +- **Location Feature StabilitĂ€t** ✅ + - App-Absturz beim Bildauswahl mit aktiviertem Standort behoben + - getDatabase() Methode zu SQLiteService hinzugefĂŒgt + - user_preferences Tabelle wird in SQLiteService.createTables() erstellt + - UserPreferencesService mit Resilience gegen DB-Timing-Issues + - Cache-First Approach fĂŒr sofortige UI-Updates + - Graceful Degradation wenn DB-Tabellen noch nicht existieren + +- **iOS Location Permission** ✅ + - expo-location Plugin bereits in app.json konfiguriert + - Benötigt Rebuild (expo prebuild) fĂŒr System-Settings-Eintrag + - Permission-Text fĂŒr klare Nutzer-Kommunikation + +- **Settings Toggle Fix** ✅ + - Location-Toggle in App-Settings funktioniert jetzt zuverlĂ€ssig + - Cache wird sofort aktualisiert fĂŒr responsive UI + - Fallback zu Default-Werten bei DB-Fehlern + +## 🎯 Aktueller Status (Stand: 17.01.2025) + +### VollstĂ€ndig implementierte Features: +1. **KI-gestĂŒtzte ErnĂ€hrungsanalyse** - Automatische Erkennung und Analyse von Mahlzeiten +2. **Real-time Updates** - Live-Status wĂ€hrend der Analyse mit Auto-Polling +3. **Context Menu** - Native Long-Press Menu mit 6+ Aktionen +4. **Location Tracking** - Automatische GPS-Erfassung mit Privacy-First +5. **Advanced Settings** - Umfangreiche Einstellungsmöglichkeiten +6. **Robuste Fehlerbehandlung** - Graceful Error-Handling auf allen Ebenen +7. **Performance-optimiert** - Batch-Operations und intelligentes State-Management +8. **VollstĂ€ndige Offline-FunktionalitĂ€t** - Lokale Speicherung aller Daten +9. **Intuitive BenutzeroberflĂ€che** - Klare Status-Indikatoren und Feedback + +### Technische Highlights: +- **100% TypeScript** mit strikten Typen +- **Reaktive Updates** durch Zustand State Management +- **Modulare Architektur** fĂŒr einfache Erweiterbarkeit +- **Performance-optimiert** mit SQLite-Transaktionen +- **Production-ready** Error-Handling und Logging +- **Privacy-First** Design mit expliziten Permissions +- **Native UI-Elemente** fĂŒr beste User Experience + +### App-Metriken: +- **Analyse-Zeit**: ~13 Sekunden pro Foto (Gemini API) +- **Genauigkeit**: 85%+ Confidence-Score bei guten Fotos +- **StabilitĂ€t**: Robuste Fehlerbehandlung verhindert Crashes +- **UX**: Sofortiges Feedback, keine blockierende UI +- **Privacy**: Opt-in Location, lokale Datenhaltung + +## 📋 NĂ€chste Schritte (Phase 4+) + +### Geplante Features: +1. **Cloud-Sync** mit Supabase-Backend +2. **Erweiterte Statistiken** und Trends +3. **Benutzerdefinierte ErnĂ€hrungsziele** +4. **Export-Funktionen** (CSV, PDF) +5. **Social-Features** (Teilen, Vergleichen) +6. **Barcode-Scanner** fĂŒr verpackte Lebensmittel +7. **Rezept-Erkennung** und VorschlĂ€ge +8. **Apple Health Integration** + +Die App ist jetzt voll funktionsfĂ€hig als KI-gestĂŒtzter Kalorien-Tracker mit robuster lokaler Datenhaltung und fortschrittlicher Bildanalyse! \ No newline at end of file diff --git a/nutriphi/Plan.md b/nutriphi/Plan.md new file mode 100644 index 000000000..5bb8ef177 --- /dev/null +++ b/nutriphi/Plan.md @@ -0,0 +1,357 @@ + + +MVP Projektplan: KI-Kalorien Tracker Nutriphi (Finaler Plan) +1. Projekt-Übersicht +Ziel: React Native App mit Expo fĂŒr automatische KalorienschĂ€tzung durch Foto-Analyse Architektur: Local-First mit optionaler Cloud-Synchronisation (Supabase-ready) UI-Framework: NativeWind (Tailwind CSS fĂŒr React Native) Sync-Strategy: Bidirektionale Synchronisation mit Konfliktlösung +2. Technologie-Stack +Frontend +* React Native: 0.73+ +* Expo SDK: 50+ +* TypeScript: VollstĂ€ndige Typisierung +* NativeWind: 2.0+ fĂŒr Styling +* React Navigation: 6.x fĂŒr Navigation +* Zustand: Lightweight State Management +* Expo Camera: Foto-Aufnahme +* React Native Reanimated: Smooth Animationen +Datenschicht +* Expo SQLite: PrimĂ€re lokale Datenbank +* Expo FileSystem: Lokale Foto-Speicherung +* AsyncStorage: App-Einstellungen +* Supabase: Cloud-Backend (optional, spĂ€ter) +* Supabase Storage: Cloud-Foto-Speicherung +KI & APIs +* Google Gemini Vision API: PrimĂ€re Bilderkennung +* Optimierter Prompt: Strukturierte NĂ€hrwert-Analyse +* Fallback-System: Graceful Degradation bei API-Fehlern +Development Tools +* Expo Dev Tools: Development Environment +* TypeScript: Compile-time Type Safety +* ESLint + Prettier: Code Quality +* Jest: Unit Testing +3. Erweiterte Datenbank-Architektur +Haupttabelle: meals (Dual-kompatibel) + +sql +CREATE TABLE meals ( + -- PrimĂ€rschlĂŒssel (dual-kompatibel) + id INTEGER PRIMARY KEY AUTOINCREMENT, -- SQLite + cloud_id TEXT UNIQUE, -- UUID fĂŒr Supabase + + -- Sync-Metadaten + user_id TEXT, -- NULL lokal, UUID in Cloud + sync_status TEXT DEFAULT 'local', -- local, synced, conflict, pending + version INTEGER DEFAULT 1, -- FĂŒr Konfliktlösung + last_sync_at TEXT, -- ISO DateTime + + -- Foto & Metadaten + photo_path TEXT NOT NULL, -- Lokaler Pfad + photo_url TEXT, -- Cloud Storage URL + photo_size INTEGER, -- DateigrĂ¶ĂŸe in Bytes + photo_dimensions TEXT, -- JSON: {"width": 1920, "height": 1080} + + -- Zeitstempel + timestamp TEXT DEFAULT (datetime('now')), + created_at TEXT DEFAULT (datetime('now')), + updated_at TEXT DEFAULT (datetime('now')), + + -- Mahlzeit-Kontext + meal_type TEXT, -- breakfast, lunch, dinner, snack + location TEXT, -- Optional: GPS oder manuell + + -- KI-Analyse Ergebnisse + analysis_result TEXT, -- VollstĂ€ndiges JSON der Gemini-Antwort + analysis_confidence REAL, -- 0.0 - 1.0 + analysis_status TEXT DEFAULT 'pending', -- pending, completed, failed, manual + + -- Aggregierte NĂ€hrwerte + total_calories INTEGER, + total_protein REAL, + total_carbs REAL, + total_fat REAL, + total_fiber REAL, + total_sugar REAL, + + -- Gesundheitsbewertung + health_score REAL, -- 1.0 - 10.0 + health_category TEXT, -- very_healthy, healthy, moderate, unhealthy + + -- User-Interaktion + user_notes TEXT, + user_modified INTEGER DEFAULT 0, -- Boolean als Integer + user_rating INTEGER, -- 1-5 Sterne fĂŒr KI-Genauigkeit + + -- API-Metadaten + api_provider TEXT DEFAULT 'gemini', + api_cost REAL, -- Kosten in Cent + processing_time INTEGER -- Millisekunden +); +Detailtabelle: food_items + +sql +CREATE TABLE food_items ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + cloud_id TEXT UNIQUE, + meal_id INTEGER NOT NULL, + + -- Sync-Metadaten + sync_status TEXT DEFAULT 'local', + version INTEGER DEFAULT 1, + + -- Lebensmittel-Details + name TEXT NOT NULL, + category TEXT, -- protein, vegetable, grain, fruit, dairy, fat, processed, beverage + portion_size TEXT, -- "150g", "1 StĂŒck", "1 Tasse" + + -- NĂ€hrwerte pro Item + calories INTEGER, + protein REAL, + carbs REAL, + fat REAL, + fiber REAL, + sugar REAL, + + -- KI-Metadaten + confidence REAL, -- 0.0 - 1.0 + bounding_box TEXT, -- JSON: Position im Bild + + -- Eigenschaften + is_organic INTEGER DEFAULT 0, + is_processed INTEGER DEFAULT 0, + allergens TEXT, -- JSON Array + + created_at TEXT DEFAULT (datetime('now')), + + FOREIGN KEY (meal_id) REFERENCES meals(id) ON DELETE CASCADE +); +Sync-Metadaten + +sql +CREATE TABLE sync_metadata ( + table_name TEXT NOT NULL, + record_id INTEGER NOT NULL, + cloud_id TEXT, + last_sync_at TEXT, + conflict_data TEXT, -- JSON fĂŒr Konfliktlösung + retry_count INTEGER DEFAULT 0, + + PRIMARY KEY (table_name, record_id) +); +Performance-Indizes + +sql +CREATE INDEX idx_meals_timestamp ON meals(timestamp DESC); +CREATE INDEX idx_meals_sync_status ON meals(sync_status); +CREATE INDEX idx_meals_meal_type ON meals(meal_type); +CREATE INDEX idx_food_items_meal ON food_items(meal_id); +CREATE INDEX idx_food_items_category ON food_items(category); +CREATE INDEX idx_sync_metadata_status ON sync_metadata(table_name, last_sync_at); +4. Optimierter Gemini Prompt +Haupt-Prompt-Template: + +Du bist ein professioneller ErnĂ€hrungsexperte. Analysiere dieses Essen-Foto prĂ€zise und detailliert. + +AUFGABE: +1. Erkenne alle sichtbaren Lebensmittel und schĂ€tze realistische PortionsgrĂ¶ĂŸen +2. Berechne NĂ€hrwerte basierend auf Standard-Portionen +3. Bewerte die Gesundheit der gesamten Mahlzeit +4. BerĂŒcksichtige versteckte Zutaten (Öle, Saucen, GewĂŒrze) + +ANTWORT-FORMAT (nur JSON, keine zusĂ€tzlichen Texte): +{ + "meal_analysis": { + "total_calories": , + "total_protein": , + "total_carbs": , + "total_fat": , + "total_fiber": , + "total_sugar": , + "health_score": <1.0-10.0>, + "health_category": "healthy|moderate|unhealthy", + "confidence": <0.0-1.0>, + "meal_type_suggestion": "breakfast|lunch|dinner|snack" + }, + "food_items": [ + { + "name": "Gegrilltes HĂ€hnchen", + "category": "protein", + "portion_size": "120g", + "calories": 180, + "protein": 27.0, + "carbs": 0.0, + "fat": 7.5, + "fiber": 0.0, + "sugar": 0.0, + "confidence": 0.9, + "is_organic": false, + "is_processed": false, + "allergens": [] + } + ], + "analysis_notes": { + "health_reasoning": "Ausgewogene Mahlzeit mit hochwertigem Protein und GemĂŒse", + "improvement_suggestions": [ + "Mehr Vollkornprodukte hinzufĂŒgen", + "Portion der Kohlenhydrate erhöhen" + ], + "cooking_method": "grilled", + "estimated_freshness": "fresh", + "hidden_ingredients": ["Olivenöl (1 TL)", "GewĂŒrze"], + "portion_accuracy": "high" + } +} + +BEWERTUNGSKRITERIEN health_score: +10: Optimal (viel GemĂŒse, mageres Protein, Vollkorn, minimal verarbeitet) +8-9: Sehr gesund (ausgewogen, natĂŒrliche Zutaten) +6-7: Gesund (gute Balance, moderate Verarbeitung) +4-5: MittelmĂ€ĂŸig (gemischt, einige verarbeitete Komponenten) +2-3: Ungesund (viel verarbeitet, hoher Zucker/Fett) +1: Sehr ungesund (Fast Food, stark verarbeitet) + +KATEGORIEN: +- protein: Fleisch, Fisch, Eier, HĂŒlsenfrĂŒchte, NĂŒsse +- vegetable: Alle GemĂŒsesorten +- grain: Reis, Nudeln, Brot, Getreide +- fruit: Alle FrĂŒchte +- dairy: Milchprodukte +- fat: Öle, Butter, Avocado +- processed: Verarbeitete Lebensmittel +- beverage: GetrĂ€nke + +WICHTIG: +- Realistische PortionsgrĂ¶ĂŸen (Deutsche Standards) +- Kalorien auf 5er-Schritte runden +- Bei Unsicherheit: confidence reduzieren +- Versteckte Fette/Öle nicht vergessen +- Mehrere gleiche Items separat listen +Kontext-spezifische Erweiterungen: + +typescript +const promptContexts = { + breakfast: "KONTEXT: FrĂŒhstĂŒck - berĂŒcksichtige typische deutsche FrĂŒhstĂŒcksportionen", + restaurant: "KONTEXT: Restaurant - grĂ¶ĂŸere Portionen, mehr versteckte Fette wahrscheinlich", + homemade: "KONTEXT: Hausgemacht - tendenziell gesĂŒnder, weniger versteckte ZusĂ€tze", + fastfood: "KONTEXT: Fast Food - höhere Kaloriendichte, mehr verarbeitete Zutaten" +}; +5. App-Architektur +Ordnerstruktur: + +src/ +├── components/ +│ ├── ui/ # Basis UI-Komponenten +│ │ ├── Button.tsx +│ │ ├── Card.tsx +│ │ └── LoadingSpinner.tsx +│ ├── meals/ # Mahlzeit-spezifische Komponenten +│ │ ├── MealList.tsx +│ │ ├── MealItem.tsx +│ │ ├── MealDetail.tsx +│ │ └── NutritionBar.tsx +│ ├── camera/ # Kamera-Komponenten +│ │ ├── CameraModal.tsx +│ │ ├── PhotoPreview.tsx +│ │ └── PhotoButton.tsx +│ └── sync/ # Sync-UI-Komponenten +│ ├── SyncStatus.tsx +│ └── ConflictResolver.tsx +├── services/ +│ ├── database/ +│ │ ├── SQLiteService.ts # Lokale Datenbank +│ │ ├── SyncService.ts # Synchronisation +│ │ └── MigrationService.ts # Schema-Updates +│ ├── api/ +│ │ ├── GeminiService.ts # KI-Integration +│ │ └── SupabaseService.ts # Cloud-Backend +│ ├── storage/ +│ │ ├── PhotoService.ts # Foto-Management +│ │ └── CacheService.ts # Lokaler Cache +│ └── utils/ +│ ├── DateUtils.ts +│ ├── NutritionUtils.ts +│ └── ValidationUtils.ts +├── stores/ +│ ├── MealStore.ts # Zustand fĂŒr Mahlzeiten +│ ├── SyncStore.ts # Synchronisation-Status +│ └── AppStore.ts # Globaler App-Zustand +├── types/ +│ ├── Database.ts # Datenbank-Typen +│ ├── API.ts # API-Response-Typen +│ └── UI.ts # UI-Komponenten-Typen +├── hooks/ +│ ├── useMeals.ts # Mahlzeit-Management +│ ├── useCamera.ts # Kamera-Funktionen +│ └── useSync.ts # Synchronisation +└── utils/ + ├── constants.ts + ├── config.ts + └── helpers.ts +6. Implementierungsphasen +Phase 1: Foundations & Database +Fokus: Solide Basis schaffen +* Expo-Projekt mit TypeScript und NativeWind setup +* Erweiterte SQLite-Datenbank implementieren +* Basis-Services fĂŒr Database-Operations +* Migration-System fĂŒr Schema-Updates +* Grundlegende App-Navigation +Phase 2: Core UI & Camera +Fokus: Basis-FunktionalitĂ€t implementieren +* MealList mit erweiterten NativeWind-Komponenten +* Floating Action Button mit Animationen +* Camera-Modal mit Vorschau-FunktionalitĂ€t +* Foto-Speicherung im lokalen FileSystem +* Basic Loading-States und Error-Handling +Phase 3: AI Integration & Analysis +Fokus: Gemini API vollstĂ€ndig integrieren +* Optimierten Prompt-Service implementieren +* Robuste API-Error-Handling-Strategien +* Retry-Mechanismus mit exponential backoff +* Offline-Queue fĂŒr fehlgeschlagene Requests +* Erweiterte NĂ€hrwert-Darstellung in UI +Phase 4: Enhanced UX & Data Visualization +Fokus: User Experience verbessern +* Detailansicht fĂŒr einzelne Mahlzeiten +* NĂ€hrwert-Visualisierung (Balken, Kreise) +* Tagesstatistiken und einfache Trends +* User-Korrektur-Interface fĂŒr KI-Ergebnisse +* Mahlzeit-Typ-Erkennung und -Kategorisierung +Phase 5: Sync Preparation & Cloud-Ready +Fokus: FĂŒr Cloud-Sync vorbereiten +* Sync-Metadaten in lokaler Datenbank +* Data-Transformation-Layer implementieren +* Conflict-Resolution-Algorithmus +* Settings-Screen fĂŒr Sync-PrĂ€ferenzen +* Export/Import-FunktionalitĂ€t als Backup +Phase 6: Supabase Integration (Optional) +Fokus: Cloud-Synchronisation aktivieren +* Supabase-Client-Setup und Authentication +* Bidirektionale Sync-Implementation +* Photo-Upload zu Supabase Storage +* Real-time Conflict-Resolution +* Multi-Device-Support +7. MVP Success Criteria +Funktionale Anforderungen: +✅ Core Functionality +* Foto aufnehmen und lokal speichern +* Gemini API erfolgreich aufrufen +* Strukturierte NĂ€hrwert-Analyse erhalten +* Daten persistent in SQLite speichern +✅ User Experience +* Intuitive Ein-Screen-App mit Liste +* Smooth Kamera-Integration +* VerstĂ€ndliche NĂ€hrwert-Darstellung +* Responsive UI mit NativeWind +✅ Data Quality +* Realistische KalorienschĂ€tzungen (±20% Genauigkeit) +* VollstĂ€ndige NĂ€hrwert-Breakdown +* Plausible Gesundheitsbewertungen +* Robuste Error-Handling +Performance-Anforderungen: +* App-Start unter 3 Sekunden +* Foto-zu-Analyse unter 15 Sekunden +* Smooth 60fps Scrolling in Meal-Liste +* Maximaler Memory-Footprint: 100MB +StabilitĂ€t: +* Keine Crashes bei normaler Nutzung +* Graceful Degradation bei API-Fehlern +* Offline-Foto-Speicherung funktioniert zuverlĂ€ssig +* Daten-IntegritĂ€t bei App-Kills gewĂ€hrleistet diff --git a/nutriphi/ReadMes/Expo-ImagePicker.md b/nutriphi/ReadMes/Expo-ImagePicker.md new file mode 100644 index 000000000..583016167 --- /dev/null +++ b/nutriphi/ReadMes/Expo-ImagePicker.md @@ -0,0 +1,799 @@ +Expo ImagePicker + + +A library that provides access to the system's UI for selecting images and videos from the phone's library or taking a photo with the camera. + +Bundled version: +~16.1.4 +expo-image-picker provides access to the system's UI for selecting images and videos from the phone's library or taking a photo with the camera. + +Installation +Terminal + +Copy + +npx expo install expo-image-picker +If you are installing this in an existing React Native app, make sure to install expo in your project. + +Known issues  +On iOS, when an image (usually of a higher resolution) is picked from the camera roll, the result of the cropped image gives the wrong value for the cropped rectangle in some cases. Unfortunately, this issue is with the underlying UIImagePickerController due to a bug in the closed-source tools built into iOS. + +Configuration in app config +You can configure expo-image-picker using its built-in config plugin if you use config plugins in your project (EAS Build or npx expo run:[android|ios]). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect. + +Example app.json with config plugin +app.json + +Copy + + +{ + "expo": { + "plugins": [ + [ + "expo-image-picker", + { + "photosPermission": "The app accesses your photos to let you share them with your friends." + } + ] + ] + } +} +Configurable properties +Name Default Description +photosPermission "Allow $(PRODUCT_NAME) to access your photos" +Only for:  + +A string to set the NSPhotoLibraryUsageDescription permission message. + +cameraPermission "Allow $(PRODUCT_NAME) to access your camera" +Only for:  + +A string to set the NSCameraUsageDescription permission message. + +microphonePermission "Allow $(PRODUCT_NAME) to access your microphone" +Only for:  + +A string to set the NSMicrophoneUsageDescription permission message. + +Are you using this library in an existing React Native app? +Usage +Image Picker + +Copy + + +Open in Snack + + +import { useState } from 'react'; +import { Button, Image, View, StyleSheet } from 'react-native'; +import * as ImagePicker from 'expo-image-picker'; + +export default function ImagePickerExample() { + const [image, setImage] = useState(null); + + const pickImage = async () => { + // No permissions request is necessary for launching the image library + let result = await ImagePicker.launchImageLibraryAsync({ + mediaTypes: ['images', 'videos'], + allowsEditing: true, + aspect: [4, 3], + quality: 1, + }); + + console.log(result); + + if (!result.canceled) { + setImage(result.assets[0].uri); + } + }; + + return ( + +