sveltekit-hono Svelte Themes

Sveltekit Hono

A modern, full-stack web application template combining the power of SvelteKit frontend with Hono API backend, optimized for deployment on Cloudflare Workers.

šŸš€ SvelteKit + Hono + Cloudflare Workers

A modern, full-stack web application template combining the power of SvelteKit frontend with Hono API backend, optimized for deployment on Cloudflare Workers.

✨ Features

  • šŸ”„ Lightning Fast - SvelteKit for optimal performance and developer experience
  • 🌐 Global Edge Deployment - Cloudflare Workers for worldwide low-latency
  • šŸ› ļø Type-Safe API - Hono with full TypeScript support and validation
  • šŸŽØ Modern UI - TailwindCSS for beautiful, responsive design
  • šŸ”§ Developer Experience - Hot reload, TypeScript, ESLint, Prettier
  • šŸš€ Production Ready - Optimized builds and edge-side caching
  • šŸ”’ Environment Management - Secure variable handling for all environments
  • šŸ“Š Built-in Monitoring - Health checks and request logging

šŸ—ļø Tech Stack

šŸš€ Quick Start

Prerequisites

  • Node.js 18+ and pnpm installed
  • Cloudflare account (for deployment)
  • Wrangler CLI: npm install -g wrangler

Installation

  1. Clone the repository

    git clone <your-repo-url>
    cd sveltekit-hono
    
  2. Install dependencies

    pnpm install
    
  3. Set up environment variables

    cp .env.example .env.local
    
  4. Start development server

    pnpm dev
    
  5. Open your browser Visit http://localhost:5173

šŸ› ļø Development

Available Scripts

Command Description
pnpm dev Start SvelteKit development server
pnpm dev:cf Start Cloudflare Workers development server
pnpm build Build for production
pnpm preview Preview production build locally
pnpm preview:cf Preview with Cloudflare Workers simulation
pnpm deploy Deploy to Cloudflare Workers
pnpm deploy:cf Deploy to Cloudflare production environment
pnpm check Run TypeScript and Svelte checks
pnpm lint Lint code with ESLint and Prettier
pnpm format Format code with Prettier

Development Workflows

For Frontend Development:

pnpm dev  # Fastest hot reload, recommended for UI work

For Full-Stack with Cloudflare Simulation:

pnpm dev:cf  # Test with Cloudflare Workers environment

🌐 API Endpoints

The Hono API provides the following endpoints:

Method Endpoint Description
GET /api/health Health check and environment info
GET /api/hello Basic hello endpoint with request info
GET /api/users Get all users (demo data)
POST /api/users Create a new user
PUT /api/users/:id Update user by ID
DELETE /api/users/:id Delete user by ID

Example API Usage

// Fetch users
const response = await fetch('/api/users');
const { users } = await response.json();

// Create user
const newUser = await fetch('/api/users', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ name: 'John Doe', email: '[email protected]' })
});

šŸ“ Project Structure

ā”œā”€ā”€ src/
│   ā”œā”€ā”€ routes/
│   │   ā”œā”€ā”€ +page.svelte          # Main demo page
│   │   ā”œā”€ā”€ +layout.svelte        # App layout
│   │   └── api/
│   │       └── [...paths]/
│   │           └── +server.ts     # Hono API server
│   ā”œā”€ā”€ lib/
│   │   └── env.ts                # Environment configuration
│   ā”œā”€ā”€ models/
│   │   └── user.model.ts         # TypeScript models
│   ā”œā”€ā”€ types/
│   │   └── health.ts             # Type definitions
│   ā”œā”€ā”€ app.html                  # HTML template
│   └── app.css                   # Global styles
ā”œā”€ā”€ static/                       # Static assets
ā”œā”€ā”€ wrangler.toml                 # Cloudflare Workers config
ā”œā”€ā”€ svelte.config.js              # SvelteKit configuration
ā”œā”€ā”€ vite.config.ts                # Vite configuration
└── DEVELOPMENT.md                # Detailed development guide

šŸš€ Deployment

Cloudflare Workers Deployment

  1. Login to Cloudflare

    wrangler login
    
  2. Deploy to development

    pnpm deploy
    
  3. Deploy to production

    pnpm deploy:cf
    

Environment Variables

Configure your environment variables in:

  • Local development: .env.local
  • Cloudflare Workers: wrangler.toml
# wrangler.toml
[vars]
ENVIRONMENT = "development"

[env.production.vars]
ENVIRONMENT = "production"

šŸ”§ Configuration

Environment Variables

# .env.local
ENVIRONMENT=development
API_BASE_URL=http://localhost:5173/api
CF_PAGES_URL=https://localhost:8787

Cloudflare Workers

The application is optimized for Cloudflare Workers with:

  • Global Edge Deployment - Ultra-low latency worldwide
  • Automatic HTTPS - SSL certificates handled automatically
  • Static Asset Optimization - CDN-cached static files
  • Serverless Functions - API routes as Cloudflare Workers

šŸ¤ Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

šŸ“š Documentation

šŸ› Troubleshooting

Common Issues

API routes not working in production?

  • Check wrangler.toml configuration
  • Ensure all HTTP methods are exported in +server.ts

Environment variables not accessible?

  • Client-side vars must be prefixed with PUBLIC_
  • Server-side vars must be configured in wrangler.toml

Build errors?

  • Run pnpm check for TypeScript validation
  • Check all imports and dependencies

For more troubleshooting tips, see DEVELOPMENT.md.

šŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

⭐ Show your support

Give a ā­ļø if this project helped you!


Built with ā¤ļø using SvelteKit, Hono, and Cloudflare Workers

Top categories

Loading Svelte Themes