chain-rdeveloper portal
build

Backend-for-Frontend Service (svc-bff)

Overview

svc-bff is a FastAPI transparent proxy that sits between nginx and svc-core. It validates the user session, retrieves the Auth0 access token from Redis, and forwards it in the Authorization header on every downstream call. It also mints a short-lived, audience-bound internal JWT (X-Internal-Token) so svc-core can verify the caller rather than trusting raw identity headers. It does not aggregate or transform data.

Internal port: 4000 (not exposed to host)

Responsibilities

  • Validate the signed session cookie on every request

  • Retrieve the access token for the session from Redis

  • Forward requests to svc-core with the Authorization: Bearer <token> header injected

  • Mint a short-lived, audience-bound internal JWT (X-Internal-Token, aud=svc-core) per request for svc-core to verify

  • Propagate user identity headers (X-User-Id, X-User-Email, X-User-Name) to downstream services

  • Proxy WebSocket connections for real-time (SSE/streaming) endpoints

  • Handle multipart file uploads (reconstructs Content-Type boundary)

API Endpoints

See spec/api/svc-bff.md for the full auto-generated reference.

MethodPathDescription
GET/POST/PUT/DELETE/PATCH/HEAD/OPTIONS/proxy/{path}Transparent proxy to svc-core
WebSocket/ws/{path}WebSocket proxy to svc-core
GET/debug/sessionSession debug info (dev mode only)

nginx maps /api/* → svc-bff /proxy/* and /api/ws/* → svc-bff /ws/*.

Request Flow

nginx (auth verified)
  ↓  Cookie: sid=<signed_session_id>
svc-bff /proxy/{path}
  ↓  decode cookie → session_id
  ↓  Redis GET session:{session_id} → access_token
  ↓  mint short-lived internal JWT (aud=svc-core, sub=user_id)
  ↓  forward request to svc-core with:
       Authorization: Bearer <access_token>
       X-Internal-Token: <signed internal JWT>   # verified by svc-core
       X-User-Id: <user_id>
       X-User-Email: <email>
       X-User-Name: <name>
svc-core

If the session cookie is missing, invalid, or the token cannot be found in Redis, svc-bff returns 401.

Configuration

VariableDescriptionDefault
REDIS_URLRedis connection URLredis://redis:6379
REDIS_PASSWORDRedis passwordoptional
SESSION_COOKIE_NAMECookie name (must match svc-auth)sid
SESSION_SECRETCookie signing secret (must match svc-auth)required
PROXY_TIMEOUTDownstream request timeout in seconds60
ENVIRONMENTdevelopment / productiondevelopment
INTERNAL_JWT_SECRETShared secret for minting internal service JWTs (required outside local/dev; ≥32 chars)—
INTERNAL_JWT_ISSUERiss claim for minted tokenssvc-bff
INTERNAL_JWT_AUDIENCEaud claim for minted tokens (svc-core verifies)svc-core
INTERNAL_JWT_TTLToken lifetime in seconds120

Runtime Dependencies

  • Redis — reads access tokens stored by svc-auth (bff-network)

  • svc-core — proxies all API traffic (backend-network)

No dedicated PostgreSQL database.

Networks

  • bff-network — Redis access

  • backend-network — svc-core access