- ⚡️ Powered by Bun: Uses the fast Bun runtime for development, testing, and bundling.
- 🚀 Blazing Fast Hono: Built on the Hono web framework, known for its exceptional performance.
- 🐘 PostgreSQL with Drizzle ORM: Type-safe SQL queries and schema management with Drizzle ORM.
- 🛡️ JWT Authentication: Secure user authentication using JSON Web Tokens.
- 👑 Role-Based Access Control (RBAC): Middleware to protect routes based on user roles (
admin,user). - caching for frequently accessed data.
- 📝 Input Validation: Uses
zodfor robust and type-safe validation of incoming requests. - 🐳 Optimized for Docker: Includes a multi-stage
Dockerfilethat builds a tiny, secure production image.
- Runtime: Bun
- Framework: Hono
- Database: PostgreSQL
- ORM: Drizzle ORM
- Authentication: Hono/jwt
- Validation: Zod &
@hono/zod-validator - Caching: Redis
- Containerization: Docker
-
Install dependencies:
bun install
-
Set up Environment Variables: Create a
.envfile in the root of the project by copying the example file.cp .env.example .env
Then, fill in the required values in the
.envfile:DATABASE_URL="postgres://USER:PASSWORD@HOST:PORT/DATABASE" JWT_SECRET="your-super-secret-and-long-jwt-secret-key" REDIS_URL="redis://127.0.0.1:6379" PORT="3000"
-
Run Database Migrations: This command will generate your schema and apply them to the database.
bun run db:push
-
Development Server: Start the server in watch mode.
bun dev
-
Production Build: Compile the application into a single binary.
bun run build
-
Start in Production Mode: Run the compiled binary. Requires environment variables to be set manually.
bun start
| Method | Path | Description | Auth Required | Admin Only |
|---|---|---|---|---|
POST |
/api/auth/register |
Register a new user. | ❌ | ❌ |
POST |
/api/auth/login |
Log in to get a JWT. | ❌ | ❌ |
GET |
/api/posts |
Get a list of all posts. | ❌ | ❌ |
GET |
/api/posts/:id |
Get a single post by its ID. | ❌ | ❌ |
POST |
/api/posts |
Create a new post. | ✅ | ❌ |
DELETE |
/api/posts/:id |
Delete a post by its ID. | ✅ | ✅ |
This project is fully containerized for easy deployment.
-
Build the Docker image:
docker build -t your-api-name . -
Run the Docker container: Make sure to pass all required environment variables to the container.
docker run -p 3000:3000 \ -e DATABASE_URL="<your_database_url>" \ -e JWT_SECRET="<your_jwt_secret>" \ -e REDIS_URL="<your_redis_url>" \ -d your-api-name