ElectroShop is a MERN stack electrical and hardware shop. It has a customer storefront, shopping cart, checkout with Cambodia delivery locations, and an admin panel for product, stock, sales, delivery price, and delivery status management.
- Frontend: React 18, Vite, Bootstrap, React Bootstrap
- Backend: Node.js, Express.js
- Database: MongoDB Atlas with Mongoose
- Auth: JWT admin login
- Uploads: Multer local image upload
Customer:
- Browse products by category
- Search products
- View product details
- Add products to cart
- Choose delivery place
- Enter name, phone number, and address at checkout
- Place order
Admin:
- Login with JWT
- Separate admin dashboard layout
- Add, edit, and delete products
- Upload product images from local computer
- View total products, total stock, low stock, and out of stock
- View sales report and recent orders
- Update delivery status
- Set delivery price for Phnom Penh and Cambodia provinces
Install these first:
- Node.js v16 or newer
- npm
- MongoDB Atlas account or local MongoDB connection string
Copy backend/.env.example to backend/.env, then edit the values:
PORT=5000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_secret_key
ADMIN_EMAIL=admin@electroshop.com
ADMIN_PASSWORD=admin123Copy frontend/.env.example to frontend/.env, then edit the value if needed:
VITE_API_URL=http://localhost:5000/apiFrom the project root:
npm run install-allThis installs dependencies for:
- root project
backendfrontend
If you want to install manually:
npm install
cd backend
npm install
cd ../frontend
npm installSeed products and delivery zones:
npm run seedWarning: this clears and recreates sample products.
Seed only Cambodia delivery prices:
cd backend
npm run seed:deliveryThis adds or updates Phnom Penh plus 24 provinces without deleting products.
From the project root:
npm run devThis starts both servers:
- Frontend:
http://localhost:3000 - Backend:
http://localhost:5000
Run separately if needed:
cd backend
npm run devcd frontend
npm run devOpen:
http://localhost:3000/admin/login
Demo login:
Email: admin@electroshop.com
Password: admin123
After admin login, the app redirects public pages back to the admin dashboard. Logout returns to the customer home page.
Customer pages:
//products/products/:id/cart/about/contact
Admin pages:
/admin/login/admin/dashboard/admin/add/admin/edit/:id/admin/delivery-prices
Shop name, phone, email, address, about text, and social links are in:
frontend/src/config/shopConfig.js
Edit this file to update header, footer, About page, Contact page, and home page text.
Admin can upload product images from local computer.
Uploaded files are saved in:
backend/uploads/
The backend serves them from:
http://localhost:5000/uploads/filename.jpg
Uploaded image file contents are ignored by git. The folder stays in the repo because of:
backend/uploads/.gitkeep
Products:
| Method | Route | Description |
|---|---|---|
| GET | /api/products |
Get products |
| GET | /api/products/:id |
Get one product |
| GET | /api/products/search/:name |
Search product by name |
| POST | /api/products |
Create product |
| PUT | /api/products/:id |
Update product |
| DELETE | /api/products/:id |
Delete product |
Cart:
| Method | Route | Description |
|---|---|---|
| GET | /api/cart |
Get cart |
| POST | /api/cart |
Add item |
| PUT | /api/cart/:id |
Update quantity |
| DELETE | /api/cart/:id |
Remove item |
Orders:
| Method | Route | Description |
|---|---|---|
| POST | /api/orders |
Checkout and create order |
| GET | /api/orders/report |
Admin sales report |
| PUT | /api/orders/:id/delivery-status |
Update delivery status |
Delivery prices:
| Method | Route | Description |
|---|---|---|
| GET | /api/delivery-zones |
Public delivery places |
| GET | /api/delivery-zones/admin/all |
Admin delivery places |
| PUT | /api/delivery-zones/:id |
Update delivery price/status |
Admin:
| Method | Route | Description |
|---|---|---|
| POST | /api/admin/login |
Admin login |
| GET | /api/admin/verify |
Verify token |
Upload:
| Method | Route | Description |
|---|---|---|
| POST | /api/upload |
Upload product image |
npm run buildIf checkout says Cart session is required, add an item to cart again and retry checkout.
If uploaded images do not show, restart backend and check that this route exists:
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));If delivery places are empty, run:
cd backend
npm run seed:deliveryIf admin login fails, check backend/.env:
ADMIN_EMAIL=admin@electroshop.com
ADMIN_PASSWORD=admin123
JWT_SECRET=your_secret_key