I love NestJS and their workflow, but sadly, cloudflare cannot compatible for NestJS. This porject just a template for mimic NestJS workflow.
This template mimics NestJS's folder structure and separation of concerns (controllers, services, entities) while staying lightweight and fully compatible with Cloudflare Workers.
- Module-based folder structure (
src/module/) - Separation of concerns: controllers, services, entities
- Auto-generated OpenAPI/Swagger docs (
/doc-ui) - Global error handling
- Drizzle ORM + PostgreSQL setup with Docker Compose
- Route utility (
CreateRouteUtil) for standardized route definitions
- Dependency Injection / IoC container
- Decorator-based routing (
@Get,@Post,@Controller,@Injectable) - Guards (authentication, role-based access)
- Interceptors (logging, response transformation)
- Pipes (automatic Zod validation)
- Exception filters (per-controller error handling)
- Wire Drizzle ORM into services
- Complete user module (full CRUD)
nodejs>=24.7.0pnpm>=10.15.0hono>=4.9.5zod>=4.1.5
pnpm install
pnpm run dev
This project uses drizzle-orm as ORM, and drizzle-kit for database migrations.
-
Setup your database and get the connection string (Example:
postgresql://user:password@localhost:5432/mydb) -
Create a
.envfile in the root directory (or you can copy, paste, and rename the .env.example into .env) and add your database connection string:
DATABASE_URL=postgresql://user:password@localhost:5432/mydb
- Run the migration command to create the necessary tables in your database:
a. For genererating migration files based on schema changes:
pnpm drizzle-kit generate
b. For applying the migrations to the database:
pnpm drizzle-kit migrate
- Verify that the tables have been created in your database. You can try running the seed command to populate initial data:
pnpm tsx src/db/seed.ts
-
Add and edit schema files in the
/src/db/schema.tsas needed. You also can edit the seed data in/src/db/seed.ts. -
For more commands and options, refer to the Drizzle ORM documentation for PostgreSQL: https://orm.drizzle.team/docs/get-started/postgresql-new
This project includes a docker-compose.yml file to set up a PostgreSQL database using Docker Compose.
To start the PostgreSQL database, run the following command in the terminal:
docker compose up -d
Just make sure before running the command, you need to check the env