| from fastapi import FastAPI | |
| from api.status import router as status_router | |
| from api.chat import router as chat_router | |
| from core.memory import check_redis_health | |
| import logging | |
| app = FastAPI() | |
| logger = logging.getLogger(__name__) | |
| # Mount routers | |
| app.include_router(status_router, prefix="/api") | |
| app.include_router(chat_router, prefix="/api") | |
| async def root(): | |
| logger.info("API root endpoint accessed") | |
| return {"message": "AI Life Coach API is running"} | |
| async def health_check(): | |
| """Comprehensive health check endpoint""" | |
| redis_healthy = check_redis_health() | |
| # Additional health checks could be added here | |
| overall_healthy = redis_healthy | |
| health_status = { | |
| "status": "healthy" if overall_healthy else "degraded", | |
| "services": { | |
| "redis": "healthy" if redis_healthy else "unhealthy" | |
| }, | |
| "timestamp": __import__('time').time() | |
| } | |
| if overall_healthy: | |
| logger.info("Health check passed") | |
| else: | |
| logger.warning("Health check degraded") | |
| return health_status | |
| # Add startup event for initialization logging | |
| async def startup_event(): | |
| logger.info("AI Life Coach API starting up...") | |
| logger.info("Redis health: %s", "healthy" if check_redis_health() else "unhealthy") | |