Backend-for-frontend @sushrutalgs.ai
Built a Cloudflare Worker gateway that sits between the sushrutalgs.ai web and iOS apps and the AI backend, handling user authentication, per-user daily usage limits, and secure request forwarding so both apps talk to one trusted entry point. It runs live in staging and production and adds only about 14 milliseconds of overhead at the edge.
Source is private; sushrutalgs.ai is a live product. Happy to walk through the code or grant read access on request.
Stack
System architecture. Tap to enlarge.
Overview
The BFF is the single trusted entry point for sushrutalgs.ai. Both the web and iOS apps call it instead of holding backend secrets or duplicating auth and billing logic. It verifies who the user is, enforces their daily usage limit, and forwards the request to the AI backend.
Approach
Results
Live in staging and production at about 14 ms of edge overhead, a roughly 33 KB gzipped bundle, and JWT verification at p95 around 0.13 ms. Quota enforcement measured about 9,200 operations per second on a single hot row, with verified fail-closed mapping and zero errors through 200 concurrent requests.
Engineering
TypeScript and Hono on Cloudflare Workers, with the jose library for JWT and JWKS verification, Supabase for auth and the quota function, and Cloudflare Access service tokens for upstream auth. Staging auto-deploys on push; production is gated by a release, so the iOS app's uptime is decoupled from web deploys.