This Library Management System Server is a robust backend API developed using Express, designed to facilitate comprehensive management of library operations. It supports a wide range of features from user authentication and book management to permission controls and user profile management. The system ensures data integrity and security using bearer token authentication, making it ideal for educational institutions, public libraries, and private collections.
- FEATURES
- PREREQUISITES
- SETUP
- RUNNING THE SCRIPT
- ERROR HANDLING
- HOSTING
- USED PACKAGES
- TOOLS
- ARTICLES
- DO NOT FORGET TO DO
- TUTORIALS
- INSPIRATIONS
- CONTRIBUTE
- CONTRIBUTORS
- SPECIAL THANKS
- LICENSE
- CONTACT
-
Authentication:
- Handles user login, logout, password resets, and email verification processes.
- Ensures secure access through bearer token authentication.
-
Book Management:
- Provides functionality to create, retrieve, update, and delete book records.
- Includes endpoints for managing book images, fetching trending books, and maintaining user-specific book favorites and histories.
-
User Profile Management:
- Facilitates fetching and updating user profile information based on username. Respects privacy settings and only returns allowed information.
-
Permission and Role Management:
- Manages permissions and roles within the system, allowing for the creation of new roles, modification of existing ones, and deletion of roles based on IDs.
-
Subject Management:
- Allows for the creation, deletion, and retrieval of subjects, providing administrative control over subject-related data.
-
Error and Request Handling:
- Includes comprehensive handling of unsupported methods and detailed error responses to ensure robustness and reliability of the API.
- User
- Auth
- Signup:
POST /api/{{VERSION}}/auth/signup
- Verify signup using email:
GET /api/{{VERSION}}/auth/verify/verification-token
- Login:
POST /api/{{VERSION}}/auth/login
- Request password reset email:
PUT /api/{{VERSION}}/auth/request-new-password
- Resend password reset email:
PUT /api/{{VERSION}}/auth/resend-verification/verification-token
- Reset password:
PUT /api/{{VERSION}}/auth/reset-password/verification-token
- Logout:
GET /api/{{VERSION}}/auth/logout
- Signup:
- Profile
- Update personal information:
- Reset password:
- Delete account:
- Request
- Request a book:
POST /api/{{VERSION}}/books/request
- Cancel a requested book:
- Get all requested books:
- Request a book:
- Favorite books
- Add a book to favorite:
POST /api/{{VERSION}}/books/favourite/book-id
- Remove a book from favorite:
GET /api/{{VERSION}}/books/favourite
- Get all favorite books:
DELETE /api/{{VERSION}}/books/favourite/book-id
- Add a book to favorite:
- Recently visited
- Add a book to recently visited:
- Get all recently visited books:
- Auth
- Admin
- Admin
- Create admin:
POST /api/{{VERSION}}/admin
- Verify admin request using email:
GET /api/{{VERSION}}/admin/verify/verification-token
- Admin Login:
/api/{{VERSION}}/admin/login
- Request password reset email:
PUT /api/{{VERSION}}/admin/request-new-password
- Resend password reset email:
GET /api/{{VERSION}}/admin/resend-verification/token-id
- Reset password:
PUT /api/{{VERSION}}/admin/reset-password/verification-token
- Logout:
GET /api/{{VERSION}}/admin/logout
- Create admin:
- Permission
- Create permission:
POST /api/{{VERSION}}/permissions
- Create default permission:
POST /api/{{VERSION}}/permissions/default
- Get all permissions:
GET /api/{{VERSION}}/permissions
- Get permission by ID:
GET /api/{{VERSION}}/permissions/permission-id
- Update permission by ID:
PUT /api/{{VERSION}}/permissions/permission-id
- Delete permission by ID:
DELETE /api/{{VERSION}}/permissions/permission-id
- Delete permission by list:
DELETE /api/{{VERSION}}/permissions?ids=permission-id1,permission-id2
- Create permission:
- Role
- Create role:
POST /api/{{VERSION}}/roles
- Create default role:
POST /api/{{VERSION}}/roles/default
- Get all roles:
GET /api/{{VERSION}}/roles
- Get role by ID:
GET /api/{{VERSION}}/roles/role-id
- Update role by ID:
PUT /api/{{VERSION}}/roles/role-id
- Delete role by ID:
DELETE /api/{{VERSION}}/roles/role-id
- Delete role by list:
DELETE /api/{{VERSION}}/roles?ids=role-id1,role-id2
- Create role:
- Books
- Add a new book:
POST /api/{{VERSION}}/books
- Update a book by ID:
PUT /api/{{VERSION}}/books/66ab542eb599109705f946ee
- Delete a book by ID:
DELETE /api/{{VERSION}}/books/book-id
- Delete book by list:
DELETE /api/{{VERSION}}/roles?ids=role-id1,role-id2
- Add a new book:
- Publication
- Add a publication
- Get all publications
- Update a publication
- Delete a publication
- Writer
- Add a writer
- Get all writers
- Update a writer
- Delete a writer
- Subjects
- Add a subject
- Get all subjects
- Update a subject
- Delete a subject
- Lend
- Lend a book to user:
POST /api/{{VERSION}}/books/lend
- Get all lend books:
GET /api/{{VERSION}}/books/lend
- Lend a book to user:
- Return
- Return books to library:
DELETE /api/{{VERSION}}/books/return
- Return books to library:
- History
- Get all lend history
- Get lend history by book id
- Desired books
- Get all desired books
- Requested books
- Get all requested books:
GET /api/{{VERSION}}/books/request
- Get requested book by book ID:
GET /api/{{VERSION}}/books/request/requested-book-id
- Get requested book by requester ID:
GET /api/{{VERSION}}/books/request/owner/owner-id
- Get all requested books:
- Admin
- Public
- Books
- Get all books:
GET /api/{{VERSION}}/books
- Get book by id:
GET /api/{{VERSION}}/books/book-id
- Get all books:
- Desired books
- Get all books:
GET /api/{{VERSION}}/books/desired
- Get all books:
- Books history
- Get all books history:
GET /api/{{VERSION}}/books/history
- Get book history by book ID:
GET /api/{{VERSION}}/books/history/book-id
- Get all books history:
- Detect
- User device detection
- Desired books
- Get all desired books
- Trending books
- Get all trending books
- Books
- Node.js (v20.x or higher)
- Yarn (v1.22.x or higher)
Ensure you have Node.js
and Yarn
installed by running node -v
and yarn -v
in your terminal. These commands will display the current version of each installed on your system. If these are not installed, follow the installation instructions on the Node.js website and the Yarn website.
-
Clone the repository and navigate to the directory:
git clone https://github.com/montasim/library-management-system-server.git cd library-management-system-server
-
Install the dependencies:
yarn install
-
Configuring the Environment:
Create a
.env.development
or.env.staging
or.env.production
file in the root directory of the project and populate it with the necessary environment variables. See the .env.example file for an example.
-
Build the Docker Compose Services:
docker-compose -f docker-compose-development.yml build
-
Run the Docker Compose Services:
docker-compose -f docker-compose-development.yml up
-
Stop the Containers:
docker-compose -f docker-compose-development.yml down
-
Rebuild the Containers:
docker-compose -f docker-compose-development.yml up --build
-
Running the Application:
To start the application in development mode, use:
yarn dev
This will run the server with nodemon, automatically restarting when any changes are made.
-
To build and run the application in production mode, use:
yarn start
This will build the application and start the server using the built files.
This script first builds the project by linting the code, fixing lint issues, running prettier, and then starts the application with pm2.
-
Testing:
To run the tests configured with Jest, use:
yarn test
This will build the project and then run all the Jest tests.
-
Linting and Code Formatting:
-
To check for linting errors:
yarn lint:check
-
To fix linting errors:
yarn lint:fix
-
To check if files are formatted correctly:
yarn prettier:check
-
To format files:
yarn prettier:fix
-
-
Generating Documentation:
To generate code documentation with JSDoc, run:
yarn generate-docs
This will create documentation based on your JSDoc comments.
-
Release Management:
To create a new release, you can use:
yarn release
This will automatically bump the version, update the CHANGELOG, and create a commit and a tag.
For minor or major releases:
yarn release:minor yarn release:major
-
Cleanup:
To clean up dependencies and rebuild the project:
yarn clean
This command initializes the auto cleanup process and then forces a rebuild.
Step-by-step guide on setting up your own Vercel instance:
Vercel is the recommended option for hosting the files since it is free and easy to set up.
- Go to vercel.com.
- Click on
Log in
. - Sign in with GitHub by pressing
Continue with GitHub
. - Sign in to GitHub and allow access to all repositories if prompted.
- Fork this repo.
- Go back to your Vercel dashboard.
- To import a project, click the
Add New...
button and select theProject
option. - Click the
Continue with GitHub
button, search for the required Git Repository and import it by clicking theImport
button. Alternatively, you can import a Third-Party Git Repository using theImport Third-Party Git Repository ->
link at the bottom of the page. - Create a personal access token (PAT) here and enable the
repo
anduser
permissions (this allows access to see private repo and user stats). - Copy all the .env.development file as environment variables in the Vercel dashboard.
- Click deploy, and you're good to go. See your domains to use the API!
List of used packages:
Node.js (v20.x or higher)
: The runtime environment for executing JavaScript on the server side.Express.js (v4.19.x or higher)
: The web application framework for creating server-side logic.MongoDB (v6.8.x or higher)
: The NoSQL database for storing and retrieving data.@googleapis/drive (v8.11.0)
: A library for interacting with Google Drive API.bcrypt (v5.1.1)
: A library to help you hash passwords.compression (v1.7.4)
: Middleware to compress response bodies for all requests.cors (v2.8.5)
: Middleware to enable Cross-Origin Resource Sharing.dompurify (v3.1.5)
: A library to sanitize HTML to prevent XSS attacks.dotenv (v16.4.5)
: A module to load environment variables from a .env file.express-useragent (v1.0.15)
: A user agent middleware for Express.glob (v10.4.2)
: A library to match files using the patterns the shell uses.helmet (v7.1.0)
: Middleware to secure Express apps by setting various HTTP headers.hpp (v0.2.3)
: Middleware to protect against HTTP Parameter Pollution attacks.jest (v29.7.0)
: A testing framework for JavaScript.joi (v17.13.3)
: A library for data validation.jsdom (v24.1.0)
: A library to simulate a web browser environment in Node.js.jsonwebtoken (v9.0.2)
: A library to sign, verify, and decode JSON Web Tokens.moment (v2.30.1)
: A library for parsing, validating, manipulating, and formatting dates.mongodb (v6.8.0)
: MongoDB driver for Node.js.mongoose (v8.4.4)
: An ODM (Object Data Modeling) library for MongoDB and Node.js.morgan (v1.10.0)
: HTTP request logger middleware for Node.js.multer (v1.4.5-lts.1)
: Middleware for handling multipart/form-data, used for file uploads.node-cache (v5.1.2)
: A caching library for Node.js.nodemailer (v6.9.14)
: A module for sending emails.pm2 (v5.4.1)
: A production process manager for Node.js applications.request-ip (v3.3.0)
: A library to retrieve a request's IP address.supertest (v7.0.0)
: A library for testing HTTP assertions.terser (v5.31.1)
: A JavaScript parser, mangler, and compressor toolkit for ES6+.uuid (v10.0.0)
: A library to generate RFC4122 UUIDs.winston (v3.13.0)
: A logging library for Node.js.winston-daily-rotate-file (v5.0.0)
: Transport for winston to log to daily rotated files.winston-mongodb (v5.1.1)
: Transport for winston to log to a MongoDB collection.
@babel/core (v7.24.7)
: The core of Babel, a JavaScript compiler.@babel/preset-env (v7.24.7)
: A Babel preset to compile ES6+ down to ES5.eslint (v9.5.0)
: A tool for identifying and reporting on patterns in JavaScript.jsdoc (v4.0.3)
: A tool for generating documentation from JavaScript source code.nodemon (v3.1.4)
: A utility that will monitor for any changes in your source and automatically restart your server.prettier (v3.3.2)
: An opinionated code formatter.standard-version (v9.5.0)
: A utility for versioning and changelog management.
Contributions are always welcome! Please read the contribution guidelines first.