Architecture & Cost Overview
Container disks on Cloudflare Containers are ephemeral when an instance sleeps. Never keep SQLite or uploaded files on container-local disk in production — always use
DATABASE_URL (PostgreSQL) and R2 FUSE mounting (/app/uploads).First-Time Setup
1
Provision Supabase PostgreSQL (Singapore)
- Create a Supabase project in
ap-southeast-1and set an alphanumeric database password (avoid@,#,%,&so URI parsing stays clean). - Create the 11 application tables +
alembic_version(stamped to the current Alembichead) and enable Row Level Security (RLS) on every table inpublic. - Revoke Data API access from
anonandauthenticatedroles since only the Flask backend connects via Postgres: - Copy the Session pooler URI (port
5432, IPv4-compatible) from Connect → Session pooler.
2
Enable Cloudflare R2 & Create S3 API Token
- Enable R2 Object Storage in the Cloudflare Dashboard and create a bucket (e.g.
banana-slides-storageinAPAC). - Go to R2 → Manage API Tokens → Create Account API token, grant Object Read & Write scoped to that bucket, and save the Access Key ID and Secret Access Key.
3
Enable Workers Paid & Google OAuth
- Upgrade Cloudflare Workers to Workers Paid ($5/month) to unlock Cloudflare Containers and Durable Objects.
- In Google Cloud Console, add your Cloudflare Pages URL (and any custom domain) under Authorized JavaScript origins for your OAuth 2.0 Client ID.
4
Deploy the Backend Container
Ensure Docker Desktop is running locally, then deploy from Upload runtime secrets to the Worker (pass the variable name in the command, and paste the value at the prompt):
cloudflare-backend/:cloudflare-backend/package.json pins wrangler@4.85.0 so it works on Node.js 20.18+. If your machine runs Node.js 22.12+, you may use newer Wrangler 4 releases.5
Connect Cloudflare Pages (Frontend)
- Create a Cloudflare Pages project linked to your GitHub repository:
- Production branch:
main - Root directory:
frontend - Build command:
npm run build:web - Build output directory:
dist
- Production branch:
- Under Settings → Variables and secrets (both Production and Preview), set
BACKEND_ORIGINto your Worker URL (https://banana-slides-backend.<subdomain>.workers.dev). - Verify GitHub App repository permissions so pushes to
maintrigger automatic builds.
Day-2 Updates & Redeployment
Use the automated helper script from the repository root whenever you update backend Python code or container configuration:- Docker Desktop is running.
cloudflare-backend/entrypoint.shuses Unix LF line endings (required for Linux containers).npm --prefix cloudflare-backend run typecheckpasses with 0 errors.npx wrangler deploypushes any container/Worker changes.- Public endpoints (
/,/health,/api/auth/config,/api/output-language,/llms.txt,/robots.txt) returnHTTP 200, andPOST /api/auth/dev-loginreturns403.
Adding a Custom Domain & AI Search Checklist
Adding a Custom Domain & AI Search Checklist
- Add your domain under Cloudflare Pages → Custom domains.
- Add
https://yourdomain.comto Google Cloud Console Authorized JavaScript origins. - Update the
CORS_ORIGINSWorker secret (npx wrangler secret put CORS_ORIGINS) to includehttps://yourdomain.com. - Replace
yourdomain.cominfrontend/public/sitemap.xmland push tomain. - In Cloudflare Dashboard Security → Bots, ensure search & AI crawlers (
Googlebot,OAI-SearchBot,GPTBot,PerplexityBot,ClaudeBot) are not blocked.
Detailed Reference
For full architecture notes, Alembic PostgreSQL migration guidelines, and troubleshooting (error 1101 cold-start tuning, CRLF guard, IPv4 pooler, DEV_LOGIN_DISABLED), see docs/deploy-cloudflare-supabase.md.