A robust, production-ready RESTful API backend for the Intelligent Library Management System (ILMS), built with Node.js, Express, and MongoDB. This system manages books, users, borrowing transactions, and provides AI-powered recommendations and dashboard analytics.
-
Authentication & Authorization
- Secure JWT-based authentication
- Role-based access control (Admin vs. Student)
- Password hashing with bcrypt
-
Book Management
- Complete CRUD operations
- Advanced search (Title, Author, ISBN)
- Filtering by genre and sorting
- Pagination support
-
Transaction System
- Borrow and return workflows
- Automatic due date calculation
- Availability tracking
- Duplicate borrow prevention
-
AI Recommendations
- Personalized book suggestions based on borrowing history
- Heuristic-based matching algorithm
-
Dashboard Analytics
- Real-time statistics for administrators
- User and book metrics
-
Security & Reliability
- Helmet for secure HTTP headers
- CORS configuration
- Rate limiting ready
- Global error handling
- MongoDB connection retry logic
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB (Atlas or Local) with Mongoose ODM
- Authentication: JSON Web Tokens (JWT)
- Security: bcryptjs, helmet, cors
- Logging: Morgan (dev mode)
- Node.js (v18+)
- MongoDB (Local or Atlas connection string)
-
Clone the repository
git clone <repository-url> cd ILMS-backend
-
Install dependencies
npm install
-
Configure Environment Create a
.envfile in the root directory:PORT=8000 MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_secure_secret_key JWT_EXPIRES_IN=7d FRONTEND_URL=http://localhost:5173 NODE_ENV=development
-
Seed the Database (Optional) Populate the database with initial admin/student users and sample books:
npm run seed
Creates:
- Admin:
admin@library.com/password123 - Student:
user@library.com/password123
- Admin:
-
Start the Server
# Development (with auto-reload) npm run dev # Production npm start
| Method | Endpoint | Description | Access |
|---|---|---|---|
| POST | /api/auth/register |
Register a new user | Public |
| POST | /api/auth/login |
Login and receive JWT | Public |
| GET | /api/auth/me |
Get current user profile | Private |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/books |
List books (pagination, search, filter) | Public |
| GET | /api/books/:id |
Get book details | Public |
| POST | /api/books |
Create a new book | Admin |
| PUT | /api/books/:id |
Update a book | Admin |
| DELETE | /api/books/:id |
Remove a book | Admin |
Query Parameters: page, limit, search, genre, sortBy, order
| Method | Endpoint | Description | Access |
|---|---|---|---|
| POST | /api/transactions/borrow |
Borrow a book | Private |
| POST | /api/transactions/return/:id |
Return a borrowed book | Private |
| GET | /api/transactions/my |
Get user's history | Private |
| GET | /api/transactions |
Get all transactions | Admin |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/recommendations |
Get personalized suggestions | Private |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/stats |
Get system analytics | Admin |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/health |
Server health check | Public |
src/
├── config/ # Database configuration
├── controllers/ # Request handlers (logic)
├── middleware/ # Auth, error handling, validation
├── models/ # Mongoose schemas
├── routes/ # API route definitions
├── utils/ # Helpers and seeder script
└── app.js # Express app setup
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License.