Recipe corpus (#108): - Add _MAIN_INGREDIENT_SIGNALS to tag_inferrer.py (Chicken/Beef/Pork/Fish/Pasta/ Vegetables/Eggs/Legumes/Grains/Cheese) — infers main:* tags from ingredient names - Update browser_domains.py main_ingredient categories to use main:* tag queries instead of raw food terms; recipe_browser_fts now has full 3.19M row coverage (was ~1.2K before backfill) Bug fixes: - Fix community posts response shape (#96): add total/page/page_size fields - Fix export endpoint arg types (#92) - Fix household invite store leak (#93) - Fix receipts endpoint issues - Fix saved_recipes endpoint - Add session endpoint (app/api/endpoints/session.py) Shopping list: - Add migration 033_shopping_list.sql - Add shopping schemas (app/models/schemas/shopping.py) - Add ShoppingView.vue, ShoppingItemRow.vue, shopping.ts store Frontend: - InventoryList, RecipesView, RecipeDetailPanel polish - App.vue routing updates for shopping view Docs: - Add user-facing docs under docs/ (getting-started, user-guide, reference) - Add screenshots
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
#!/usr/bin/env python
|
|
# app/main.py
|
|
|
|
import logging
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.routes import api_router
|
|
from app.core.config import settings
|
|
from app.services.meal_plan.affiliates import register_kiwi_programs
|
|
|
|
# Structured key=value log lines — grep/awk-friendly for log-based analytics.
|
|
# Without basicConfig, app-level INFO logs are silently dropped.
|
|
logging.basicConfig(level=logging.INFO, format="%(levelname)s:%(name)s: %(message)s")
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
logger.info("Starting Kiwi API...")
|
|
settings.ensure_dirs()
|
|
register_kiwi_programs()
|
|
|
|
# Start LLM background task scheduler
|
|
from app.tasks.scheduler import get_scheduler
|
|
get_scheduler(settings.DB_PATH)
|
|
logger.info("Task scheduler started.")
|
|
|
|
# Initialize community store (no-op if COMMUNITY_DB_URL is not set)
|
|
from app.api.endpoints.community import init_community_store
|
|
init_community_store(settings.COMMUNITY_DB_URL)
|
|
|
|
yield
|
|
|
|
# Graceful scheduler shutdown
|
|
from app.tasks.scheduler import get_scheduler, reset_scheduler
|
|
get_scheduler(settings.DB_PATH).shutdown(timeout=10.0)
|
|
reset_scheduler()
|
|
logger.info("Kiwi API shutting down.")
|
|
|
|
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
description="Pantry tracking + leftover recipe suggestions",
|
|
version="0.2.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.CORS_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(api_router, prefix=settings.API_PREFIX)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"service": "kiwi-api", "docs": "/docs"}
|