from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.api.v1.api import api_router from app.config import settings from app.core.ai_config import configure_dspy from app.db import init_db from app.models import push_subscription # noqa: F401 — ensures table is created from app.scheduler import start_scheduler, stop_scheduler @asynccontextmanager async def lifespan(app: FastAPI): init_db() configure_dspy() start_scheduler() yield stop_scheduler() app = FastAPI(title="Healthy Fit API", lifespan=lifespan) app.add_middleware( CORSMiddleware, allow_origins=[o.strip() for o in settings.CORS_ORIGINS.split(",")], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(api_router, prefix="/api/v1") @app.get("/") def read_root(): return {"message": "Welcome to Healthy Fit API", "version": "1.0.0"}