Getting Started
Prerequisites
Section titled “Prerequisites”- Node.js 18+
- Wrangler CLI v4+
- Cloudflare account (paid plan, $5/month)
- Bun (for seed generation)
Initial Setup
Section titled “Initial Setup”# Install dependenciesnpm install
# Create the D1 database (if not already created)wrangler d1 create lattice-db
# Update wrangler.toml with the database_id from the output above
# Run migrations locallynpm run db:migrate# Equivalent to: wrangler d1 migrations apply lattice-db --local
# Run migrations on remote D1npm run db:migrate:prod# Equivalent to: wrangler d1 migrations apply lattice-db --remoteSeeding the Database
Section titled “Seeding the Database”# Generate seed SQLnpm run seed > seed.sql# Equivalent to: bun src/seed/generate.ts > seed.sql
# Apply seed data locallywrangler d1 execute lattice-db --local --file=seed.sql
# Apply seed data to remotewrangler d1 execute lattice-db --remote --file=seed.sqlDeploy
Section titled “Deploy”# Deploy to Cloudflare Workersnpm run deploy# Equivalent to: wrangler deployThe worker is named lattice-gateway and the entry point is src/workers/gateway.ts.
Wrangler Configuration
Section titled “Wrangler Configuration”Key settings from wrangler.toml:
name = "lattice-gateway"main = "src/workers/gateway.ts"compatibility_date = "2025-01-01"compatibility_flags = ["nodejs_compat"]
# D1 binding[[d1_databases]]binding = "DB"database_name = "lattice-db"migrations_dir = "src/db/migrations"
# KV binding (read cache)[[kv_namespaces]]binding = "CACHE"
# HTML text imports (for Explorer UI)[[rules]]type = "Text"globs = ["**/*.html"]
[vars]ENVIRONMENT = "development"