A production-ready monorepo demonstrating how to build a full-stack application with a SvelteKit frontend and a Cloudflare Worker backend for image transformation workflows, complete with seamless local development support.
This monorepo showcases best practices for integrating Cloudflare Workers with SvelteKit applications. It provides a unified local development experience where both the frontend and backend run together, allowing you to develop and test your image transformation pipeline as if it were deployed to Cloudflare's edge network.
Cloudflare Workers are lightweight, fast serverless functions that run on Cloudflare's edge network. They enable you to build scalable applications without managing infrastructure, making them ideal for image processing, API gateways, and real-time transformations.
This monorepo consists of two main applications:
image-transformerA Cloudflare Worker that handles image transformation logic. This service:
/upload, /status, /view) for the frontendsk-image-transformerA modern SvelteKit application serving as the user interface:
Install dependencies across the monorepo:
pnpm i
Start the development environment:
pnpm start
This single command:
Once running, open your browser and navigate to:
http://localhost:5173/
You should see the SvelteKit application ready to upload and transform images using the local Worker backend.
The key to seamless local development is the Vite proxy and Wrangler integration:
Vite Configuration (sk-image-transformer/vite.config.ts):
/upload, /status, and /view endpointshttp://127.0.0.1:8787Development Script (dev.mjs):
Communication:
/upload, /status, /view endpointsPOST /upload
- Accept: multipart/form-data
- Body: FormData with 'file' field
- Returns: JSON with transformation details
GET /status?id={transformation_id}
- Returns: JSON with current transformation status
GET /view/{image_id}
- Returns: Transformed image file or metadata
Ready to go live? Follow these steps:
Update the wrangler.jsonc files in both image-transformer and sk-image-transformer directories with your Cloudflare account details:
{
"name": "image-transformer",
"main": "src/index.ts",
"compatibility_date": "2024-01-01",
"env": {
"production": {
"routes": [
{ "pattern": "example.com/worker/*", "zone_name": "example.com" }
]
}
}
}
If using Cloudflare R2 for storage:
pnpm dlx wrangler r2 bucket create image-transformer-bucket
Deploy the backend worker first:
cd image-transformer
pnpm run deploy
Then deploy the SvelteKit application:
cd ../sk-image-transformer
pnpm run deploy
pnpm start # Start both Worker and SvelteKit dev servers
pnpm format # Format code across all workspaces
image-transformer (Worker)pnpm dev # Start Wrangler dev server
pnpm deploy # Deploy to Cloudflare
pnpm test # Run tests with Vitest
pnpm cf-typegen # Generate TypeScript types for worker
sk-image-transformer (SvelteKit)pnpm dev # Start Vite dev server
pnpm build # Build for production
pnpm preview # Preview production build locally
pnpm deploy # Deploy to Cloudflare Pages
pnpm lint # Run linting with ESLint and Prettier
pnpm format # Format code with Prettier
pnpm check # Type-check with svelte-check
ā
Unified Local Development - Frontend and backend run together locally with proxy routing
ā
Image Transformation - Process images at the edge with Cloudflare Workers
ā
CORS Support - Vite proxy handles CORS bypassing during development
ā
Multi-Drive Support - Upload files from any drive on Windows (not just C:)
ā
Production Ready - Same setup works during development and after deployment
ā
Type Safe - Full TypeScript support in both frontend and backend
ā
Hot Reloading - Automatic refresh during development
ā
Testing - Vitest integration for Worker testing
Feel free to fork this repository and use it as a starting point for your own Cloudflare + SvelteKit image processing projects!
This project is open source and available under the MIT License.