A complete MERN stack e-commerce application for a pet foods and accessories store.
petshop/
βββ client/ # React.js Frontend (Vite)
β βββ src/
β β βββ components/
β β β βββ Admin/ # AdminLayout
β β β βββ Common/ # Navbar, Footer, ProductCard
β β βββ context/ # AuthContext, CartContext
β β βββ pages/
β β β βββ Admin/ # Dashboard, Products, Orders, Users, Settings
β β β βββ Auth/ # Login, Register
β β β βββ User/ # Home, Products, ProductDetail, Cart, Checkout, etc.
β β βββ utils/ # API client (Axios)
β βββ package.json
βββ server/ # Node.js + Express.js Backend
βββ config/ # MongoDB connection
βββ controllers/ # auth, product, cart, order, user, review, wishlist, admin
βββ data/ # Seed data
βββ middleware/ # JWT auth
βββ models/ # User, Product, Order, Cart, Review, Admin
βββ routes/ # All API routes
βββ package.json
- Node.js v18+
- MongoDB (local or MongoDB Atlas)
- npm or yarn
git clone <repo-url>
cd petshopcd server
npm install
# Copy env file and configure
cp .env.example .envEdit .env:
PORT=8000
MONGO_URI=mongodb://localhost:27017/petpaws
JWT_SECRET=your_super_secret_key_here
JWT_EXPIRE=7d
NODE_ENV=developmentSeed the database:
npm run seedThis creates:
- π Admin:
admin@petpaws.com/admin123 - π€ User:
john@example.com/user123 - 16 sample products across all categories
- Sample order and settings
Start the backend:
npm run dev # Development (nodemon)
npm start # ProductionServer runs at: http://localhost:8000
cd client
npm install
npm run devFrontend runs at: http://localhost:5173
The Vite proxy forwards all /api/* requests to http://localhost:8000.
| URL | Description |
|---|---|
http://localhost:5173 |
Customer storefront |
http://localhost:5173/admin |
Admin panel |
http://localhost:5173/login |
Login page |
http://localhost:8000/api/health |
API health check |
- username, email, password (bcrypt hashed)
- phone, avatar, role (user/admin)
- addresses (array), wishlist (product refs)
- isActive, lastLogin
- name, description, price, discountedPrice, discount
- category (15 types), petType (8 types), brand
- images, stock, weight, variants
- ratings.average, ratings.count
- tags, isFeatured, isActive, soldCount
- user, orderItems (product, name, image, price, qty, variant)
- shippingAddress, paymentMethod, paymentStatus
- itemsPrice, shippingPrice, taxPrice, totalPrice
- orderStatus, statusHistory, trackingNumber
- user, items (product, name, image, price, qty, variant, stock)
- user, product, rating (1-5), title, comment
- isVerifiedPurchase, isApproved
- banners, categories, shippingFee, freeShippingAbove, taxRate
- siteName, siteTagline, contactEmail, contactPhone
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/auth/register |
Public | Register user |
| POST | /api/auth/login |
Public | Login user |
| POST | /api/auth/admin/login |
Public | Admin login |
| GET | /api/auth/me |
User | Get current user |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/products |
Public | Get all (filters, pagination) |
| GET | /api/products/featured |
Public | Featured products |
| GET | /api/products/brands |
Public | All brands |
| GET | /api/products/:id |
Public | Single product + reviews |
| GET | /api/products/:id/related |
Public | Related products |
| POST | /api/products |
Admin | Create product |
| PUT | /api/products/:id |
Admin | Update product |
| DELETE | /api/products/:id |
Admin | Soft-delete product |
Query Parameters (GET /api/products):
keyword,category,petType,brandminPrice,maxPrice,ratingsort(newest, popular, rating, price_asc, price_desc)page,limit,featured
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/cart |
User | Get cart |
| POST | /api/cart |
User | Add item |
| PUT | /api/cart/:itemId |
User | Update quantity |
| DELETE | /api/cart/:itemId |
User | Remove item |
| DELETE | /api/cart |
User | Clear cart |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/orders |
User | Create order |
| GET | /api/orders/my |
User | My orders |
| GET | /api/orders/:id |
User | Order detail |
| PUT | /api/orders/:id/cancel |
User | Cancel order |
| GET | /api/orders |
Admin | All orders |
| PUT | /api/orders/:id/status |
Admin | Update status |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| PUT | /api/users/profile |
User | Update profile |
| PUT | /api/users/password |
User | Change password |
| POST | /api/users/addresses |
User | Add address |
| PUT | /api/users/addresses/:id |
User | Update address |
| DELETE | /api/users/addresses/:id |
User | Delete address |
| GET | /api/users |
Admin | All users |
| PUT | /api/users/:id/toggle |
Admin | Toggle status |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/wishlist |
User | Get wishlist |
| POST | /api/wishlist/:productId |
User | Toggle item |
| DELETE | /api/wishlist/:productId |
User | Remove item |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/reviews |
User | Add review |
| GET | /api/reviews/product/:id |
Public | Product reviews |
| DELETE | /api/reviews/:id |
User/Admin | Delete review |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/admin/dashboard |
Admin | Dashboard stats |
| GET | /api/admin/settings |
Admin | Get settings |
| PUT | /api/admin/settings |
Admin | Update settings |
| POST | /api/admin/banners |
Admin | Add banner |
| DELETE | /api/admin/banners/:id |
Admin | Delete banner |
| POST | /api/admin/categories |
Admin | Add category |
- β User registration & login with JWT
- β Product browsing with advanced filters (category, pet type, price, brand, rating)
- β Product search with text indexing
- β Product detail with image gallery, variants, reviews
- β Shopping cart (add, update qty, remove, clear)
- β Wishlist (add/remove, move to cart)
- β Multi-step checkout (address β payment β review)
- β Order placement with stock validation
- β Order tracking with status timeline
- β Order cancellation
- β Product reviews & star ratings
- β Verified purchase badge on reviews
- β Profile management (name, phone)
- β Password change
- β Multiple saved addresses
- β Order history with status filters
- β Responsive mobile design
- β Admin dashboard with revenue charts, top products, low stock alerts
- β Product management (create, edit, delete, featured toggle)
- β Category and pet type filter for products
- β Order management (view, update status, add tracking number)
- β Customer management (view, activate/deactivate)
- β Store settings (shipping fee, free shipping threshold, tax rate)
- β Banner management for homepage
- β JWT authentication with refresh on every request
- β Password hashing with bcryptjs
- β Automatic discount price calculation
- β Stock management (deduct on order, restore on cancel)
- β Sorted/paginated API responses
- β Text search with MongoDB indexes
- β Axios interceptors for auth headers and 401 redirect
- β React Context for auth and cart state
- β Vite proxy for seamless API calls in development
- πΆ Dog Food (Dry, Wet, Treats, Puppy, Senior)
- π± Cat Food (Dry, Wet, Treats, Kitten)
- π¦ Bird Food
- π Fish Food
- πΎ Dog Accessories (Collars, Leashes, Bowls, Clothing)
- π Cat Accessories (Scratching Posts, Litter, Carriers)
- πΎ Toys (Chew, Interactive, Plush, Fetch)
- βοΈ Grooming (Brushes, Shampoo, Nail Care, Dental)
- π Health & Supplements (Vitamins, Joint, Skin & Coat)
- ποΈ Beds & Furniture
- π Cages & Habitats
- π Leashes & Collars
- π Clothing & Apparel
- π Small Animal Food
- π Other
# Set environment variables:
MONGO_URI=mongodb+srv://...
JWT_SECRET=strong_secret_here
NODE_ENV=production
PORT=8000cd client
npm run build
# Deploy the dist/ folder
# Set environment variable:
VITE_API_URL=https://your-backend-url.comUpdate vite.config.js proxy target for staging, or update src/utils/api.js baseURL.
| Layer | Technology |
|---|---|
| Frontend | React 18, React Router 6, Vite 5 |
| Styling | Pure CSS with CSS Variables |
| State | React Context API |
| HTTP Client | Axios with interceptors |
| Backend | Node.js, Express.js 4 |
| Database | MongoDB with Mongoose 8 |
| Auth | JWT (jsonwebtoken) + bcryptjs |
| Icons | react-icons (Feather) |
| Notifications | react-hot-toast |
- Admin email: admin@petpaws.com
- Default admin password: admin123
- Test user: john@example.com / user123