Skip to Content
SPAPS is proprietary hosted SaaS. Paid access required; pre-1.0 contracts may change. Terms and access
OverviewRequest Lifecycle

Request Lifecycle

Every SPAPS request passes through shared HTTP concerns before it reaches a domain service. The important thing to understand is that application identity and user identity are separate checks: API key validation identifies the calling application, while JWT or local-mode identity identifies the user principal.

Sequence

The Key Dependencies

DependencyFileRole
get_db_sessionmiddleware/spaps_deps.pyYields an async SQLAlchemy session from app.state.db_resources
get_applicationmiddleware/spaps_deps.pyExtracts and validates X-API-Key, sets application state, enforces publishable-key route scope and origin rules
get_current_usermiddleware/spaps_deps.pyAuthenticates JWTs and enforces token application matching
get_optional_usermiddleware/spaps_deps.pyAllows routes to handle anonymous or authenticated callers
require_admin_usermiddleware/spaps_deps.pyRequires an authenticated admin principal

Local Mode Branch

In local mode, missing API keys fall back to a synthetic local application and test personas. Explicit API keys still resolve real applications, which keeps app-scoped entitlements and origin behavior testable in development.

DEVELOPMENT_ENVIRONMENT=local SPAPS_LOCAL_MODE=true curl 'http://localhost:3301/api/some-route?_user=admin'

Local mode is a development convenience. Startup checks refuse unsafe local-mode or production-credential combinations in production-like environments.

Failure Shape

Domain errors are routed through installed error handlers and JSON responses are wrapped by ResponseEnvelopeMiddleware. When debugging a status code, check dependency failures before service logic: missing API key, publishable-key scope, origin mismatch, JWT mismatch, and role checks all happen before the route’s business body matters.

Next