Craig 32461b7405 TICKET-006 (backend): OFF normalization, scan/search/refresh, restore-on-rescan
- services/off.py: single normalizer module (kcal/kJ fallback, not-found
  rule); fetch_product/search_off degrade gracefully on upstream errors
  (503/timeout → None / []), never 500; User-Agent + timeouts on all calls
- routers/off.py: thin routes for GET /api/off/product/{barcode},
  GET /api/off/search, POST /api/off/refresh/{food_id} (404 unknown id,
  400 no-barcode)
- services/foods.py: restore-on-rescan (§3.1) — barcode collision on a
  soft-deleted food clears deleted_at + updates row instead of 409;
  GET /api/foods/recent ordered by most-recent daily_log appearance,
  deduped, soft-deleted excluded
- tests: httpx mocked at the boundary (MockTransport, no real OFF);
  48 new tests (normalizer unit + router + restore + recent + error paths)
- 152 passing (was 104)
2026-07-26 15:46:24 +01:00
2026-07-26 11:16:10 +01:00

CalCount

A personal, self-hosted calorie counter web app with barcode scanning via phone camera and OpenFoodFacts lookup. See SPEC.md for the full spec, data model, API design, and development rules (§8 — read it before writing code).

Stack

  • Backend: Python ≥3.12, FastAPI, SQLAlchemy 2, Pydantic 2, SQLite, httpx — managed with uv
  • Frontend: Svelte 5 (runes) + Vite 7, zxing-wasm barcode fallback — managed with npm (Node ≥22.12)

Project layout

backend/    FastAPI app (main.py), SQLAlchemy models, Pydantic schemas,
            routers/, services/, migrations/, tests/
frontend/   Vite + Svelte SPA (src/), lib/ (api, stores, scanner, format),
            components/

Setup

# Backend (uv creates .venv and installs from uv.lock)
cd backend
uv sync

# Frontend
cd frontend
npm install

Run

Two terminals:

# Terminal 1 — backend on http://localhost:8000
cd backend
uv run uvicorn main:app --reload

# Terminal 2 — frontend on http://localhost:5173 (proxies /api → :8000)
cd frontend
npm run dev

The SQLite database (backend/calcount.db) is created and migrated automatically on backend startup (backend/migrations/).

Test

cd backend && uv run pytest        # backend suite
cd frontend && npm test            # frontend suite (vitest)

Build

cd frontend && npm run build       # production build to frontend/dist/
S
Description
No description provided
Readme 256 KiB
Languages
Python 56.5%
Svelte 25.1%
TypeScript 11.7%
JavaScript 6.3%
Shell 0.3%