This is a modern full-stack E-Commerce application built using the MERN stack (MongoDB, Express, React, Node.js). It includes authentication with JSON Web Tokens (JWT), role-based authorization (Admin & User access control), password hashing, and concurrent client-server execution.
- User Authentication: Secure registration, login, and forgot password flows.
- Security: Password hashing using
bcryptand token-based authentication viajsonwebtoken. - Role-based Access Control: Route protections for standard Users and Admin users.
- Concurrent Development: Run both the Express backend and React frontend with a single command.
.
├── client/ # React frontend application
│ ├── public/ # Static public assets
│ ├── src/ # React source code (components, pages, styles)
│ ├── package.json # Frontend dependencies & scripts
│ └── README.md # Frontend-specific documentation
├── config/ # Database and configuration files
│ └── db.js # MongoDB connection setup
├── controllers/ # Request handlers / Controller layer
│ └── authController.js # User registration, login, & password management
├── helpers/ # Helper utilities (e.g., password hashing)
├── middlewares/ # Custom Express middlewares (e.g., authentication & role validation)
├── models/ # Mongoose schemas/models
│ └── userModel.js # User database schema
├── routes/ # Express API routes
│ └── authrRoute.js # Auth endpoints
├── .env # Environment variables (Ignored in git)
├── package.json # Root configuration & scripts
└── server.js # Main entry point for the backend server
Make sure you have Node.js and MongoDB installed on your system.
git clone <repository-url>
cd ecommerceInstall dependencies for both the root (backend) and client (frontend):
Root Backend:
npm installClient Frontend:
cd client
npm install
cd ..Create a .env file in the root directory (alongside server.js) with the following variables:
PORT=8080
MONGO_URL=your_mongodb_connection_uri
JWT_SECRET=your_jwt_secret_keyIn the root directory, you can run the following scripts:
- Run Client & Server concurrently (Recommended)
npm run dev
- Run Backend only (with Nodemon)
npm run server
- Run Frontend only
npm run client
- Production Start (Backend)
npm start
All backend routes are prefixed with /api/v1.
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /register |
Register a new user | No |
| POST | /login |
Login user and retrieve JWT token | No |
| POST | /forgot-password |
Reset password request | No |
| GET | /test |
Test route for auth verification | Yes (Admin only) |
| GET | /user-auth |
Verify token for standard User routing | Yes |
| GET | /admin-auth |
Verify token for Admin routing | Yes (Admin only) |
- Backend: Node.js, Express, MongoDB (Mongoose), JSON Web Tokens (JWT), Bcrypt
- Frontend: React, React Router, Bootstrap, Axios

