create-hono-server
v1.0.3
Published
Scaffold a Hono server with authentication, RBAC, and OpenAPI docs
Maintainers
Readme
create-hono-server
A CLI tool to scaffold a production-ready Hono server with JWT authentication, role-based access control (RBAC), PostgreSQL, Drizzle ORM, and OpenAPI documentation.
Features
✅ Interactive CLI with prompts
✅ Multiple package manager support (bun, npm, pnpm, yarn)
✅ JWT-based authentication with HTTP-only cookies
✅ Role-based access control (admin, moderator, user)
✅ PostgreSQL + Drizzle ORM
✅ OpenAPI 3.0 documentation with Scalar API Reference
✅ Zod validation
✅ TypeScript support
✅ Production-ready code structure
✅ Beautiful colored terminal output
Usage
npx create-hono-serverOr with a specific package manager:
bunx create-hono-serverWhat You Get
Running this CLI will create a new Hono server project with:
Authentication System
- POST
/auth/signup- User registration (defaults to "user" role) - POST
/auth/login- User login - Cookie-based JWT authentication
- POST
Role-Based Access Control
- Three roles:
user,moderator,admin - Role checker middleware for protected routes
- JWT tokens include role information
- Three roles:
User Management
- GET
/users/me- Get current user (protected) - GET
/users/allusers- Get all users with pagination (requires admin or moderator role)
- GET
Documentation
- GET
/reference- Interactive API docs (Scalar) - GET
/openapi.json- OpenAPI specification
- GET
Database
- PostgreSQL with Drizzle ORM
- User and session tables
- Type-safe queries
Project Structure
your-project/
├── src/
│ ├── index.ts # Main application
│ ├── db/
│ │ ├── schema.ts # Database schema (with roles)
│ │ ├── connection.ts # DB connection
│ │ └── init.ts # DB initialization
│ ├── middleware/
│ │ ├── auth.ts # Auth middleware
│ │ └── roleChecker.ts # Role-based access control
│ ├── routes/
│ │ ├── auth.ts # Auth routes
│ │ └── users.ts # User routes (with RBAC)
│ └── utils/
│ └── auth.ts # Auth utilities
├── package.json
├── tsconfig.json
├── drizzle.config.ts
├── .env.example
├── .gitignore
└── README.mdQuick Start
After creating your project:
# Navigate to project
cd your-project-name
# Create .env file (use .env.example as template)
cp .env.example .env
# Edit .env with your database credentials
# DATABASE_URL=postgresql://user:password@localhost:5432/dbname
# JWT_SECRET=your-secret-key
# Push database schema
bun run db:push
# Start development server
bun run devVisit http://localhost:3000/reference for API documentation.
Available Scripts
bun run dev- Start development server with hot reloadbun run start- Start production serverbun run db:generate- Generate database migrationsbun run db:push- Push schema to databasebun run db:studio- Open Drizzle Studio
Tech Stack
- Hono - Ultrafast web framework
- Drizzle ORM - TypeScript ORM
- Zod - Schema validation
- Scalar - API documentation
- Bun - JavaScript runtime
- PostgreSQL - Database
Development
Local Testing
npx create-hono-server
Requirements
- Node.js 18+ or Bun
- PostgreSQL database (local or cloud like Neon)
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues and questions, please open an issue on the GitHub repository.
Made with ❤️ using Hono and Bun
