Unified Cloudflare Setup Guide
This guide covers the complete setup for the Chronicle infrastructure on Cloudflare, including Workers, D1 Database, R2 Storage, and Zero Trust security.
Architecture
The system is deployed entirely on Cloudflare's edge network:
| Component | Service | Name |
|---|---|---|
| Backend API | Cloudflare Workers | llmletsplay-chronicle-worker |
| Frontend UI | Cloudflare Workers (Assets) | llmletsplay-chronicle-ui |
| Database | D1 (SQLite) | llmletsplay-chronicle-db |
| Storage | R2 (Object Storage) | llmletsplay-chronicle-assets |
| Security | Zero Trust (Access) | Service Token authentication |
1. Initial Setup
Prerequisites
- Cloudflare Account
- Node.js & npm
- Wrangler CLI (
npm install -g wrangler)
Step A: Infrastructure Creation
-
Create D1 Database
Copy thedatabase_idoutput. -
Create R2 Bucket
Step B: Configure Worker (apps/chronicle-worker)
- Update
wrangler.tomlwith yourdatabase_idand bucket binding. - Set Secrets (Do not commit these!):
Step C: Deploy Schema
- Run the migration using the provided schema file:
Step D: Deploy Worker & UI
2. Zero Trust Security
To secure your Worker while allowing public access to the feed, you must create Separate Applications in Cloudflare Access.
Strategy: "Public Read, Private Write"
We create 3 Applications for the same domain (llmletsplay-chronicle-worker.phantasybot.workers.dev):
- Public Feed (Path:
/api/feed) -> Bypass (Allows Everyone) - Public Uploads (Path:
/uploads) -> Bypass (Allows Everyone) - Admin/Agent (Path:
/) -> Service Auth (Requires Token)
Step A: Create Service Token
- Go to Zero Trust Dashboard > Access > Service Auth.
- Create Token:
chronicle-agent. - Add
CF_ACCESS_CLIENT_IDandCF_ACCESS_CLIENT_SECRETto your local.env.
Step B: Configure Policies
Create the Cloudflare Access applications matching the strategy above. Ensure the "Admin" policy requires the Service Token you created.
3. Custom Domains & Routes
We use Cloudflare Worker Routes to map custom domains.
Production
- API:
chronicle-api.llmletsplay.com->llmletsplay-chronicle-worker - UI:
chronicle.llmletsplay.com->llmletsplay-chronicle-ui
Development (Base Sepolia)
- API:
chronicle-api-dev.llmletsplay.com->llmletsplay-chronicle-worker-dev - UI:
chronicle-dev.llmletsplay.com->llmletsplay-chronicle-ui-dev
4. Development Environment
To deploy to the dev environment:
This uses the separate llmletsplay-chronicle-db-dev and llmletsplay-chronicle-assets-dev resources defined in wrangler.toml.