.claude/skills/cloudflare-workers/SKILL.md
Edge deployment patterns and Cloudflare-specific considerations for LivestockAI
npx skillsauth add captjay98/gemini-livestockai Cloudflare WorkersInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
LivestockAI is deployed on Cloudflare Workers for global edge performance. This skill covers Workers-specific patterns and constraints.
process.envCloudflare Workers does NOT support process.env. Environment variables come from:
.dev.vars file# .dev.vars (local)
DATABASE_URL=postgres://...
BETTER_AUTH_SECRET=...
# Production secrets
wrangler secret put DATABASE_URL
wrangler secret put BETTER_AUTH_SECRET
Database and auth modules must use dynamic imports in server functions:
// ✅ Correct - works on Workers
export const fn = createServerFn().handler(async () => {
const { getDb } = await import('~/lib/db')
const db = await getDb()
// ...
})
// ❌ Wrong - fails on Workers
import { db } from '~/lib/db'
Workers have a 128MB memory limit. For large operations:
The wrangler.jsonc file configures the Worker:
{
"name": "livestockai",
"compatibility_date": "2024-01-01",
"compatibility_flags": ["nodejs_compat"],
"main": "./dist/server/index.mjs",
}
# Deploy to production
bun run deploy
# or
wrangler deploy
# Preview deployment
wrangler deploy --env preview
# View logs
wrangler tail
The devops-engineer agent has access to Cloudflare MCP servers:
| Server | Purpose |
| -------------------------- | -------------------------- |
| cloudflare-bindings | Manage Workers, KV, R2, D1 |
| cloudflare-builds | Deployment status and logs |
| cloudflare-observability | Worker logs and debugging |
| cloudflare-docs | Documentation search |
Other agents should delegate Cloudflare tasks to devops-engineer.
Use dynamic imports for database connections:
const { getDb } = await import('~/lib/db')
const db = await getDb()
Minimize bundle size and avoid heavy initialization code.
// ✅ Works - uses getDb() which handles env detection
const { getDb } = await import('~/lib/db')
const db = await getDb()
// ❌ Fails - process.env not available
const url = process.env.DATABASE_URL
Browser → Cloudflare CDN → Worker → TanStack Start → Server Functions → Neon PostgreSQL
Static assets are served from Cloudflare's CDN automatically. The public/ directory contents are deployed alongside the Worker.
neon-database - Database connection patternsdynamic-imports - Why dynamic imports are requiredtanstack-start - Server function patternsdata-ai
Input validation patterns with Zod in LivestockAI server functions
testing
Unit testing patterns with Vitest in LivestockAI
tools
Server → Service → Repository pattern for feature organization
data-ai
Server-side rendering and server functions with TanStack Start in LivestockAI