from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from pathlib import Path from app.db.session import engine from app.db.base import Base from app.routers import products, categories, suppliers, stock_movements, reports Base.metadata.create_all(bind=engine) app = FastAPI( title="Small Business Inventory System", description="A comprehensive inventory management system for small businesses", version="1.0.0", openapi_url="/openapi.json", ) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(products.router, prefix="/api/v1") app.include_router(categories.router, prefix="/api/v1") app.include_router(suppliers.router, prefix="/api/v1") app.include_router(stock_movements.router, prefix="/api/v1") app.include_router(reports.router, prefix="/api/v1") @app.get("/") def root(): return { "title": "Small Business Inventory System", "description": "A comprehensive inventory management system for small businesses", "version": "1.0.0", "documentation": "/docs", "health_check": "/health", } @app.get("/health") def health_check(): try: db_dir = Path("/app/storage/db") db_file = db_dir / "db.sqlite" return { "status": "healthy", "database": { "status": "connected", "path": str(db_file), "exists": db_file.exists(), }, "storage": {"directory": str(db_dir), "exists": db_dir.exists()}, } except Exception as e: return {"status": "unhealthy", "error": str(e)} if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)