This project is a backend API for managing a library system. It supports book catalog management, inventory tracking, borrowing and returning books, and automatic customer reputation scoring.
Built using NestJS, Prisma ORM, and PostgreSQL.
Make sure you have the following installed:
- Node.js (v18 or later)
- npm
- PostgreSQL
- Git
git clone https://github.com/your-username/libmanage-backend.git cd libmanage-backend
npm install
DATABASE_URL="postgresql://USERNAME:PASSWORD@localhost:5432/libmanage?schema=public"
npx prisma generate npx prisma migrate dev
npm run start:dev
The application is divided into the following main modules:
-
Catalog Module
Responsible for managing book-related information such as titles, genres, language, ISBN, and authors. It handles searching, filtering, pagination, and soft deletion of books. -
Inventory Module
Manages physical book copies, including their availability status (e.g., AVAILABLE, LOANED, DAMAGED). This module tracks multiple copies of the same book and supports soft deletion and status updates. -
Circulation Module
Handles borrowing and returning of books. It coordinates updates across multiple resources (loans, book copies, and customers) using database transactions to ensure consistency. -
Reputation Module
Calculates and applies customer reputation score changes automatically based on borrowing behavior. Scores are adjusted when a book is returned early, on time, or late, preventing manual manipulation from the client.
Prisma ORM is used to provide type-safe database access and transaction management. Critical operations such as borrowing and returning books are executed within transactions to guarantee data integrity.
Soft deletes are implemented using deletedAt fields. This approach preserves historical data while preventing permanently removed records from appearing in active queries.
The system follows clean RESTful API principles:
- URLs identify resources (domain concepts)
- HTTP methods describe actions
- Controllers handle routing only
- Business logic is encapsulated within services
This design ensures the backend is maintainable, scalable, and aligned with real-world library workflows.