paper-dynasty-gameplay-webapp/app/main.py
Cal Corum c09f9d1302 CLAUDE: Initialize Paper Dynasty web app with Model/Service Architecture
Establishes foundation for migrating baseball simulation from Discord bot to web application using service-oriented architecture pattern.

Key components:
- FastAPI application structure with dependency injection
- Service layer foundation with base classes and container
- Comprehensive directory documentation with README files
- PostgreSQL containerization with Docker Compose
- Testing structure for unit/integration/e2e tests
- Migration planning documentation
- Rotating log configuration per user requirements

Architecture follows Model/Service/Controller pattern to improve testability, maintainability, and scalability over original monolithic Discord app.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-27 21:44:12 -05:00

65 lines
1.7 KiB
Python

"""
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)