Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 178 additions & 1 deletion api/app.py
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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,
Expand All @@ -103,6 +149,8 @@ def create_app(settings: AppSettings | None = None) -> FastAPI:
openapi_url=settings.openapi_url,
)

# ------------------------------------------------------------------
# Pre-existing wiring seams
# ------------------------------------------------------------------
# Application wiring seams
# ------------------------------------------------------------------
Expand All @@ -116,13 +164,31 @@ 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.
app.state.jd_analyzer_factory = None
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

Expand All @@ -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
# ------------------------------------------------------------------

Expand All @@ -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)
Expand Down Expand Up @@ -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
# ------------------------------------------------------------------

Expand All @@ -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(),
Expand All @@ -219,6 +386,7 @@ async def root(
}

# ------------------------------------------------------------------
# Static pages
# Optional static frontend
# ------------------------------------------------------------------

Expand All @@ -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:
Expand Down