from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.core.config import settings from app.api.routes import api_router from app.db.session import engine app = FastAPI( title=settings.PROJECT_NAME, description="Inventory Management System API for Small Businesses", version="0.1.0", openapi_url="/openapi.json", docs_url="/docs", redoc_url="/redoc", ) # Set up CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include API router app.include_router(api_router) # Health check endpoint @app.get("/health", tags=["Health"]) async def health_check(): # Try to connect to the database try: # Create a new connection and check if it works with engine.connect() as connection: result = connection.execute("SELECT 1").fetchone() db_status = "healthy" if result[0] == 1 else "unhealthy" except Exception: db_status = "unhealthy" return { "status": "healthy", "database": db_status, "api_version": "0.1.0", "environment": "development" } if __name__ == "__main__": import uvicorn uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)