Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/arshad1416_grocery-app-kimi-k3.json
T

1 line
6.6 KiB
JSON

{"repo": "arshad1416/grocery-app-kimi-k3", "files": {"GroceryApp/src/services/BARCODE_FEATURE.md": {"f1e5d0c52d17fd046a230e400ce856daacac0a02": {"t": 1785596355.88107, "n": 6177, "h": "9386eacd778f2c59", "c": "# Barcode Scanner + Product Database Feature\n\n## What Was Built\n\n### New Files\n\n| File | Purpose |\n|------|---------|\n| `src/types/product.ts` | ProductInfo, ScanResult, NewProductSubmission types |\n| `src/services/productCache.ts` | In-memory session cache (max 200 items) |\n| `src/services/tursoClient.ts` | HTTP client for Turso `/v2/pipeline` API (zero native deps) |\n| `src/services/tursoMigrations.ts` | SQL migrations for `products` + `product_prices` tables |\n| `src/services/productLookup.ts` | Lookup chain: cache → Turso → Open Food Facts → USDA |\n| `src/services/aiCleanup.ts` | Heuristic + AI product name normalization (MiMo via OpenCode Go) |\n| `src/components/BarcodeScannerScreen.tsx` | Full-screen barcode scanner (expo-camera, EAN-13/UPC) |\n\n### Modified Files\n\n| File | Change |\n|------|--------|\n| `src/types/index.ts` | ~~Added Turso url/token/enabled to AppSettings~~ **Removed in v1** — client-held Turso credentials are extractable from the built app (see GOAL_PROMPT_NOTES.md) |\n| `App.tsx` | ~~Adds Turso init after device identity setup~~ **Removed in v1** — Turso is never initialized client-side |\n| `src/screens/AddItemSheet.tsx` | Scan button, scanner overlay, lookup, new-product form |\n\n---\n\n## What You Need to Do to Activate\n\n### 1. Install expo-camera (barcode scanning)\n\n```bash\nnpx expo install expo-camera\n```\n\nThis is the same library already used dynamically in `CameraScanner.tsx`. Installing it makes the real camera available.\n\n### 2. Create a Turso database\n\n```bash\n# Install Turso CLI\ncurl -sSfL https://get.turso.tech/install.sh | bash\n\n# Login\nturso auth login\n\n# Create a database for PantryRun products\nturso db create pantryrun-products\n\n# Get the database URL + token\nturso db show pantryrun-products --url # → https://pantryrun-products-<org>.turso.io\nturso db tokens create pantryrun-products # → <token>\n\n# Initialize the schema\nturso db shell pantryrun-products < src/services/init-schema.sql\n```\n\n### 3. Create `init-schema.sql`\n\nRun this against your Turso DB to create the tables:\n\n```sql\nCREATE TABLE IF NOT EXISTS products (\n barcode TEXT PRIMARY KEY,\n product_name TEXT NOT NULL,\n brand TEXT,\n category TEXT,\n image_url TEXT,\n quantity_label TEXT,\n source TEXT NOT NULL DEFAULT 'user',\n raw_input TEXT,\n ai_cleaned INTEGER DEFAULT 0,\n first_seen_at TEXT NOT NULL DEFAULT (datetime('now')),\n updated_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\n\nCREATE TABLE IF NOT EXISTS product_prices (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n barcode TEXT NOT NULL REFERENCES products(barcode),\n price REAL NOT NULL,\n store_name TEXT NOT NULL,\n store_id TEXT NOT NULL,\n quantity REAL,\n unit TEXT,\n scanned_at TEXT NOT NULL DEFAULT (datetime('now')),\n submitted_by TEXT\n);\n\nCREATE INDEX IF NOT EXISTS idx_prices_barcode ON product_prices(barcode);\nCREATE INDEX IF NOT EXISTS idx_prices_scanned ON product_prices(scanned_at);\nCREATE INDEX IF NOT EXISTS idx_products_category ON products(category);\n```\n\n### 4. Get a USDA API key (free)\n\nSign up at https://fdc.nal.usda.gov/api-key-signup.html — instant, no wait.\n\nThen add to `.env`:\n```\nEXPO_PUBLIC_USDA_API_KEY=your_key_here\nEXPO_PUBLIC_AI_CLEANUP_URL=https://opencode.ai/zen/go/v1/chat/completions\nEXPO_PUBLIC_AI_CLEANUP_KEY=your_opencode_go_key\n```\n\n### 5. Set Turso credentials in-app\n\nThe SettingsScreen needs Turso URL + token fields (not built yet). For testing, you can hardcode them temporarily or add a TursoConfigSection in SettingsScreen.\n\n---\n\n## Architecture Diagram\n\n```\nUser scans barcode (expo-camera → ML Kit)\n │\n ▼\nBarcodeScannerScreen ── onScan(barcode) ──► AddItemSheet\n │\n ▼\n lookupProduct(barcode)\n │\n ┌──────────┼──────────┐\n ▼ ▼ ▼\n In-memory Turso DB Open Food Facts\n cache (your (free, no key)\n (session products) │\n only) ▼\n USDA\n (free fallback)\n │\n ┌──────────┘\n ▼\n Found? ──Yes──► Pre-fill form\n │\n No\n │\n ▼\n Show \"New Product\"\n form → user types name\n │\n ▼\n submitNewProduct()\n │\n ▼\n AI Cleanup → Turso INSERT\n (heuristic + MiMo)\n```\n\n## Edge Cases Handled\n\n1. **Camera not available** → falls back to manual barcode entry (type digits)\n2. **No network** → cache hit works, otherwise shows error\n3. **Turso not configured** → lookup still works (OFF + USDA), save disabled\n4. **Product not in any DB** → new product form, user enters name\n5. **All-caps names** → AI cleanup normalizes to title case\n6. **Rapid scanning** → `scanned` flag prevents duplicate triggers\n7. **Non-retail barcodes** → regex validates 8-14 digit codes only\n\n## What's Not Built (For Your Next Session)\n\n1. **Turso settings UI** in SettingsScreen (URL + token fields)\n2. **Turso schema auto-migration** on app start (the `migrations` table check)\n3. **AI cleanup server endpoint** (currently configured to hit OpenCode Go API directly — a Cloudflare Worker wrapper would be cleaner)\n4. **Price history view** in ItemEditScreen (data is stored, UI not wired)\n5. **expo-camera install** — you need to `npx expo install expo-camera`\n6. **Turso database creation** — via CLI\n"}}}}