A modern full-stack template using SvelteKit, TypeScript, Cloudflare Workers, Lucia Auth, Drizzle ORM, and Cloudflare D1.
git clone https://github.com/amxv/sveltekit-workers-d1-auth.git
cd sveltekit-workers-d1-auth
bun install
# Create a new D1 database
bunx wrangler d1 create your-database-name
After creating the database, you'll see output like this:
ā
Successfully created DB 'your-database-name'
Created D1 database 'your-database-name' (DATABASE_ID)
Add the following to your wrangler.toml:
[[d1_databases]]
binding = "DB" # i.e. available in your Worker on env.DB
database_name = "your-database-name"
database_id = "DATABASE_ID"
mv .env.example .env
mv wrangler.toml.example wrangler.toml
Edit wrangler.toml
and add the D1 configuration from step 3 (make sure to keep the migrations_dir).
For local development:
# Generate migrations
bunx drizzle-kit generate
# apply migrations to your local D1 database
bunx wrangler d1 migrations apply your-database-name
For production:
# apply migrations to your production D1 database
bunx wrangler d1 migrations apply your-database-name --remote
bunx drizzle-kit studio
Start the development server:
bun run dev
Add bindings to src/app.d.ts
to use them in your code.
Deploy to Cloudflare Workers:
bun run deploy
MIT