Hi everyone,
I’d like to share the backend layer of my SendaFun side‑project: apis.sendafun.com, a dedicated serverless API gateway powering the whole multi‑subdomain creative tool ecosystem.
All services run on Cloudflare Workers stack, no traditional VMs or containers. The primary design goal is keeping heavy image‑processing logic inside user browsers whenever possible, while the API layer takes care of authentication, paywall validation, payment webhooks, rate‑limiting and cross‑subdomain isolation.
Why a standalone API subdomain?
Originally, I considered embedding backend logic inside each sub‑domain. Very quickly I hit several hard problems:
- Avoid cross‑site permission leakage between independent sub‑sites (
shop.sendafun.com,pattern.sendafun.com,smartimgkit.comand others). - Centralize paywall & subscription validation, so every frontend tool respects the same business rules.
- Unify webhook handling for multiple payment providers.
- Central rate‑limit, logging, CORS and security headers in one single place.
Splitting out apis.sendafun.com gives me clean separation: front‑end sites are static, all sensitive business logic lives on the dedicated API host.
Core responsibilities of apis.sendafun.com
- Subscription & paywall validation: Verify monthly / yearly membership status. Enforce business boundaries: subscription only unlocks self‑generated templates, cannot access pre‑made shop marketplace assets. Non‑member restrictions (watermark output, PDF export locked).
- Payment webhook receiver: Handle payment events from multiple payment gateways, update user entitlements without sharing user sessions across sub‑domains.
- Rate limiting & abuse prevention: Prevent users from bypassing paywalls or over‑consuming backend resources.
- Storage glue layer: Connect frontend tools to Cloudflare R2 storage, without exposing R2 credentials to browser clients.
- Cross‑subdomain secure communication: Strict CORS configuration, only allow trusted sendafun‑family origins. Block unknown external origins.
Important architecture trade‑offs
- Privacy‑first principle: User‑uploaded photos for pattern generation stay inside browser. The API does NOT receive user source images. It only receives small‑size computed parameters, thumbnails and metadata.
- Strict sub‑domain isolation: Even though they share one API backend, each sub‑site remains independent. No shared browser session / cookie across sites.
- Not a public open‑API: This gateway is built exclusively for SendaFun ecosystem front‑ends. Third‑party public API access is not supported for now.
- Some related sub‑services are still under active development: shop marketplace endpoints, pattern generator backend helpers are being built out.
Tech stack
- Cloudflare Workers as serverless runtime
- Cloudflare R2 for object storage
- Workers KV for lightweight user‑state and entitlement storage
- Strict CORS / COOP / COEP security headers
- Multiple payment‑provider webhook handling
This backend is tightly coupled with the multi‑subdomain tool ecosystem I wrote about in my previous post. The whole project is iterating step‑by‑step.
👉 Visit API gateway: https://apis.sendafun.com
I would appreciate any feedback or architecture suggestions.
Top comments (0)