A production-ready template for building full-stack web applications using SvelteKit and Cloudflare Workers, optimized for LLM-assisted development and rapid prototyping.
src/
โโโ lib/
โ โโโ components/ # Reusable Svelte components
โ โโโ server/ # Server utilities (D1 helpers, retry logic)
โ โโโ stores/ # Svelte stores for state management
โโโ routes/
โ โโโ api/ # API endpoints (+server.ts files)
โ โ โโโ hello/ # Example endpoint with D1 integration
โ โ โโโ test-local-d1/ # Local development test endpoint
โ โโโ +page.svelte # Home page
migrations/ # D1 database migrations (auto-generated)
CLAUDE.md # Development workflow documentation
D1-FUTURE-BEST-PRACTICES.md # Advanced D1 patterns and monitoring
VITE-PLUGIN-SETUP.md # Local development setup guide
From zero to fully-functional local development in 2 minutes.
git clone <your-repo-url>
cd svelte-template
npm install # Installs latest dependencies (Vite 7, Svelte 5.39, SvelteKit 2.46)
For production deployment, uncomment and configure in wrangler.toml
:
# Uncomment when ready to deploy
# account_id = "YOUR_ACCOUNT_ID"
# [[env.dev.d1_databases]]
# binding = "DB"
# database_name = "your-app-db-dev"
# database_id = "your-dev-database-id"
# [[env.prod.d1_databases]]
# binding = "DB"
# database_name = "your-app-db-prod"
# database_id = "your-prod-database-id"
# Option 1: Standard development (no database)
npm run dev
# Option 2: Full-stack development with local D1 database
npm run dev:local-db
๐ Success! Visit http://localhost:5173
Test API with real D1 bindings: http://localhost:5173/api/test-local-d1
Deploy your app to Cloudflare Workers with a real D1 database.
wrangler login
completed# Create your development database
wrangler d1 create your-app-db-dev
# Copy the database ID from the output and update wrangler.toml:
# [[env.dev.d1_databases]]
# binding = "DB"
# database_name = "your-app-db-dev"
# database_id = "paste-your-database-id-here"
# Apply your local migrations to the dev database
./build.sh --migrate-dev
# Or using npm scripts
npm run migrate:apply:dev
# Deploy to development environment
./build.sh --deploy-dev
# Or using npm scripts
npm run deploy:dev
# Check deployment status
wrangler deployments list
# Test your deployed API endpoints
curl https://your-app-dev.your-subdomain.workers.dev/api/hello
curl https://your-app-dev.your-subdomain.workers.dev/api/test-schema
๐ Success! Your app is now running on Cloudflare Workers with a real D1 database.
wrangler d1 create your-app-db-prod
./build.sh --deploy-prod
Let Claude Code (or your favorite LLM) transform your idea into working code.
This template is optimized for LLM-assisted development. Here's the proven workflow:
Example prompt to Claude Code:
I want to build a task management app with the following features:
- Users can create, edit, delete tasks
- Tasks have: title, description, due date, priority, status
- Simple dashboard showing overdue/upcoming tasks
- User authentication with email/password
Please:
1. Create the database schema and first migration
2. Build basic CRUD API endpoints
3. Create a simple UI for task management
4. Add user authentication
Claude Code will:
migrations/
src/routes/api/
# Apply migrations to local database
npm run migrate:apply:local
# Start development server with D1 bindings
npm run dev:local-db
# Test your endpoints immediately
curl http://localhost:5173/api/tasks
# Create your Cloudflare databases
wrangler d1 create your-app-db-dev
wrangler d1 create your-app-db-prod
# Update wrangler.toml with database IDs
# Apply migrations to remote databases
npm run migrate:apply:dev
npm run migrate:apply:prod
# Deploy to development environment
npm run deploy:dev
# Test production-like environment
# Deploy to production when ready
npm run deploy:prod
๐ฏ Result: From problem statement to deployed app in 15-30 minutes!
The modern development workflow optimized for rapid iteration and LLM collaboration.
Embrace experimentation. With this setup, trying ideas is cheap and abandoning failed branches is normal and healthy. The goal is to move fast and learn quickly.
git checkout -b feature/user-dashboard
# or
git checkout -b experiment/ai-task-suggestions
# or
git checkout -b fix/authentication-bug
Typical conversation with Claude Code:
"Add a user dashboard that shows:
- Task completion stats for the last 30 days
- Upcoming deadlines this week
- A quick-add task form
- Recent activity feed
Make it look modern with good UX. Add any necessary API endpoints."
Claude Code will:
# Apply any new migrations
npm run migrate:apply:local
# Start development with hot reload
npm run dev:local-db
Everything works locally with real database:
Ask Claude Code to test your features:
"Create Playwright tests that:
1. Sign up a new user
2. Create 5 tasks with different priorities
3. Mark some as complete
4. Verify dashboard shows correct stats
5. Test the quick-add task form"
Claude Code will generate and run comprehensive UI tests.
# Apply migrations to dev database
npm run migrate:apply:dev
# Deploy to development environment
npm run deploy:dev
Get instant preview URL for stakeholder review.
# Create Time Travel backup (automatic)
npm run migrate:apply:prod # Includes backup + migration
# Deploy to production
npm run deploy:prod
Test in production environment with real traffic.
git add .
git commit -m "Add user dashboard with stats and quick-add form
๐ Generated with Claude Code
https://claude.com/claude-code
Co-Authored-By: Claude <[email protected]>"
git push origin feature/user-dashboard
# Create PR via GitHub CLI or web interface
# This approach didn't work out - no worries!
git checkout main
git branch -D experiment/ai-task-suggestions
# Try a different approach
git checkout -b experiment/better-ai-suggestions
๐ฏ Key Insight: Failed branches are learning opportunities, not wasted time.
# Create new migration
./build.sh --migrate-create "add_task_categories"
# Ask Claude Code to populate the migration:
"Add a categories table with name, color, and icon fields.
Add a category_id foreign key to tasks table."
# Test locally
npm run migrate:apply:local
npm run dev:local-db
# Deploy when ready
npm run migrate:apply:dev
npm run migrate:apply:prod
Ask Claude Code:
"Optimize the dashboard API - it's getting slow with lots of tasks.
Add pagination, caching, and better database queries."
# Check backup timestamps
npm run db:backup-info
# Rollback if something goes wrong (prod only)
./build.sh --migrate-rollback 1672531200
npm run dev # Standard development
npm run dev:local-db # Local development with D1 bindings
npm run dev:reset-db # Fresh local database + restart
./build.sh --migrate-create "description" # Create migration
./build.sh --migrate-local # Apply to local DB
./build.sh --migrate-dev # Apply to dev environment
./build.sh --migrate-prod # Apply to prod (with backup)
./build.sh --migrate-status [local|dev|prod] # Check migration status
npm run deploy:dev # Deploy to development
npm run deploy:prod # Deploy to production
npm run db:backup-info # View Time Travel backups
./build.sh --migrate-rollback TIMESTAMP # Rollback production DB
This template embodies "vibe coding" - a development philosophy optimized for the LLM era:
โ DO:
โ DON'T:
The goal: Maximum learning velocity and rapid value delivery.
Happy coding! ๐