Add core router and main application
Implement application factory pattern with clean main.py. Separate routers for each domain, centralized exception handling. Core Router (src/core/router.py): - Root endpoint (/) - Health check endpoint (/health) - Simple status responses - No prefix (mounted at root) Main Application (src/main.py): - create_application() factory function - Clean configuration-focused main.py - CORS middleware setup - Exception handler registration - Router registration with proper prefixes - Global config integration Application Architecture: - Application factory pattern for testability - Routers imported from separate controllers - Exception handlers in dedicated function - All routes cleanly separated by domain Exception Handling: - OpenAI-compatible error format - Custom AppException handler - Validation error handler (422) - Generic exception handler (500) Following Best Practices: - Separation of concerns - Factory pattern for DI - Clean main.py (config only) - Type hints throughout Status: Production-ready structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
Core router for health and root endpoints.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from src.core.config import config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(tags=["core"])
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health_check() -> dict[str, str]:
|
||||
"""
|
||||
Health check endpoint.
|
||||
|
||||
Returns:
|
||||
Health status
|
||||
"""
|
||||
return {"status": "healthy", "version": config.APP_VERSION}
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def root() -> dict[str, str]:
|
||||
"""
|
||||
Root endpoint.
|
||||
|
||||
Returns:
|
||||
API information
|
||||
"""
|
||||
return {
|
||||
"name": config.APP_NAME,
|
||||
"version": config.APP_VERSION,
|
||||
"docs": "/docs",
|
||||
}
|
||||
Reference in New Issue
Block a user