from fastapi import FastAPI, Depends from fastapi.middleware.cors import CORSMiddleware import uvicorn from pathlib import Path from sqlalchemy.orm import Session from app.db.session import get_db, engine from app.db.base import Base from app.db.init_db import init_db # Import routers from app.api.routes import product_router, inventory_router, supplier_router # Create database tables Base.metadata.create_all(bind=engine) # Create FastAPI app app = FastAPI( title="Small Business Inventory Management System", description="API for managing inventory for small businesses", version="0.1.0" ) # Configure CORS app.add_middleware( CORSMiddleware, allow_origins=["*"], # Update with specific origins in production allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include routers app.include_router(product_router) app.include_router(inventory_router) app.include_router(supplier_router) @app.get("/") async def root(): return {"message": "Welcome to the Small Business Inventory Management System API"} @app.get("/health") async def health(): return {"status": "healthy"} @app.on_event("startup") async def startup_event(): db = next(get_db()) init_db(db) if __name__ == "__main__": uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)