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 e-commerce application with a Node.js/Express backend and React frontend.
🚀 Quick Start
Prerequisites
Node.js 18+
npm 9+
Installation
# Clone the repository
git clone https://github.com/Dipesh-J/Project-Ecommerce-Website.git
cd Project-Ecommerce-Website
# Install all dependencies (frontend + backend)
npm install
Running the Application
# Start both frontend and backend simultaneously
npm run dev:all
# Or run them separately:# Terminal 1 - Backend (http://localhost:3000)
npm run dev:backend
# Terminal 2 - Frontend (http://localhost:5173)
npm run dev
The frontend uses a custom design system with the following tokens:
Token
Value
Primary Color
#735F32
Primary Variant
#C69749
Background
#000000
Surface
#282A3A
Text Primary
#ffffff
Text Secondary
rgba(255, 255, 255, 0.6)
Font Family
Poppins
🔌 API Endpoints
User APIs
Method
Endpoint
Description
Auth
POST
/register
Register new user
No
POST
/login
User login
No
GET
/user/:userId/profile
Get user profile
Yes
PUT
/user/:userId/profile
Update user profile
Yes
Product APIs
Method
Endpoint
Description
Auth
POST
/products
Create product
No
GET
/products
Get all products
No
GET
/products/:productId
Get product by ID
No
PUT
/products/:productId
Update product
No
DELETE
/products/:productId
Delete product
No
Cart APIs
Method
Endpoint
Description
Auth
POST
/users/:userId/cart
Add to cart
Yes
PUT
/users/:userId/cart
Update cart
Yes
GET
/users/:userId/cart
Get cart
Yes
DELETE
/users/:userId/cart
Clear cart
Yes
Order APIs
Method
Endpoint
Description
Auth
POST
/users/:userId/orders
Create order
Yes
PUT
/users/:userId/orders
Update order status
Yes
🚀 Deployment
Frontend (Vercel/Netlify)
Connect your GitHub repository
Set build settings:
Build command: npm run build
Output directory: frontend/dist
Set environment variable:
VITE_API_URL: Your backend URL
Backend (Render/Railway)
Connect your GitHub repository
Set root directory: backend
Set environment variables:
PORT: 3000
MONGODB_URI: Your MongoDB connection string
📖 Original Backend Documentation
Key points
In this project we will work feature wise. That means we pick one object like user, book, blog, etc at a time. We work through it's feature. The steps would be:
We create it's model.
We build it's APIs.
We test these APIs.
We deploy these APIs.
We integrate these APIs with frontend.
We will repeat steps from Step 1 to Step 5 for each feature in this project.
This project is divided into 4 features namely User, Product, Cart and Order. You need to work on a single feature at a time. Once that is completed as per above mentioned steps. You will be instructed to move to next Feature.
In this project we are changing how we send token with a request. Instead of using a custom header key like x-api-key, you need to use Authorization header and send the JWT token as Bearer token.
Create a group database groupXDatabase. You can clean the db you previously used and resue that.
This time each group should have a single git branch. Coordinate amongst yourselves by ensuring every next person pulls the code last pushed by a team mate. You branch will be checked as part of the demo. Branch name should follow the naming convention project/productsManagementGroupX
Follow the naming conventions exactly as instructed.
{ title: {string, mandatory, unique},description: {string, mandatory},price: {number, mandatory, valid number/decimal},currencyId: {string, mandatory, INR},currencyFormat: {string, mandatory, Rupee symbol},isFreeShipping: {boolean, default: false},productImage: {string, mandatory}, // s3 linkstyle: {string},availableSizes: {array of string, at least one size, enum["S", "XS","M","X", "L","XXL", "XL"]},installments: {number},deletedAt: {Date, when the document is deleted}, isDeleted: {boolean, default: false},createdAt: {timestamp},updatedAt: {timestamp},}
Products API (No authentication required)
POST /products
Create a product document from request body.
Upload product image to S3 bucket and save image public url in document.
Response format
On success - Return HTTP status 201. Also return the product document. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
GET /products
Returns all products in the collection that aren't deleted.
Filters
Size (The key for this filter will be 'size')
Product name (The key for this filter will be 'name'). You should return all the products with name containing the substring recieved in this filter
Price : greater than or less than a specific value. The keys are 'priceGreaterThan' and 'priceLessThan'.
NOTE: For price filter request could contain both or any one of the keys. For example the query in the request could look like { priceGreaterThan: 500, priceLessThan: 2000 } or just { priceLessThan: 1000 } )
Sort
Sorted by product price in ascending or descending. The key value pair will look like {priceSort : 1} or {priceSort : -1}
eg /products?size=XL&name=Nit%20grit
Response format
On success - Return HTTP status 200. Also return the product documents. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
GET /products/:productId
Returns product details by product id
Response format
On success - Return HTTP status 200. Also return the product documents. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
PUT /products/:productId
Updates a product by changing at least one or all fields
Check if the productId exists (must have isDeleted false and is present in collection). If it doesn't, return an HTTP status 404 with a response body like this
Response format
On success - Return HTTP status 200. Also return the updated product document. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
DELETE /products/:productId
Deletes a product by product id if it's not already deleted
Response format
On success - Return HTTP status 200. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
FEATURE III - Cart
Models
Cart Model
{userId: {ObjectId, refs to User, mandatory, unique},items: [{productId: {ObjectId, refs to Product model, mandatory},quantity: {number, mandatory, min 1}}],totalPrice: {number, mandatory, comment: "Holds total price of all the items in the cart"},totalItems: {number, mandatory, comment: "Holds total number of items in the cart"},createdAt: {timestamp},updatedAt: {timestamp},}
Cart APIs (authentication required as authorization header - bearer token)
POST /users/:userId/cart (Add to cart)
Create a cart for the user if it does not exist. Else add product(s) in cart.
Get cart id in request body.
Get productId in request body.
Make sure that cart exist.
Add a product(s) for a user in the cart.
Make sure the userId in params and in JWT token match.
Make sure the user exist
Make sure the product(s) are valid and not deleted.
Get product(s) details in response body.
Response format
On success - Return HTTP status 201. Also return the cart document. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
PUT /users/:userId/cart (Remove product / Reduce a product's quantity from the cart)
Updates a cart by either decrementing the quantity of a product by 1 or deleting a product from the cart.
Get cart id in request body.
Get productId in request body.
Get key 'removeProduct' in request body.
Make sure that cart exist.
Key 'removeProduct' denotes whether a product is to be removed({removeProduct: 0}) or its quantity has to be decremented by 1({removeProduct: 1}).
Make sure the userId in params and in JWT token match.
Make sure the user exist
Get product(s) details in response body.
Check if the productId exists and is not deleted before updating the cart.
Response format
On success - Return HTTP status 200. Also return the updated cart document. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
GET /users/:userId/cart
Returns cart summary of the user.
Make sure that cart exist.
Make sure the userId in params and in JWT token match.
Make sure the user exist
Get product(s) details in response body.
Response format
On success - Return HTTP status 200. Return the cart document. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
DELETE /users/:userId/cart
Deletes the cart for the user.
Make sure that cart exist.
Make sure the userId in params and in JWT token match.
Make sure the user exist
cart deleting means array of items is empty, totalItems is 0, totalPrice is 0.
Response format
On success - Return HTTP status 204. Return a suitable message. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
FEATURE IV - Order
Models
Order Model
{userId: {ObjectId, refs to User, mandatory},items: [{productId: {ObjectId, refs to Product model, mandatory},quantity: {number, mandatory, min 1}}],totalPrice: {number, mandatory, comment: "Holds total price of all the items in the cart"},totalItems: {number, mandatory, comment: "Holds total number of items in the cart"},totalQuantity: {number, mandatory, comment: "Holds total number of quantity in the cart"},cancellable: {boolean, default: true},status: {string, default: 'pending', enum[pending, completed, cancled]},deletedAt: {Date, when the document is deleted}, isDeleted: {boolean, default: false},createdAt: {timestamp},updatedAt: {timestamp},}
Checkout/Order APIs (Authentication and authorization required)
POST /users/:userId/orders
Create an order for the user
Make sure the userId in params and in JWT token match.
Make sure the user exist
Get cart details in the request body
Response format
On success - Return HTTP status 200. Also return the order document. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
PUT /users/:userId/orders
Updates an order status
Make sure the userId in params and in JWT token match.
Make sure the user exist
Get order id in request body
Make sure the order belongs to the user
Make sure that only a cancellable order could be canceled. Else send an appropriate error message and response.
Response format
On success - Return HTTP status 200. Also return the updated order document. The response should be a JSON object like this
On error - Return a suitable error message with a valid HTTP status code. The response should be a JSON object like this
Testing
To test these apis create a new collection in Postman named Project 5 Shopping Cart
Each api should have a new request in this collection
Each request in the collection should be rightly named. Eg Create user, Create product, Get products etc
Each member of each team should have their tests in running state