"""gcp_solution_architecture_agent: Starlette application wiring & CLI entrypoint.""" from contextlib import asynccontextmanager import logging import click import uvicorn from starlette.applications import Starlette from starlette.routing import Route from app.config import get_settings from app.database import get_db_manager from app.workflows.routes import ( get_card, get_session_route, health_check, run_workflow, validate_artifacts_route, ) settings = get_settings() logging.basicConfig( level=getattr(logging, settings.LOG_LEVEL.upper(), logging.INFO), format="%(asctime)s %(name)s %(levelname)s %(message)s", ) logger = logging.getLogger(__name__) routes = [ Route("/health", health_check, methods=["GET"]), Route("/card", get_card, methods=["GET"]), Route("/generate", run_workflow, methods=["POST"]), Route("/validate", validate_artifacts_route, methods=["POST"]), Route("/sessions/{session_id}", get_session_route, methods=["GET"]), ] @asynccontextmanager async def lifespan(app: Starlette): """Initialize PostgreSQL database schema on server startup.""" logger.info("Initializing PostgreSQL database persistence...") get_db_manager() yield app = Starlette( debug=True, routes=routes, lifespan=lifespan, ) @click.command() @click.option("--host", default=settings.HOST, help="Host address to bind") @click.option("--port", default=settings.PORT, type=int, help="Port to listen on") def main(host: str, port: int) -> None: """Start the GCP Solution Architecture Agent Starlette REST server.""" logger.info("Starting GCP Solution Architecture Agent on %s:%d", host, port) uvicorn.run(app, host=host, port=port, log_level=settings.LOG_LEVEL.lower()) if __name__ == "__main__": main()