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.
- 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-openapiand 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.
- Runtime: Bun
- Web Framework: Hono
- Database: PostgreSQL
- ORM: Drizzle ORM
- Caching: Redis
- Validation: Zod
- Containerization: Docker & Docker Compose
- Language: TypeScript
- Code Quality: Biome (Linter & Formatter) & Husky (Git Hooks)
To run this project in your local environment, you must have Bun and Docker installed.
git clone https://github.com/masmuss/hono-elibrary.git
cd hono-elibraryFirst, 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.
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
Ensure your Docker services are running (docker-compose up). Then, in a separate terminal, run the following command:
bun run testThis command will execute all test files in the test/ directory using the environment defined in .env.test.
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!