diff --git a/api/app.py b/api/app.py index 70acde4..a5b782b 100644 --- a/api/app.py +++ b/api/app.py @@ -1,6 +1,12 @@ """ FastAPI application assembly. +This module builds the application through `create_app()` rather than +configuring a module-level singleton at import time. + +`app = create_app()` is still exported at module level because +`api.app:app` is the documented uvicorn target, the deployment entry point, +and what `tests/test_api.py` and `tests/test_voice_layer.py` import. This module builds the application through ``create_app()`` rather than configuring a module-level singleton at import time. @@ -12,6 +18,23 @@ python -m uvicorn api.app:app --reload +Starting the server calls no LLM, speech, or vector provider. +Configuration is read from: + +- config/settings.py for provider/domain values +- core/config.py for service values + +Providers are resolved lazily at first use. + +Wiring seams preserved: + +- `app.state.registry` +- `app.state.interviewer_factory` +- `app.state.voice_service_factory` + +These remain pure wiring hooks and are read on every request. +The dependency container (`core/container.py`) reads through to them +rather than shadowing them. Starting the server does not call any LLM, speech, or vector provider. Configuration is read from ``config/settings.py`` and ``core/config.py``, while providers are resolved lazily at first use. @@ -62,6 +85,18 @@ # P9: The voice client is served from the API's own origin. # +# `pages/voice-interview.html` builds its WebSocket URL from +# `location.host`. Opening the page directly as a `file://` URL would +# result in an empty host, preventing the WebSocket connection. +# +# Serving the page from the API also keeps browser fetch/WebSocket +# requests same-origin, so this vertical slice does not require CORS. +# +# CORS is available through `CORS_ALLOW_ORIGINS` in `core/config.py` +# for deployments using a separately hosted frontend. +# +# StaticFiles provides read-only static hosting and confines access +# beneath the mounted directory. # ``pages/voice-interview.html`` builds its WebSocket URL from # ``location.host``. Serving the page from the API keeps browser # fetch/WebSocket requests same-origin. @@ -75,6 +110,15 @@ def create_app(settings: AppSettings | None = None) -> FastAPI: + """ + Build and return a fully wired FastAPI application. + + If `settings` is not supplied, the process-wide cached settings + are used. + + Passing an explicit settings object allows tests to create an + independently configured application without modifying environment + variables for the rest of the test session. """Build and return a fully wired FastAPI application. Args: @@ -85,9 +129,11 @@ def create_app(settings: AppSettings | None = None) -> FastAPI: configured applications without mutating the environment used by other tests. """ + from api.registry import SessionRegistry - settings = settings or get_settings() + if settings is None: + settings = get_settings() app = FastAPI( title=settings.app_name, @@ -103,6 +149,8 @@ def create_app(settings: AppSettings | None = None) -> FastAPI: openapi_url=settings.openapi_url, ) + # ------------------------------------------------------------------ + # Pre-existing wiring seams # ------------------------------------------------------------------ # Application wiring seams # ------------------------------------------------------------------ @@ -116,6 +164,15 @@ def create_app(settings: AppSettings | None = None) -> FastAPI: # Existing interview/voice seams. app.state.interviewer_factory = None app.state.voice_service_factory = None + + # Chunk 2: + # Wiring seams for the job/candidate/matching agents: + # + # - JDAnalyzerAgent + # - ResumeParserAgent + # - ResumeMatcherAgent + # + # None means the agent resolves its own default LLM provider. app.state.gemini_live_token_factory = None # Chunk 2: job/candidate/matching agent seams. @@ -123,6 +180,15 @@ def create_app(settings: AppSettings | None = None) -> FastAPI: app.state.resume_parser_factory = None app.state.resume_matcher_factory = None + # Chunk 4: + # Bundled wiring seam for the seven evaluation agents. + app.state.evaluation_agent_factories = None + + # Chunk 5: + # Wiring seam for LeaderboardAgent used by RecruiterService. + app.state.leaderboard_factory = None + + # Make the application settings available through app.state. # Chunk 4: evaluation-agent seam. app.state.evaluation_agent_factories = None @@ -140,6 +206,29 @@ def create_app(settings: AppSettings | None = None) -> FastAPI: register_exception_handlers(app) # ------------------------------------------------------------------ + # API routes + # ------------------------------------------------------------------ + + app.include_router( + auth_router, + prefix=settings.api_prefix, + ) + + app.include_router( + admin_router, + prefix=settings.api_prefix, + ) + + app.include_router( + interview_router, + prefix=settings.api_prefix, + ) + + app.include_router( + voice_router, + prefix=settings.api_prefix, + ) + # API routers # ------------------------------------------------------------------ @@ -152,6 +241,47 @@ def create_app(settings: AppSettings | None = None) -> FastAPI: interview_mediator_router, prefix=settings.api_prefix, ) + + app.include_router( + scoring_router, + prefix=settings.api_prefix, + ) + + app.include_router( + reports_router, + prefix=settings.api_prefix, + ) + + app.include_router( + jobs_router, + prefix=settings.api_prefix, + ) + + app.include_router( + rubrics_router, + prefix=settings.api_prefix, + ) + + app.include_router( + candidates_router, + prefix=settings.api_prefix, + ) + + app.include_router( + applications_router, + prefix=settings.api_prefix, + ) + + app.include_router( + evaluations_router, + prefix=settings.api_prefix, + ) + + app.include_router( + bugs_router, + prefix=settings.api_prefix, + ) + app.include_router(scoring_router, prefix=settings.api_prefix) app.include_router(reports_router, prefix=settings.api_prefix) app.include_router(jobs_router, prefix=settings.api_prefix) @@ -186,9 +316,37 @@ async def health() -> HealthResponse: {"status": "ok"} """ + Liveness endpoint. + + This endpoint intentionally performs: + + - no LLM call + - no provider call + - no database call + - no API-key validation + + The response remains exactly: + + {"status": "ok"} + + This keeps the endpoint inexpensive enough for continuous + load-balancer health checks. + """ + return HealthResponse(status="ok") # ------------------------------------------------------------------ + # Root endpoint + # ------------------------------------------------------------------ + + @app.api_route( + f"{settings.api_prefix}/", + methods=["GET", "HEAD"], + include_in_schema=False, + ) + async def root( + container: ServiceContainer = Depends(get_container), + ) -> dict: # Root operational summary # ------------------------------------------------------------------ @@ -208,6 +366,15 @@ async def root( Persistence is explicitly reported so an ephemeral deployment does not appear durable when its data is lost on restart. """ + Return a credential-free summary of the running service. + + Provider names may be exposed, but credentials, connection + strings, and filesystem paths must never be returned. + + Persistence information is included so deployments using + temporary in-memory repositories are clearly identified. + """ + return { "service": "openhire-live-interview-api", **container.settings.public_summary(), @@ -219,6 +386,7 @@ async def root( } # ------------------------------------------------------------------ + # Static pages # Optional static frontend # ------------------------------------------------------------------ @@ -235,6 +403,15 @@ async def root( return app +# ---------------------------------------------------------------------- +# Uvicorn / deployment / test entry point +# ---------------------------------------------------------------------- + +# Keep this module-level application object because: +# +# uvicorn api.app:app --reload +# +# and existing tests depend on it. # Uvicorn/deployment/test entry point. # # Usage: