Cloudflare Workers API Development
When to use this skill
When implementing production-grade backend APIs using Cloudflare Workers with SvelteKit, including complex authentication patterns, database operations, session management, file storage integrations, and comprehensive error handling.
Overview
This skill provides comprehensive guidance for building serverless APIs with Cloudflare Workers and SvelteKit. The content is organized into focused sub-skills for progressive learning:
- Project structure and environment configuration
- API route patterns with SvelteKit
- TypeScript setup and type definitions
- Session-based authentication with KV storage
- Challenge-response authentication
- Security middleware patterns
- Schema management with Drizzle ORM
- Database client setup and utilities
- Advanced querying and pagination
- Presigned URL generation (AWS Signature v4)
- File management operations
- Upload/download API routes
- Comprehensive error handlers
- Structured logging patterns
- API error response standards
- Caching strategies
- API integration testing
- Production deployment best practices
Quick Start Guide
- Project Setup: Start with Core Architecture for proper project structure
- Authentication: Implement security patterns using the Authentication module
- Database: Add data persistence with D1 Database operations
- Storage: Integrate file handling with R2 Storage
- Production: Apply Performance & Testing patterns for deployment
Prerequisites
- Node.js 18+ and npm/yarn
- Cloudflare account with Workers, D1, KV, and R2 enabled
- SvelteKit project setup knowledge
- TypeScript proficiency
- Basic understanding of serverless concepts
Development Workflow
# Install dependencies
npm install @sveltejs/adapter-cloudflare drizzle-orm
# Set up Cloudflare bindings
# See architecture/ for detailed environment setup
# Run locally
npm run dev
# Deploy to production
npm run build
npx wrangler deploy
Key Benefits
- Production Ready: Battle-tested patterns for enterprise applications
- Type Safe: Full TypeScript coverage with comprehensive type definitions
- Secure: Zero-knowledge architecture with client-side encryption options
- Scalable: Built for high-traffic applications with proper caching strategies
- Maintainable: Modular structure following OpenCode skill factory patterns
Navigation Tips
- Each sub-skill is self-contained and can be loaded independently
- Progress sequentially from architecture to deployment
- Cross-references between modules for related concepts
- All code examples are production-tested and ready to implement
Get started with Core Architecture or jump to any specific module based on your needs.