An open API service indexing awesome lists of open source software.

https://github.com/developermonirbd/library_management_api

A Library Management System built with Express, TypeScript, and MongoDB, enabling book creation, borrowing, filtering, and reporting.
https://github.com/developermonirbd/library_management_api

eslint mongo mongoo node postman prettier type

Last synced: about 2 months ago
JSON representation

A Library Management System built with Express, TypeScript, and MongoDB, enabling book creation, borrowing, filtering, and reporting.

Awesome Lists containing this project

README

          

## ๐Ÿ“š Library Management API

A Library Management System built with Express, TypeScript, and MongoDB, enabling book creation, borrowing, filtering, and reporting.

## ๐Ÿš€ Live URL

[๐Ÿ”—](https://library-management-api-a4.vercel.app/)

## ๐Ÿ“ฆ Features

- โœ… Book CRUD operations with schema validation
- โœ… Genre filtering & sorting support
- โœ… Borrowing books with availability enforcement
- โœ… Aggregation pipeline for summary reports
- โœ… Global error handling (including validation & 404)
- โœ… Uses Mongoose middleware & static/instance methods

## ๐Ÿง‘โ€๐Ÿ’ป Tech Stack

- Node.js + Express.js
- TypeScript
- MongoDB + Mongoose
- ESLint, Prettier
- Postman (for API testing)

## ๐Ÿ› ๏ธ Installation & Setup

```Bash
git clone https://github.com/your-username/library-management-api.git
cd library-management-api
npm install
```

## ๐ŸŒ Create `.env` File

```Bash
PORT=5000
DATABASE_URL=your_mongodb_connection_string
```

## ๐Ÿ”ง Run Locally

```Bash
npm run dev
```

## ๐Ÿงช API Endpoints

### ๐Ÿ“˜ Books

| Method | Endpoint | Description |
| ------ | -------------- | --------------------------- |
| POST | /create-book | Create a book |
| GET | /books | Get all books (filter/sort) |
| GET | /books/:id | Get book by ID |
| PUT | /edit-book/:id | Update book |
| DELETE | /books/:id | Delete book |

## Filtering Example

```Http
GET /books?filter=FANTASY&sortBy=createdAt&sort=desc&limit=5
```

## ๐Ÿ“™ Borrow

| Method | Endpoint | Description |
| ------ | --------------- | ---------------------------------------------- |
| POST | /borrow/:bookId | Borrow a book (quantity check + update copies) |
| GET | /borrow-summary | Borrowed books summary (aggregation) |

## ๐Ÿงฉ Business Logic Highlights

- โœ… Borrow operation ensures book has enough copies
- โœ… available status is updated via Mongoose static method
- โœ… Uses aggregation pipeline to summarize total borrows
- โœ… Mongoose middleware handles createdAt & updatedAt

## โš ๏ธ Error Handling Example

```Json
{
"message": "Validation failed",
"success": false,
"error": {
"name": "ValidationError",
"errors": {
"copies": {
"message": "Copies must be a positive number",
"kind": "min",
"value": -5
}
}
}
}
```

## What to Submit

- [Public Github Repo Link ] (https://github.com/DeveloperMonirBD/library_management_api)
- [Live Deployment Link] (https://library-management-api-a4.vercel.app/)
- [Video Explanation (Public Link)] ()

## ๐Ÿ™Œ Author

Md. Monirul Islam