""" FastAPI application entry point. Provides RESTful API for the annotation platform. """ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager from database import init_database from routers import project, task, annotation @asynccontextmanager async def lifespan(app: FastAPI): """ Application lifespan manager. Initializes database on startup. """ # Startup: Initialize database init_database() yield # Shutdown: cleanup if needed # Create FastAPI application instance app = FastAPI( title="Annotation Platform API", description="RESTful API for data annotation management", version="1.0.0", lifespan=lifespan ) # Configure CORS middleware app.add_middleware( CORSMiddleware, allow_origins=[ "http://localhost:4200", # Frontend dev server "http://localhost:3000", # Alternative frontend port ], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include routers app.include_router(project.router) app.include_router(task.router) app.include_router(annotation.router) @app.get("/") async def root(): """Root endpoint - health check""" return { "message": "Annotation Platform API", "status": "running", "version": "1.0.0" } @app.get("/health") async def health_check(): """Health check endpoint""" return {"status": "healthy"} if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)