BookBazar is a feature-rich backend API built to power a modern online bookstore. Designed with scalability and modularity in mind, this project replicates a real-world e-commerce backend system where users can register, browse books, manage their cart, place orders, and leave reviews.
The system incorporates robust authentication, role-based authorization, secure payment simulation, image uploads to Cloudinary, and a clean MVC folder structure β making it a great showcase of best practices in backend development with Node.js, Express, and MongoDB.
Whether you're a developer exploring backend architecture or building your own e-commerce solution, BookBazar offers a solid foundation with production-ready patterns.
Server: Node, Express , MongoDB and Mongoose
- Working Backend with full CRUD for books , review , order
- JWT-based user authentication
- API Key generation to access product and order routes
- Middleware for authentication and key verification
- Full Postman collection with testable endpoints and examples
- Razorpay Payment integration
- users
- api_keys
- books
- reviews
- orders
- address
- cart_items
- payment
- JWT Auth required for reviews and orders
- Admin check middleware for book creation/deletion
- API key middleware for accessing /books, /oders , /payments
- Auth + API key (jwt , key generation)
- Book CRUD with admin check
- Reviews & Orders functionality
- Middleware (JWT , API Key , Admin)
- DB structure & relationships
- Postman collection
- Razorpay , cart, email features
GET /api/v1/healthcheck/ POST /api/v1/users/register| Parameter | Type | Description |
|---|---|---|
name |
string |
Required. The name of the user |
email |
string |
Required. The name of the email |
password |
string |
Required. The name of the password |
role |
string |
Required. The name of the role |
GET /api/v1/users/verify/:token| Parameter | Type | Description |
|---|---|---|
token |
string |
Required. The email verification token |
POST /api/v1/users/login| Parameter | Type | Description |
|---|---|---|
email |
string |
Required. The name of the email |
password |
string |
Required. The name of the password |
GET /api/v1/users/resend-mail| Parameter | Type | Description |
|---|---|---|
email |
string |
Required. User's email address |
POST /api/v1/users/refresh-token| Parameter | Type | Description |
|---|---|---|
refreshToken |
string |
Required. The refresh token issued during login |
POST /api/v1/users/forgot-password| Parameter | Type | Description |
|---|---|---|
email |
string |
Required. User's email address |
POST /api/v1/users/change-password| Parameter | Type | Description |
|---|---|---|
oldPassword |
string |
Required. Old Password is required |
newPassword |
string |
Required. New Password is required |
GET /api/v1/users/profile POST /api/v1/users/logout POST /api/v1/book/add-book| Parameter | Type | Description |
|---|---|---|
title |
string |
Required. Title of the book |
description |
string |
Required. Short description about the book |
author |
string |
Required. Author of the book |
price |
number |
Required. Price of the book |
stock |
number |
Required. Quantity available in stock |
image |
file |
Required. Cover image of the book (form-data) |
GET /api/v1/book/ GET /api/v1/book/:bookId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of book |
PATCH /api/v1/book/:bookId| Parameter | Type | Description |
|---|---|---|
bookId |
string |
Required. The ID of the book to be updated |
| Parameter | Type | Description |
|---|---|---|
title |
string |
Optional. Updated title of the book |
description |
string |
Optional. Updated description about the book |
author |
string |
Optional. Updated author name |
price |
number |
Optional. Updated price of the book |
stock |
number |
Optional. Updated stock quantity |
image |
file |
Optional. Updated cover image (form-data) |
DELETE /api/v1/book/:bookId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. bookId is required |
POST /api/v1/cart/add/:bookId| Parameter | Type | Description |
|---|---|---|
bookId |
string |
*Required. ID of the book to add to cart |
quantity |
number |
Optional. Quantity of the book (default: 1) |
GET /api/v1/cart/ DELETE /api/v1/cart/remove/:cartItemId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. cart id is required |
POST /api/v1/order/create| Parameter | Type | Description |
|---|---|---|
items |
array |
Required. Items to include in order |
shippingAddress |
Object |
Required. Address to ship the order |
paymentMethod |
string |
Required. Payment method used |
GET /api/v1/order/user GET /api/v1/order/:orderId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of order |
GET /api/v1/order/ GET /api/v1/order/status/:orderId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of order |
PATCH /api/v1/order/status/:orderId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of item to fetch |
status |
string |
Required. The name of the status |
PATCH /api/v1/order/cancel/:orderId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of order |
POST /api/v1/review/add-review/:bookId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of book |
rating |
number |
Required. rating number |
comment |
string |
Required. comment |
GET /api/v1/review/:bookId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of book |
DELETE /api/v1/review/:reviewId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of review |
POST /api/v1/address/add-address| Parameter | Type | Description |
|---|---|---|
fullName |
string |
Required. Full name of the recipient |
street |
string |
Required. Street address |
city |
string |
Required. City of the recipient |
state |
string |
Required. State of the recipient |
country |
string |
Required. Country of the recipient |
postalCode |
string |
Required. Postal/ZIP code |
phone |
string |
Required. Contact number |
isDefault |
boolean |
Optional. Whether this is the default address |
GET /api/v1/address/ PATCH /api/v1/address/:addressId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of address |
addressId |
string |
Required. Unique ID of the address to update |
fullName |
string |
Optional. Updated full name of the recipient |
street |
string |
Optional. Updated street address |
city |
string |
Optional. Updated city |
state |
string |
Optional. Updated state |
country |
string |
Optional. Updated country |
postalCode |
string |
Optional. Updated postal or ZIP code |
phone |
string |
Optional. Updated phone number |
isDefault |
boolean |
Optional. Set as default address |
DELETE /api/v1/address/remove/:addressId| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of address |
GET /api/v1/admin/site-status GET /api/v1/admin/top-book GET /api/v1/admin/top-users GET /api/v1/admin/daily-orders GET /api/v1/admin/revenue POST /api/v1/payment/initiate| Parameter | Type | Description |
|---|---|---|
amount |
number |
Required. Total payment amount in smallest currency unit (e.g., paise) |
orderId |
string |
Required. ID of the order this payment is for |
method |
string |
Required. Payment method used (e.g., "razorpay") |
providerReferenceId |
string |
Required. Unique reference string from payment provider |
POST /api/v1/payment/verify GET /api/v1/payment/user GET /api/v1/payment/get-all-paymentTo run this project, you will need to add the following environment variables to your .env file
PORT
MONGO_URI
BASE_URL
CORS_ORIGIN
ACCESS_TOKEN_SECRET
ACCESS_TOKEN_EXPIRY
REFRESH_TOKEN_SECRET
REFRESH_TOKEN_EXPIRY
JWT_SECRET
MAILTRAP_SMTP_HOST
MAILTRAP_SMTP_PORT
MAILTRAP_SMTP_USER
MAILTRAP_SMTP_PASS
MAILTRAP_SENDERMAIL
NODE_ENV
CLOUDINARY_CLOUD_NAME
CLOUDINARY_API_KEY
CLOUDINARY_API_SECRET
RAZORPAY_KEY_ID
RAZORPAY_KEY_SECRET
Install my-project with npm
npm install npm install express npm i dotenv npm i express-validator npm i bcryptjs npm i crypto npm i cookie-parser npm i jsonwebtoken npm i mongoose npm i cors npm i mailgen npm i nodemailer npm i multer npm i cloudinary npm i cloudinary-build-url npm i razorpay npm i -D nodemon npm i -D prettierTo run tests, run the following command
npm run startClone the project
git clone https://github.com/i-himanshu29/BookBazar.gitGo to the project directory
cd BookBazarInstall dependencies
npm installStart the server
npm run startBookBazar/
βββ src/
β βββ config/
β β βββ cloudinary.config.js
β β βββ dbconnect.config.js
β β
β
β βββ controllers/
β β βββ auth.controller.js
β β βββ book.controller.js
β β βββ order.controller.js
β β βββ cart.controller.js
β β βββ review.controller.js
β β βββ address.controller.js
β β βββ adminDashboard.controller.js
β β βββ apiKey.controller.js
β β βββ payment.controller.js
β β βββ healthcheck.controller.js
β
β βββ middlewares/
β β βββ auth.middleware.js # verifyJWT, checkAdmin
β β βββ upload.middleware.js # multer config
β β βββ validator.middleware.js
β
β βββ models/
β β βββ user.model.js
β β βββ book.model.js
β β βββ cart.model.js
β β βββ order.model.js
β β βββ review.model.js
β β βββ address.model.js
β β βββ apiKey.model.js
β β βββ payment.model.js
β
β βββ routes/
β β βββ auth.routes.js
β β βββ book.routes.js
β β βββ order.routes.js
β β βββ cart.routes.js
β β βββ review.routes.js
β β βββ address.routes.js
β β βββ admin.routes.js
β β βββ payment.routes.js
β β βββ healthcheck.routes.js
β
β βββ utils/
β β βββ async-handler.util.js
β β βββ api-error.util.js
β β βββ api-response.util.js
β β βββ mal.util.js
β
β βββ validators/
β β βββ auth.validator.js
β β βββ book.validator.js
β β βββ order.validator.js
β β βββ cart.validator.js
β β βββ review.validator.js
β β βββ address.validator.js
β β βββ payment.validator.js
β
β βββ app.js # Express app setup (middlewares, routes)
β βββ server.js # Entry point (connect DB and start server)
β
βββ public/ # for local image storage before upload
βββ .env
βββ .gitignore
βββ package.json
βββ README.md
βββ .prettierrc
βββ .prettierignore
Hello, I'm Himanshu Maurya, a passionate Software Developer who loves building innovative and efficient software.
JavaScript , React.js , Tailwindcss , Next.js , Node.js , Express.js , MongoDB , PostgreSql , Redis , Kafka , Deployment , Docker , WebSocket , Testing , Git/GitHub , AWS , etc.
A heartfelt thank you to Hitesh Choudhary and Piyush Garg sir for their constant inspiration and valuable guidance. Their deep expertise in backend development and continuous support have played a crucial role in shaping this project.