""" FastAPI application setup for Paper Dynasty web app. Implements Model/Service Architecture with dependency injection. """ import logging from contextlib import asynccontextmanager from fastapi import FastAPI, Request from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates from app.routers import auth, games, api, pages from app.config.logging_config import setup_logging logger = logging.getLogger(f'{__name__}.main') @asynccontextmanager async def lifespan(app: FastAPI): """Application lifespan manager.""" # Startup setup_logging() logger.info("FastAPI application starting up") yield # Shutdown logger.info("FastAPI application shutting down") def create_app() -> FastAPI: """Create and configure the FastAPI application.""" app = FastAPI( title="Paper Dynasty", description="Baseball simulation web game with Model/Service Architecture", version="2.0.0", lifespan=lifespan ) # Include routers app.include_router(auth.router, prefix="/auth", tags=["authentication"]) app.include_router(games.router, prefix="/games", tags=["games"]) app.include_router(api.router, prefix="/api", tags=["api"]) app.include_router(pages.router, tags=["pages"]) # Static files and templates app.mount("/static", StaticFiles(directory="app/static"), name="static") return app # Create the application instance app = create_app() @app.get("/health") async def health_check(): """Health check endpoint.""" return {"status": "healthy", "service": "paper-dynasty-web"} if __name__ == "__main__": import uvicorn uvicorn.run("app.main:app", host="0.0.0.0", port=8001, reload=True)