feat: update project structure and docs
This commit is contained in:
28
app/main.py
28
app/main.py
@@ -1,21 +1,43 @@
|
||||
"""FastAPI application factory and entry point."""
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
|
||||
from app.common.error_handler import register_exception_handlers
|
||||
from app.core.config import settings
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Application lifespan manager for startup/shutdown events."""
|
||||
# Startup: initialize DB connections, cache, etc.
|
||||
yield
|
||||
# Shutdown: cleanup resources
|
||||
|
||||
|
||||
def app_factory():
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
def app_factory() -> FastAPI:
|
||||
"""Create and configure FastAPI application instance.
|
||||
|
||||
Returns:
|
||||
Configured FastAPI application.
|
||||
"""
|
||||
app = FastAPI(title=settings.app_name, debug=settings.debug, lifespan=lifespan)
|
||||
|
||||
# Register exception handlers
|
||||
register_exception_handlers(app)
|
||||
|
||||
# Register routers (when added)
|
||||
# from app.api.v1.router import api_router
|
||||
# app.include_router(api_router, prefix="/api/v1")
|
||||
|
||||
return app
|
||||
|
||||
|
||||
def main():
|
||||
uvicorn.run(app_factory, factory=True, host="0.0.0.0", port=8000)
|
||||
"""Run the application with uvicorn server."""
|
||||
uvicorn.run(app_factory, factory=True, host=settings.host, port=settings.port)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user