creativesar/taskflow
0
1"""2Todo Backend API - Phase II3FastAPI application with JWT authentication and task management4"""5 6from dotenv import load_dotenv7load_dotenv()8 9from fastapi import FastAPI, Request10from fastapi.middleware.cors import CORSMiddleware11from fastapi.responses import JSONResponse12import os13import logging14import traceback15 16from routes.tasks import router as tasks_router17from routes.auth import router as auth_router18from routes.chat import router as chat_router19 20# Configure logging21logging.basicConfig(level=logging.INFO)22logger = logging.getLogger(__name__)23 24app = FastAPI(25 title="Todo API",26 version="1.0.0",27 description="Full-Stack Todo Application Backend - Phase II Hackathon"28)29 30# CORS configuration31origins = os.getenv("CORS_ORIGINS", "http://localhost:3000").split(",")32 33app.add_middleware(34 CORSMiddleware,35 allow_origins=origins,36 allow_credentials=True,37 allow_methods=["*"],38 allow_headers=["*"],39)40 41 42# Global exception handler for 500 errors43@app.exception_handler(Exception)44async def global_exception_handler(request: Request, exc: Exception):45 """46 Global exception handler to catch unhandled exceptions.47 Returns generic error message to prevent information leakage.48 """49 logger.error(f"Unhandled exception: {exc}")50 logger.error(traceback.format_exc())51 return JSONResponse(52 status_code=500,53 content={"detail": "Internal server error"}54 )55 56 57# Register routers58app.include_router(tasks_router)59app.include_router(auth_router)60app.include_router(chat_router) # Phase III: AI Chatbot61 62 63@app.get("/health")64async def health_check():65 """Health check endpoint for monitoring"""66 return {"status": "healthy", "version": "1.0.0"}67 68 69@app.get("/")70async def root():71 """Root endpoint"""72 return {73 "message": "Todo API - Phase II",74 "docs": "/docs",75 "health": "/health"76 }77 