https://github.com/masmuss/hono-elibrary
🚀 A modern, containerized E-Library REST API built with Bun, Hono, Drizzle ORM, and PostgreSQL.
https://github.com/masmuss/hono-elibrary
api biomejs bun docker drizzle-orm elibrary-project honojs postgresql redis scalar typescript zod
Last synced: 3 months ago
JSON representation
🚀 A modern, containerized E-Library REST API built with Bun, Hono, Drizzle ORM, and PostgreSQL.
- Host: GitHub
- URL: https://github.com/masmuss/hono-elibrary
- Owner: masmuss
- Created: 2025-06-23T12:31:43.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-07-14T00:59:58.000Z (3 months ago)
- Last Synced: 2025-07-14T02:58:12.463Z (3 months ago)
- Topics: api, biomejs, bun, docker, drizzle-orm, elibrary-project, honojs, postgresql, redis, scalar, typescript, zod
- Language: TypeScript
- Homepage:
- Size: 269 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 📖 E-Library API
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
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
- **Runtime**: [Bun](https://bun.sh/)
- **Web Framework**: [Hono](https://hono.dev/)
- **Database**: [PostgreSQL](https://www.postgresql.org/)
- **ORM**: [Drizzle ORM](https://orm.drizzle.team/)
- **Caching**: [Redis](https://redis.io/)
- **Validation**: [Zod](https://zod.dev/)
- **Containerization**: [Docker](https://www.docker.com/) & Docker Compose
- **Language**: [TypeScript](https://www.typescriptlang.org/)
- **Code Quality**: [Biome](https://biomejs.dev/) (Linter & Formatter) & [Husky](https://typicode.github.io/husky/) (Git Hooks)## 🚀 Getting Started
To run this project in your local environment, you must have **Bun** and **Docker** installed.
### 1. **Clone the Repository**
```bash
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:```bash
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`:
```bash
bun run migrate:generate
```
- To apply migrations manually (optional, as it's automated on startup):
```bash
docker-compose exec app bun run db:migrate
```##
📂 Project Structure
```plaintext
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!