Initial project scaffold: FastAPI backend + Svelte 5 frontend

Backend (uv): FastAPI app with routers (foods, log, targets, OFF proxy),
SQLAlchemy models, Pydantic schemas, migration runner + 0001 initial schema,
example pytest suite (7 tests).
Frontend (npm): Vite 7 + Svelte 5 runes, lib/ (api, stores, scanner, format)
per spec §7, placeholder components, example vitest suite (4 tests).
SPEC.md §1: registered uvicorn and Vitest (rule §8.3.3).
This commit is contained in:
Craig
2026-07-26 10:25:59 +01:00
commit e047d884b6
47 changed files with 3994 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
"""Foods router (spec §3.1). Thin: validate → service → schema (spec §8.1 rule 2)."""
from fastapi import APIRouter, Depends, Query
from sqlalchemy import select
from sqlalchemy.orm import Session
from database import get_db
from models import Food
from schemas import FoodRead
router = APIRouter(prefix="/api/foods", tags=["foods"])
@router.get("", response_model=list[FoodRead])
def list_foods(
q: str | None = None,
limit: int = Query(default=50, le=200),
offset: int = 0,
db: Session = Depends(get_db),
):
"""Search local foods. Soft-deleted foods are hidden (spec §8.1 rule 7)."""
stmt = select(Food).where(Food.deleted_at.is_(None)).limit(limit).offset(offset)
if q:
stmt = stmt.where(Food.name.contains(q) | Food.brand.contains(q))
return db.scalars(stmt).all()