This is a full-stack eCommerce store built using modern web technologies. It allows users to browse products, filter them by categories and brands, and make purchases. The store features authentication, a shopping cart, and an admin panel for managing products and orders.
- User authentication (Sign up, Login, Logout)
- Product listing with category and brand filters
- Shopping cart functionality
- Checkout process with payment integration
- Admin panel for product and order management
- Responsive design for mobile and desktop
- Node.js & npm installed
- MongoDB running locally or on a cloud provider
-
Clone the repository:
git clone https://github.com/safwan-ms/MERN-Stack-SafwaxStore.git cd MERN-Stack-SafwaxStore -
Install dependencies for frontend and backend:
cd frontend # Navigate to frontend folder npm install or npm i # Install frontend dependencies cd ../backend # Navigate to backend folder npm install or npm i # Install backend dependencies
-
Set up environment variables:
-
Create a
.envfile in thebackenddirectory and add the required configurations:MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_secret_key
-
-
Start the development servers:
npm run backend # Start backend server npm run frontend # Start frontend server
-
Access the application:
- Open http://localhost:5173 in your browser for the frontend.
- Backend runs on
http://localhost:5000(or specified port).
| Method | Endpoint | Description |
|---|---|---|
| POST | / |
Create a new user |
| GET | / |
Get all users (Admin only) |
| POST | /auth |
Login a user |
| POST | /logout |
Logout the current user |
| GET | /profile |
Get the current user's profile |
| PUT | /profile |
Update the current user's profile |
| DELETE | /:_id |
Delete a user by ID (Admin only) |
| GET | /:_id |
Get a user by ID (Admin only) |
| PUT | /:_id |
Update a user by ID (Admin only) |
authenticate: Ensures only authenticated users can access certain routes.authorizedAdmin: Restricts access to admin users only.
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Fetch paginated products |
| POST | / |
Add a new product (Admin only, uses formidable for file uploads) |
| GET | /allproducts |
Fetch all products without pagination |
| POST | /:id/reviews |
Add a review to a product (Authenticated users only) |
| GET | /top |
Fetch top-rated products |
| GET | /new |
Fetch newly added products |
| GET | /:id |
Fetch a product by ID |
| PUT | /:id |
Update product details (Admin only, uses formidable for file uploads) |
| DELETE | /:id |
Delete a product by ID (Admin only) |
| POST | /filtered-products |
Filter products based on criteria |
authenticate: Ensures only authenticated users can access certain routes.authorizedAdmin: Restricts access to admin users only.checkId: Validates product ID before performing actions.formidable(): Handles file uploads for product images.
| Method | Endpoint | Description |
|---|---|---|
| POST | / |
Create a new category (Admin only) |
| PUT | /:categoryId |
Update a category (Admin only) |
| DELETE | /:categoryId |
Remove a category (Admin only) |
| GET | /categories |
List all categories |
| GET | /:id |
Read a category by ID |
authenticate: Ensures only authenticated users can access certain routes.authorizedAdmin: Restricts access to admin users only.
| Method | Endpoint | Description |
|---|---|---|
| POST | / |
Create a new order (Authenticated users only) |
| GET | / |
Get all orders (Admin only) |
| GET | /mine |
Get the current user's orders |
| GET | /total-orders |
Get total number of orders |
| GET | /total-sales |
Calculate total sales |
| GET | /total-sales-by-date |
Calculate total sales by date |
| GET | /:id |
Get an order by ID (Authenticated users only) |
| PUT | /:id/pay |
Mark an order as paid (Authenticated users only) |
| PUT | /:id/deliver |
Mark an order as delivered (Admin only) |
authenticate: Ensures only authenticated users can access certain routes.authorizedAdmin: Restricts access to admin users only (where applicable).
- All admin routes require authentication and admin authorization.
- Users can only modify their own profiles unless they have admin access.
- Product and category-related operations (add, update, delete) are restricted to admins.
POST /api/users/auth
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}GET /api/products/allproductsPOST /api/products
Authorization: Bearer <admin-token>
Content-Type: multipart/form-data
{
"name": "New Product",
"image": "<file>",
"brand": "Brand Name",
"price": 100,
"quantity": 10,
"category": "category_id",
"description": "Product description",
"countInStock": 50
}
POST /api/categories
Authorization: Bearer <admin-token>
Content-Type: application/json
{
"name": "Electronics"
}Contributions are welcome! Feel free to fork the repository and submit pull requests.
Developed by Safwax