Skip to content

πŸš€ A modern, containerized E-Library REST API built with Bun, Hono, Drizzle ORM, and PostgreSQL.

Notifications You must be signed in to change notification settings

masmuss/hono-elibrary

Repository files navigation

πŸ“– E-Library API

Bun Hono Badge Drizzle ORM PostgreSQL Redis Badge Docker Scalar Badge Zod Badge TypeScript Biome Badge

A backend API for a simple e-library system built with a modern stack, featuring Bun as the runtime, Hono as the web framework, and Drizzle as the ORM. This project is fully containerized with Docker for ease of development and deployment.

✨ Key Features

  • Authentication & Authorization: JWT-based registration, login, and logout system with Role-Based Access Control (RBAC).
  • User Management (Admin): Full CRUD operations for managing users and their roles (ADMIN, LIBRARIAN, MEMBER).
  • Content Management (Admin): Ability to create, read, update, and delete book and category data.
  • Loan Lifecycle: A complete book loan workflow, from a member's request, approval/rejection by a librarian, to the final return of the book.
  • Member Profile & History: Members can view their personal profile and their own loan history.
  • API Validation & Documentation: Type-safe request validation using Zod, and automated, interactive API documentation with @hono/zod-openapi and Scalar UI.
  • Centralized Error Handling: A consistent and informative error handling system across all endpoints.
  • Automated Code Quality: Equipped with Git Hooks using Husky and Biome to ensure code quality and formatting before every commit and push.

πŸ› οΈ Tech Stack

πŸš€ Getting Started

To run this project in your local environment, you must have Bun and Docker installed.

1. Clone the Repository

git clone https://github.com/masmuss/hono-elibrary.git
cd hono-elibrary

2. Run the Setup Script

First, make the script executable:

chmod +x setup.sh

Then, run it:

./setup.sh

The script will check your dependencies, create the necessary .env files, and guide you through starting the services.

Your application will be running and accessible at http://localhost:3000.

πŸ“š Usage

API Documentation

This project includes interactive API documentation powered by Scalar. You can access it to see all available endpoints and try them out directly.

  • Documentation URL: http://localhost:3000/reference

Running Unit Tests

Ensure your Docker services are running (docker-compose up). Then, in a separate terminal, run the following command:

bun run test

This command will execute all test files in the test/ directory using the environment defined in .env.test.

Database Migrations

This project uses drizzle-kit to manage database schema migrations.

  • To generate a new migration file after changing the schema in src/db/schema.ts:

    bun run migrate:generate
  • To apply migrations manually (optional, as it's automated on startup):

    docker-compose exec app bun run db:migrate

πŸ“‚ Project Structure

e-library/
β”œβ”€β”€ .husky/         # Git Hooks configuration
β”œβ”€β”€ src/            # Source code
β”‚   β”œβ”€β”€ core/       # Core logic: base classes, handlers, repositories, schemas
β”‚   β”œβ”€β”€ db/         # Drizzle config, schema, and migration files
β”‚   β”œβ”€β”€ lib/        # Hono app setup and global types
β”‚   β”œβ”€β”€ middlewares/  # Custom middlewares
β”‚   β”œβ”€β”€ routes/     # API endpoint definitions
β”‚   └── index.ts    # Main application entry point
β”œβ”€β”€ test/           # All unit test files
β”œβ”€β”€ .env.docker.example # Example environment file for Docker
β”œβ”€β”€ .env.test.example   # Example environment file for testing
β”œβ”€β”€ docker-compose.yml # Docker services definition
β”œβ”€β”€ Dockerfile.dev    # Instructions for building the development image
β”œβ”€β”€ setup.sh        # Interactive setup script for new developers
└── package.json    # Project dependencies and scripts

Made with ❀️ and a passion for learning!

About

πŸš€ A modern, containerized E-Library REST API built with Bun, Hono, Drizzle ORM, and PostgreSQL.

Topics

Resources

Stars

Watchers

Forks