This is a comprehensive e-commerce full-stack application built using Next.js for the frontend and Node.js with Express.js for the backend. It provides functionality for user authentication, seller product management, and buyer shopping experience.
This is a comprehensive e-commerce full-stack application built using Next.js for the frontend and Node.js with Express.js for the backend. It provides functionality for user authentication, seller product management, and buyer shopping experience.
Clone and navigate to the client directory:
git clone https://github.com/debrajhyper/e-commerce.git
cd e-commerce/client
Install dependencies:
npm install
Create a .env file in the root of the client directory and add:
API_BASE_URL=http://localhost:5000/api // Backend server URL
Run the development server:
npm run dev
Open http://localhost:3000 in your browser to see the application.
Navigate to the server directory:
cd e-commerce/server
Install dependencies:
npm install
Create a .env
file in the root of the server directory and add:
DB_USER=DATABASE_USER
DB_HOST=DATABASE_HOST
DB_NAME=DATABASE_NAME
DB_PASSWORD=DATABASE_PASSWORD
DB_PORT=DATABASE_PORT
JWT_SECRET=JWT_SECRET
AUTH_ROLE_BUYER=buyer
AUTH_ROLE_SELLER=seller
PORT=5000
Set up your PostgreSQL database and update the connection string in .env
.
Run the server:
node serve.js
Create a new user account.
Request body:
{
"email": "string",
"password": "string",
"role": "seller" | "buyer"
}
Log in to an existing account.
Request body:
{
"email": "string",
"password": "string"
}
Response:
{
"token": "jwt_token",
}
Get all products.
Response:
[
{
"id": "string",
"name": "string",
"category": "string",
"description": "string",
"price": number,
"discount": number,
"sellerId": "string"
}
]
Get a specific product by ID.
Response:
{
"id": "string",
"name": "string",
"category": "string",
"description": "string",
"price": "string",
"discount": "string",
"sellerId": "string"
}
Create a new product (seller only).
Request body:
{
"name": "string",
"category": "string",
"description": "string",
"price": "string",
"discount": "string"
}
Update an existing product (seller only).
Request body:
{
"id": "string",
"name": "string",
"category": "string",
"description": "string",
"price": "string",
"discount": "string"
}
Delete a product (seller only).
Get the current user's cart.
Response:
[
{
"id": "string",
"name": "string",
"category": "string",
"description": "string",
"price": "string",
"discount": "string",
"quantity": number,
"seller_id": number
}
]
Add a product to the cart.
Request body:
{
"productId": "string",
"quantity": number
}
Remove a product from the cart.
client/
âââ public/
âââ src/
â âââ app/
â | âââ auth/
â | | âââ login/
â | | | âââ page.tsx
â | | âââ signup/
â | | âââ page.tsx
â | âââ buyer/
â | | âââ cart/
â | | | âââ page.tsx
â | | âââ dashboard/
â | | âââ page.tsx
â | âââ seller/
â | | âââ add-product/
â | | | âââ page.tsx
â | | âââ dashboard/
â | | | âââ page.tsx
â | | âââ edit-product/
â | | âââ page.tsx
â | âââ unauthorize/
â | âââ layout.tsx
â | âââ not-found.tsx
â | âââ page.tsx
â âââ components/
â | âââ ui/
â | âââ DashboardTitle.tsx
â | âââ ErrorAlert.tsx
â | âââ Footer.tsx
â | âââ Header.tsx
â | âââ ProductCard.tsx
â | âââ ProductCardLoading.tsx
â | âââ ProductCount.tsx
â | âââ ProductForm.tsx
â | âââ SearchBar.tsx
â âââ constants/
â âââ helpers/
â âââ hooks/
â âââ lib/
â âââ public/
â âââ store/
â âââ styles/
â âââ utils/
âââ .eslintrc.json
âââ next.config.js
âââ package.json
âââ postcss.config.js
âââ tailwind.config.js
âââ tsconfig.json
server/
âââ config/
â âââ database.js
âââ controllers/
â âââ authController.js
â âââ cartController.js
â âââ productController.js
âââ middleware/
â âââ auth.js
âââ models/
â âââ Cart.js
â âââ Product.js
â âââ User.js
âââ routes/
â âââ auth.js
â âââ cart.js
â âââ products.js
âââ .env
âââ package.json
âââ server.js