A simple, Dockerized REST API for managing books, borrowers, and borrowings.
- CRUD for Books and Borrowers
- Borrow/Return books with due dates and stock updates
- List borrower's current books
- Overdue listing
- Search by title/author/isbn
- Basic Auth (configurable via env)
- Rate limiting on two sensitive endpoints
- Export CSV reports (last month's overdue and borrowings)
- Dockerfile + docker-compose
- Auto DB sync on startup
cp .env.example .env
docker-compose up --buildAPI base: http://localhost:3000
Default Basic Auth:
user: admin
pass: admin123
Configure via
.env.
POST /books(rate limited) — createGET /books— listGET /books/search?title=&author=&isbn=— search any combinationPUT /books/:id— updateDELETE /books/:id— delete
POST /borrowers— createGET /borrowers— listPUT /borrowers/:id— updateDELETE /borrowers/:id— deleteGET /borrowers/:id/books— list books currently borrowed by borrower
POST /borrowings(rate limited) — borrow a book{ borrowerId, bookId, dueDate? }POST /borrowings/:id/return— return bookGET /borrowings/overdue— list overdue borrowingsGET /borrowings— list all borrowings
GET /reports/last-month/borrowings.csvGET /reports/last-month/overdue.csv
All endpoints require Basic Auth.
- books
- id, title, author, isbn (unique), quantity, shelf_location, createdAt, updatedAt
- borrowers
- id, name, email (unique), registered_date, createdAt, updatedAt
- borrowings
- id, borrower_id (FK), book_id (FK), borrowed_date, due_date, returned_date (nullable), status ('borrowed'|'returned'), createdAt, updatedAt
See scripts/schema.sql for a SQL version.
- Open Postman.
- Go to File → Import.
- Select:
postman/Library-Management.postman_collection.json
The Postman collection postman/Library-Management.postman_collection.json already includes a base-URL variable:
"variable": [
{
"key": "base-URL",
"value": "http://localhost:3000"
}
]👉 If you are running the API locally or on another server, update this value:
- Local development(default)
"value": "http://localhost:3000"- GitHub Codespaces for setup the codespaces go to the next section Run in GitHub Codespaces
"value": "https://<your-port>-<username>-<id>.app.github.dev"- Production server
"value": "https://your-production-domain.com"You can edit it in two ways:
- Directly in the JSON file before importing to Postman.
- Inside Postman → Open the collection → View Variables → change
base-URL.
You can run this project directly in GitHub Codespaces without installing dependencies locally.
- Navigate to the repository on GitHub via
https://github.com/BassamRamadan/Library-Management-System. - Click the green Code button → Open with Codespaces → New codespace.
Inside the Codespace terminal, run:
cp .env.example .env
docker-compose up --build
- Find the port your app is running on (e.g.
3000) in the Ports tab via vscode for example. - Right-click the port → Change Port Visibility → select Public.
- GitHub will generate a public URL like:
https://jubilant-acorn-rrwp7959gp4259j7.github.dev/ - Use this URL as your
base-URLin Postman.
- Auto-creates and syncs tables on startup.
BORROW_DAYSenv controls default loan duration (days) ifdueDatenot provided.- Rate limiting applied to
POST /booksandPOST /borrowings.