sveltekit-workers-d1-auth Svelte Themes

Sveltekit Workers D1 Auth

sveltekit + D1 + Drizzle + Lucia template for Cloudflare Workers

SvelteKit + Cloudflare Workers + D1 Template

A modern full-stack template using SvelteKit, TypeScript, Cloudflare Workers, Lucia Auth, Drizzle ORM, and Cloudflare D1.

Tech Stack

  • šŸŽÆ SvelteKit - Full-stack web framework
  • šŸ”’ Lucia Auth - Authentication
  • šŸ“¦ Cloudflare D1 - SQLite database on the edge
  • šŸ› ļø Drizzle ORM - Type-safe ORM
  • šŸ’Ø TailwindCSS - Utility-first CSS
  • šŸ“¦ Bun - Fast package manager & runtime
  • šŸ“¦ Prettier - Formatting svelte files only
  • šŸ“¦ Biome - Formatting all other files + Linting

Getting Started

  1. Clone the repository:
git clone https://github.com/amxv/sveltekit-workers-d1-auth.git
cd sveltekit-workers-d1-auth
  1. Install dependencies:
bun install
  1. Set up Cloudflare D1 Database:
# 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"
  1. Configure your environment:
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).

  1. Initialize and sync your database:

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
  1. (Optional) View your database with Drizzle Studio:
bunx drizzle-kit studio

Development

Start the development server:

bun run dev

Cloudflare Bindings

Add bindings to src/app.d.ts to use them in your code.

Deployment

Deploy to Cloudflare Workers:

bun run deploy

License

MIT

Top categories

Loading Svelte Themes