A modern, production-ready starter template for building fast and scalable APIs on Cloudflare Workers. This kit combines the power of Hono framework, Drizzle ORM, and Zod validation to give you everything you need to build robust serverless applications.
This starter kit comes with a carefully curated stack of modern tools:
- 🚀 Hono - Lightning-fast web framework with excellent TypeScript support
- 🗄️ Drizzle ORM - Type-safe database operations with SQL-like syntax
- 🐘 neondatabase/serverless - Serverless PostgreSQL database package with automatic scaling
- ✅ Zod - Runtime type validation and schema definition
- ☁️ Cloudflare Workers - Global edge computing platform
- 🧪 Vitest - Fast unit testing framework
- 🎯 TypeScript - Full type safety throughout your application
- 🎨 Code Quality - ESLint + Prettier with
@antfu/eslint-config - 🔒 Git Hooks - Husky + lint-staged for automated code quality checks
.
├── .github/ # GitHub-specific configurations
│ └── workflows/ # Automation workflows for testing, deployment, etc.
├── .husky/ # Git hooks (e.g., pre-commit)
├── .vscode/ # VS Code workspace-specific settings
├── src/
│ ├── config/ # Configuration files
│ ├── db/ # Database related code
│ │ ├── connection.ts # Database connection setup
│ │ └── schema/ # Drizzle schema definitions
│ ├── middlewares/ # Hono middlewares
│ ├── routes/ # API routes
│ ├── services/ # Business logic
│ └── index.ts # Entry point
├── tests/ # Test files
├── .env.example # Environment variables template
├── .dev.vars.example # Development environment variables template
├── .lintstagedrc # Configuration for lint-staged (pre-commit)
├── drizzle.config.ts # Drizzle configuration
├── eslint.config.mjs # ESLint configuration
├── package.json # Project metadata and dependencies
├── tsconfig.json # TypeScript configuration
└── wrangler.toml # Cloudflare Workers configuration
# Clone the repository
git clone https://github.com/Musanna-al-akil/cloudflare-hono-drizzle-zod-starter-pack.git
# Navigate to the project directory
cd cloudflare-hono-drizzle-zod-starter-pack
# Install dependencies
bun installCreate your environment files by copying the examples:
# Copy environment files
cp .env.example .env
cp .dev.vars.example .dev.varsThen update the files with your actual values:
.env file:
DB_URL=your_database_connection_string_here.dev.vars file:
SECRET_KEY=your_secret_key_here
DB_URL=your_database_connection_string_here# Start the development server
bun run devYour API will be available at http://localhost:8787
# Login to Cloudflare (first time only)
bunx wrangler login
# Deploy to Cloudflare Workers
bun run deploy| Command | Description |
|---|---|
bun run dev |
Start development server with hot reload |
bun run deploy |
Deploy to Cloudflare Workers |
bun run lint |
Check code for style and quality issues |
bun run lint:fix |
Automatically fix linting errors |
bun run db:generate |
Generate database migrations |
bun run db:migrate |
Apply database migrations |
The following environment variables are required:
| Variable | Description | Example |
|---|---|---|
DB_URL |
Database connection string | postgresql://user:pass@host:port/db |
SECRET_KEY |
Application secret key | your-super-secret-key-here |
This starter uses Drizzle ORM for database operations and is currently configured with Neon (PostgreSQL), but can be easily configured to work with any database that Drizzle supports.
Currently configured for:
- Neon - Serverless PostgreSQL with automatic scaling
Other supported databases:
- PostgreSQL, MySQL, SQLite, SQL Server, and more
To set up your database:
-
Generate migrations:
bun run db:generate
-
Apply migrations:
bun run db:migrate
Run your test suite with:
bun test- Fast: Built for speed with minimal overhead
- TypeScript-first: Excellent TypeScript support out of the box
- Middleware support: Easy to extend with custom middleware
- Multiple platforms: Works on Cloudflare Workers, Deno, Bun, and Node.js
- Type-safe: Full TypeScript support with automatic type inference
- SQL-like syntax: Familiar query syntax that's easy to learn
- Migration system: Version-controlled database schema changes
- Multiple databases: Support for PostgreSQL, MySQL, SQLite, and more
- Runtime validation: Ensure data integrity at runtime
- Type inference: Automatically generate TypeScript types from schemas
- Error handling: Detailed error messages for validation failures
- Schema composition: Build complex schemas from simple ones
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ by Musanna AL Akil
For questions, issues, or contributions, please open an issue on GitHub.