from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from database import engine, Base from middleware.license_check import LicenseCheckMiddleware from services.cloud_sync import start_cloud_sync # Import all models so SQLAlchemy can create their tables import models.user # noqa: F401 import models.table # noqa: F401 import models.printer # noqa: F401 import models.product # noqa: F401 import models.order # noqa: F401 from routers import auth, tables, products, orders, waiters, reports, system @asynccontextmanager async def lifespan(app: FastAPI): Base.metadata.create_all(bind=engine) sync_task = await start_cloud_sync() yield sync_task.cancel() app = FastAPI(title="POS Local Backend", lifespan=lifespan) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"], ) app.add_middleware(LicenseCheckMiddleware) app.include_router(auth.router, prefix="/api/auth", tags=["auth"]) app.include_router(tables.router, prefix="/api/tables", tags=["tables"]) app.include_router(products.router, prefix="/api/products", tags=["products"]) app.include_router(orders.router, prefix="/api/orders", tags=["orders"]) app.include_router(waiters.router, prefix="/api/waiters", tags=["waiters"]) app.include_router(reports.router, prefix="/api/reports", tags=["reports"]) app.include_router(system.router, prefix="/api/system", tags=["system"])