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