You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A full-stack web application for managing a library's book catalog and member borrowing workflows. Built with React, Node.js, Express.js, and MySQL, featuring role-based access control for Admins and Members.
🚀 Features
👤 Member
Register and log in with hashed password authentication (bcrypt)
Browse and search the full book catalog (by title, author, ISBN, category, or rack number)
View detailed book information including cover image
Submit borrowing requests for available books
Track personal borrowed books dashboard
🛡️ Admin
Approve or reject member borrowing requests
Add new books with cover image upload
Edit existing book details (automatically replaces old cover image)
Delete books (automatically removes associated image from server)
git clone https://github.com/shehabgamaleldeen/Library.git
cd Library
2. Set up the database
Create a MySQL database and import the schema from /database
Update the connection config in server/Database/connection.js
3. Start the backend
cd server
npm install
npm start
# Server runs on http://localhost:4000
4. Start the frontend
cd client
npm install
npm start
# App runs on http://localhost:3000
🔐 Role System
Role
role_id
Capabilities
Admin
1
Full access — manage books, approve/reject requests, view all users
Member
2
Browse catalog, submit borrow requests, view own borrowed books
Pending
3
Registered but awaiting admin account approval
New registrations are assigned role_id: 3 by default. An admin must manually promote the account to role_id: 2 before the member can log in.
📁 Key Implementation Details
Image Management: Multer handles book cover uploads; when a book is updated or deleted, the old image file is automatically removed from the server using fs.unlinkSync.
Query Abstraction: All database interactions are encapsulated in dedicated query modules per entity (queries.books.js, queries.user.js, queries.borrowingRequest.js), keeping routes clean and maintainable.
Route Protection: Two custom Express middleware functions (Admin.js, authorize.js) validate the request token against the database and check the user's role_id before allowing access to protected routes.
Input Validation: Every POST and PUT endpoint uses express-validator to validate and sanitize request body fields before any database operation.