This is a scalable, microservice-based backend for an e-commerce platform, powered by PostgreSQL as the database. It includes essential services like user authentication, product management, shopping cart, favorites, orders, and checkout. The microservice architecture ensures each feature is modular and can be easily updated or scaled as the business grows. This design allows for smooth integration, flexibility, and easy maintenance in the long run.
To set up and run this e-commerce backend locally, follow the steps below:
- Docker: Make sure Docker is installed on your system.
- npm: If you're working in a development environment, ensure you have npm installed.
Execute the following commands in your terminal
git clone https://github.com/anshifmonz/bazaar-bloom.git
cd bazaar-bloom
mv .env.example .env
docker-compose upNote: Update the .env file to set appropriate values for sensitive information such as DB credentials, Session Secret, etc.
Execute the following commands in your terminal
git clone https://github.com/anshifmonz/bazaar-bloom.git
cd bazaar-bloom
mv .env.example .env
docker-compose -f docker-compose.test.yml upExecute the following command in your terminal
git clone https://github.com/anshifmonz/bazaar-bloom.git
cd bazaar-bloom
mv .env.example .env
# Install dependencies for each service
dirs=('auth' 'cart' 'checkout' 'favorite' 'order' 'product' 'server')
for dir in "${dirs[@]}"; do
if [ -d "$dir" ]; then
echo "Installing dependencies in $dir"
cd $dir && npm install && cd ..
fi
done
docker-compose -f docker-compose.dev.yml upOnce the server is up, you can access it at http://localhost:3000.
GET /api/<service>
This endpoint acts as a proxy gateway, forwarding requests to various microservices in the system. Each service handles a specific functionality such as authentication, cart management, product data, favorites, orders, and checkout.
The request is routed to different services based on the path prefix:
/api/auth→ Routes to the User Service/api/cart→ Routes to the Cart Service/api/product→ Routes to the Product Service/api/favorite→ Routes to the Favorite Service/api/order→ Routes to the Order Service/api/checkout→ Routes to the Checkout Service
cURL Command:
To call the Authentication Service:
curl -X GET "http://localhost:9999/api/auth/someAuthEndpoint"To call the Cart Service:
curl -X GET "http://localhost:9999/api/cart/someCartEndpoint" \
-H "Cookie: connect.sid=<your-session-id>"POST /api/auth/signUp
Register a new user.
Headers:
Content-Type: application/json
Body: (JSON)
{
"name": "string",
"email": "string",
"password": "string"
}Success Response:
- Status Code:
201 Created - Body:
{ "success": true, "message": "User created" }
Error Response:
- Status Code:
500 Bad Request - Body:
{ "message": "Server error" }
cURL Command:
curl -X POST http://localhost:3000/api/auth/signUp \
-H "Content-Type: application/json" \
-d '{
"name": "johndoe",
"email": "johndoe@example.com",
"password": "securepassword"
}'POST /api/auth/logIn
Login a user.
Headers:
Content-Type: application/json
Body: (JSON)
{
"email": "string",
"password": "string"
}Success Response:
-
Status Code:
200 OK -
Body:
{ "message": "LogIn Successful" } -
Status Code:
404 Not Found -
Body:
{ "message": "Email or password is incorrect" }
Error Response:
- Status Code:
500 Internal Server Error - Body:
{ "message": "Server error" }
cURL Command:
curl -X POST http://localhost:3000/api/auth/logIn \
-H "Content-Type: application/json" \
-d '{
"email": "johndoe@example.com",
"password": "securepassword"
}'POST /api/auth/logOut
Logout a user.
Headers:
Content-Type: application/jsonCookie: connect.sid=<your-session-id>
Parameters
No additional query or body parameters are required.
Success Response:
- Status Code:
200 OK - Body:
{ "success": true, "message": "logOut successful" }
Error Response:
- Status Code:
500 Internal Server Error - Body:
{ "message": "Server error" }
cURL Command:
curl -X POST http://localhost:3000/api/auth/logOut \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>"GET /api/product/
This endpoint retrieves a list of products from the database based on user-specified filters like search terms, category, price range, and sorting options.
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
search |
string |
No | Search term to match product names or descriptions. |
category |
string |
No | Filter products by their category. |
minPrice |
number |
No | Minimum price of products. |
maxPrice |
number |
No | Maximum price of products. |
sort |
string |
No | Sort order of results. Possible values: price_asc, price_desc. |
Success Response:
- Status Code:
200 OK - Body:
{ "success": true, "data": [ { "id": 1, "name": "Product Name", "description": "Product Description", "category": "Category Name", "price": 100.0 }, { "id": 2, "name": "Another Product", "description": "Another Description", "category": "Another Category", "price": 200.0 } ] }
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
cURL Command:
curl -X GET "http://localhost:3000/api/products?search=laptop&category=electronics&minPrice=500&maxPrice=2000&sort=price_asc"POST /api/product/
This endpoint allows you to add a new product to the database. It validates the input to ensure the price and stock fields are valid numbers.
Headers:
Cookie: connect.sid=<your-session-id>
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | The name of the product. |
description |
string |
Yes | A brief description of the product. |
price |
number |
Yes | The price of the product. Must be a positive number or decimal value. |
stock |
number |
Yes | The quantity of the product in stock. Must be a positive integer. |
category |
string |
Yes | The category to which the product belongs. |
img_url |
string |
No | A URL pointing to the product's image. |
Success Response:
- Status Code:
200 OK - Body:
{ "success": true }
Error Response:
- Status Code:
400 Bad Request - Body:
{ "success": false, "message": "Invalid input" } - Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
cURL Command:
curl -X POST "http://localhost:3000/api/products" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>" \
-d '{
"name": "Laptop",
"description": "A high-performance laptop for professionals.",
"price": 1500.99,
"stock": 10,
"category": "Electronics",
"img_url": "http://localhost:3000/images/laptop.jpg"
}'PUT /api/product/
This endpoint allows you to update the details of an existing product in the database. It validates the presence of a productId and dynamically constructs the update query based on the fields provided in the request body.
Headers:
Cookie: connect.sid=<your-session-id>
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
productId |
string |
Yes | The unique identifier of the product to be updated. |
name |
string |
No | The updated name of the product. |
description |
string |
No | The updated description of the product. |
price |
number |
No | The updated price of the product. Must be a positive number or decimal. |
stock |
number |
No | The updated stock quantity of the product. Must be a positive integer. |
category |
string |
No | The updated category of the product. |
img_url |
string |
No | The updated URL pointing to the product's image. |
Success Response:
- Status Code:
200 OK - Body:
{ "success": true }
Error Response:
- Status Code:
400 Bad Request - Body:
{ "success": false, "message": "Product id required" } - Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
cURL Command:
curl -X PUT "http://localhost:3000/api/product" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>" \
-d '{
"productId": "12345",
"name": "Updated Name",
"description": "An updated description.",
"price": 1600.99,
"stock": 15,
"category": "Electronics",
"img_url": "http://localhost:3000/images/updated-product.jpg"
}'DELETE /api/product/
This endpoint allows you to delete one or more products from the database by specifying their IDs in the request body.
Headers:
Cookie: connect.sid=<your-session-id>
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
productId |
string |
Yes | A comma-separated string of product IDs to delete. Each ID must be valid. |
Success Response:
- Status Code:
200 OK - Body:
{ "success": true }
Error Response:
- Status Code:
400 Bad Request- Body:
{ "success": false, "message": "Invalid input" }
- Body:
- Status Code:
500 Internal Server Error- Body:
{ "success": false, "message": "Server error" }
- Body:
cURL Command:
curl -X DELETE "http://localhost:3000/api/products" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>" \
-d '{
"productId": "12345,67890"
}'GET /api/cart/
This endpoint retrieves the cart details for the authenticated user, including the items currently in the user's cart. Authentication is managed via session-based login using Passport.js.
Headers:
Cookie: connect.sid=<your-session-id>
Parameters
No additional query or body parameters are required.
Success Response:
- Status Code:
200 OK - Body:
{ "success": true, "data": [ { "id": 1, "productId": "12345", "name": "Product Name", "quantity": 2, "price": 50.0 }, { "id": 2, "productId": "67890", "name": "Another Product", "quantity": 1, "price": 150.0 } ] }
Error Response:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
cURL Command:
curl -X GET "http://localhost:3000/api/cart" \
-H "Cookie: connect.sid=<your-session-id>"POST /api/cart/
This endpoint adds a new item to the authenticated user's cart. The item is validated to ensure it exists and is not already present in the cart.
Headers
Cookie: connect.sid=<your-session-id>
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
productId |
string |
Yes | The ID of the product to add to the cart. |
Validation:
- The
productIdmust be a numeric string.
Success Response:
- Status Code:
200 OK - Body:
{ "success": true }
Error Responses:
-
Invalid Input:
- Status Code:
400 Bad Request - Body:
{ "success": false, "message": "Invalid input" }
- Status Code:
-
Product Does Not Exist:
- Status Code:
409 Conflict - Body:
{ "success": false, "message": "Product doesn't exist" }
- Status Code:
-
Cart Item Already Exists:
- Status Code:
409 Conflict - Body:
{ "success": false, "message": "Cart item already exist" }
- Status Code:
-
Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
- Status Code:
cURL Command:
curl -X POST "http://localhost:3000/api/cart" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>" \
-d '{
"productId": "12345"
}'PATCH /api/cart/
This endpoint updates the quantity of an item in the authenticated user's cart.
Headers:
Cookie: connect.sid=<your-session-id>
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
cartItemId |
string |
Yes | The ID of the cart item to update. |
quantity |
string |
Yes | The new quantity of the cart item. |
Validation:
- Both
cartItemIdandquantitymust be numeric strings.
Success Response:
- Status Code:
200 OK - Body:
{ "success": true }
Error Responses:
-
Invalid Input:
- Status Code:
400 Bad Request - Body:
{ "success": false, "message": "Invalid input" }
- Status Code:
-
Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
- Status Code:
cURL Command:
curl -X PATCH "http://localhost:3000/api/cart" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>" \
-d '{
"cartItemId": "67890",
"quantity": "3"
}'DELETE /api/cart/
This endpoint removes a specific item from the authenticated user's cart.
Headers:
Cookie: connect.sid=<your-session-id>
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
cartItemId |
string |
Yes | The ID of the cart item to remove. |
Validation:
cartItemIdmust be a numeric string.
Success Response:
- Status Code:
200 OK - Body:
{ "success": true }
Error Responses:
-
Invalid Input:
- Status Code:
400 Bad Request - Body:
{ "success": false, "message": "Invalid input" }
- Status Code:
-
Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
- Status Code:
cURL Command:
curl -X DELETE "http://localhost:3000/api/cart" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>" \
-d '{
"cartItemId": "12345"
}'GET /api/favorite/
This endpoint retrieves a list of products that are marked as favorites by the authenticated user.
Headers:
Cookie: connect.sid=<your-session-id>
Parameters
No additional query or body parameters are required.
Success Response:
- Status Code:
200 OK - Body:
{ "success": true, "data": [ { "id": 1, "product_id": 1, "name": "Product Name", "description": "Product Description", "category": "Category Name", "price": 100.0, "img_url": "http://localhost:3000/product-image.jpg" }, { "id": 2, "product_id": 2, "name": "Another Product", "description": "Another Description", "category": "Another Category", "price": 200.0, "img_url": "http://localhost:3000/another-product-image.jpg" } ] }
Error Response:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
cURL Command:
curl -X GET "http://localhost:3000/api/favorites" \
-H "Cookie: connect.sid=<your-session-id>"POST /api/favorite/
This endpoint allows an authenticated user to add a product to their list of favorite products.
Headers:
Content-Type: application/jsonCookie: connect.sid=<your-session-id>
Body Parameter
| Parameter | Type | Required | Description |
|---|---|---|---|
productId |
number |
Yes | The ID of the product to add to the favorites. |
Success Response:
- Status Code:
200 OK - Body:
{ "success": true }
Error Responses:
-
Invalid Input:
- Status Code:
400 Bad Request - Body:
{ "success": false, "message": "Invalid input" }
- Status Code:
-
Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
- Status Code:
cURL Command:
curl -X POST "http://localhost:3000/api/favorites" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>" \
-d '{"productId": 123}'DELETE /api/favorite/
This endpoint removes a specific product from the authenticated user's list of favorite products.
Headers:
Content-Type: application/jsonCookie: connect.sid=<your-session-id>
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
favId |
string |
Yes | The ID of the favorite product to remove. |
Validation:
favIdmust be a numeric string.
Success Response:
- Status Code:
200 OK - Body:
{ "success": true }
Error Responses:
-
Invalid Input:
- Status Code:
400 Bad Request - Body:
{ "success": false, "message": "Invalid input" }
- Status Code:
-
Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
- Status Code:
cURL Command:
curl -X DELETE "http://localhost:3000/api/favorite" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>" \
-d '{
"favId": "12345"
}'GET /api/order/
This endpoint retrieves all orders for the authenticated user.
Headers:
Content-Type: application/jsonCookie: connect.sid=<your-session-id>
Parameters:
- None
Success Response:
- Status Code:
200 OK - Body:
{ "success": true, "data": [ { "id": "123", "product_id": "456", "name": "Product name", "imgage_url": "url", "quantity": 2, "price_at_purchase": 20, "status": "pending" // completed, cancelled, }, { "id": "132", "product_id": "789", "name": "Product name", "imgage_url": "url", "quantity": 5, "price_at_purchase": 200, "status": "cancelled" // completed, cancelled, } ] }
Error Responses:
Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
cURL Command:
curl -X GET "http://localhost:3000/api/orders" \
-H "Content-Type": "application/json" \
-H "Cookie: connect.sid=<your-session-id>"GET /api/order/:orderId
This endpoint retrieves the details of a specific order for the authenticated user.
Headers:
Content-Type: application/jsonCookie: connect.sid=<your-session-id>
URL Parameters:
orderId(required): The ID of the order to retrieve the details for.
Validation:
- The
orderIdmust be a valid integer.
Success Response:
- Status Code:
200 OK - Body:
{ "success": true, "data": { "order_id": "123", "quantity": 2, "price_at_purchase": 55, "status": "completed", "product_name": "name", "product_image_url": "url", "shipping_address": "123 Main St, City, Country" } }
Error Responses:
-
Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
- Status Code:
-
Order Not Found:
- Status Code:
404 Not Found - Body:
{ "success": false, "message": "Order not found" }
- Status Code:
cURL Command:
curl -X GET "http://localhost:3000/api/order/123" \
-H "Content-Type": "application/json" \
-H "Cookie: connect.sid=<your-session-id>"POST /api/order/product
This endpoint allows the authenticated user to place an order for a product with a specified quantity.
Headers:
Cookie: connect.sid=<your-session-id>Content-Type: application/json
Body Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
productId |
string |
Yes | The ID of the product to order. |
quantity |
string |
Yes | The quantity of the product to order. |
Validation:
productIdandquantitymust be numeric strings.
Success Response:
- Status Code:
201 Created - Body:
{ "success": true }
Error Responses:
-
Invalid Input:
- Status Code:
400 Bad Request - Body:
{ "success": false, "message": "Invalid input" }
- Status Code:
-
Product Out of Stock:
- Status Code:
409 Conflict - Body:
{ "success": false, "message": "Not enough stock available" }
- Status Code:
-
Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
- Status Code:
cURL Command:
curl -X POST "http://localhost:3000/api/orders" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>" \
-d '{
"productId": "12345",
"quantity": "2"
}'POST /api/order/cart
This endpoint allows the authenticated user to place an order for all items currently in their cart.
Headers:
Content-Type: application/jsonCookie: connect.sid=<your-session-id>
Parameters:
- None
Validation:
- The cart must contain items to proceed with the order.
Success Response:
- Status Code:
201 Created - Body:
{ "success": true }
Error Responses:
-
Cart is Empty:
- Status Code:
400 Bad Request - Body:
{ "success": false, "message": "Cart is empty" }
- Status Code:
-
No Stock Available:
- Status Code:
409 Conflict - Body:
{ "success": false, "data": [ { "cart_id": 1, "productId": 1, "available": 3 } ], "message": "Not enough stock available" }
- Status Code:
-
Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
- Status Code:
cURL Command:
curl -X POST "http://localhost:3000/api/order/cart" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>"POST /api/order/cancel
This endpoint allows the authenticated user to cancel a specific order.
Headers:
Content-Type: application/jsonCookie: connect.sid=<your-session-id>
Body Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | The ID of the order to cancel. |
Validation:
orderIdmust be a numeric string.
Success Response:
- Status Code:
200 OK - Body:
{ "success": true }
Error Responses:
-
Invalid Input:
- Status Code:
400 Bad Request - Body:
{ "success": false, "message": "Invalid input" }
- Status Code:
-
Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
- Status Code:
cURL Command:
curl -X POST "http://localhost:3000/api/order/cancel" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>" \
-d '{
"orderId": "12345"
}'POST /api/checkout
This endpoint allows the authenticated user to proceed with the checkout process for their cart, retrieving detailed information on the items they are purchasing.
Headers:
Content-Type: application/jsonCookie: connect.sid=<your-session-id>
Parameters:
- None
Success Response:
- Status Code:
200 OK - Body:
{ "success": true, "data": [ { "price_at_purchase": 29.99, "quantity": 2, "total_price": 59.98, "product_id": "123", "product_name": "Product Name" }, { "price_at_purchase": 15.99, "quantity": 1, "total_price": 15.99, "product_id": "456", "product_name": "Another Product" } ] }
Error Responses:
- Server Error:
- Status Code:
500 Internal Server Error - Body:
{ "success": false, "message": "Server error" }
- Status Code:
cURL Command:
curl -X POST "http://localhost:3000/api/checkout" \
-H "Content-Type: application/json" \
-H "Cookie: connect.sid=<your-session-id>"