Skip to content

RACDOX/create-hono-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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-server

Or with a specific package manager:

bunx create-hono-server

What 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
  • Role-Based Access Control

    • Three roles: user, moderator, admin
    • Role checker middleware for protected routes
    • JWT tokens include role information
  • User Management

    • GET /users/me - Get current user (protected)
    • GET /users/allusers - Get all users with pagination (requires admin or moderator role)
  • Documentation

    • GET /reference - Interactive API docs (Scalar)
    • GET /openapi.json - OpenAPI specification
  • 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.md

Quick 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 dev

Visit http://localhost:3000/reference for API documentation.

Available Scripts

  • bun run dev - Start development server with hot reload
  • bun run start - Start production server
  • bun run db:generate - Generate database migrations
  • bun run db:push - Push schema to database
  • bun run db:studio - Open Drizzle Studio

Tech Stack

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published