from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse from app.core.config import settings from app.core.middleware import RateLimitMiddleware, SecurityHeadersMiddleware, LoggingMiddleware from app.api import auth, wallets, transactions from app.db.session import engine from app.db.base import Base import uvicorn # Create database tables Base.metadata.create_all(bind=engine) app = FastAPI( title=settings.app_name, version=settings.app_version, description="A comprehensive cryptocurrency exchange platform with wallet management, trading, and secure transaction handling.", openapi_url="/openapi.json" ) # Security middleware app.add_middleware(SecurityHeadersMiddleware) app.add_middleware(RateLimitMiddleware, calls=100, period=60) app.add_middleware(LoggingMiddleware) # CORS middleware app.add_middleware( CORSMiddleware, allow_origins=settings.allowed_origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include routers app.include_router(auth.router) app.include_router(wallets.router) app.include_router(transactions.router) @app.get("/") def root(): return { "title": settings.app_name, "version": settings.app_version, "description": "Cryptocurrency Exchange Platform API", "documentation": "/docs", "health_check": "/health" } @app.get("/health") def health_check(): return { "status": "healthy", "service": settings.app_name, "version": settings.app_version, "environment": "development" if settings.debug else "production" } @app.exception_handler(Exception) async def global_exception_handler(request, exc): return JSONResponse( status_code=500, content={"detail": "Internal server error"} ) if __name__ == "__main__": uvicorn.run( "main:app", host="0.0.0.0", port=8000, reload=settings.debug )