Skip to content

Getting Started

  • Node.js 18+
  • Wrangler CLI v4+
  • Cloudflare account (paid plan, $5/month)
  • Bun (for seed generation)
Terminal window
# Install dependencies
npm 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 locally
npm run db:migrate
# Equivalent to: wrangler d1 migrations apply lattice-db --local
# Run migrations on remote D1
npm run db:migrate:prod
# Equivalent to: wrangler d1 migrations apply lattice-db --remote
Terminal window
# Generate seed SQL
npm run seed > seed.sql
# Equivalent to: bun src/seed/generate.ts > seed.sql
# Apply seed data locally
wrangler d1 execute lattice-db --local --file=seed.sql
# Apply seed data to remote
wrangler d1 execute lattice-db --remote --file=seed.sql
Terminal window
# Deploy to Cloudflare Workers
npm run deploy
# Equivalent to: wrangler deploy

The worker is named lattice-gateway and the entry point is src/workers/gateway.ts.

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"