A Modern, Responsive Shopping Cart Application Built with MERN Stack
Features โข Tech Stack โข Setup โข API Documentation โข Screenshots
- Overview
- Features
- Tech Stack
- Project Structure
- Installation & Setup
- Environment Variables
- API Documentation
- Screenshots
- Bonus Features Implemented
- Demo Video
- Future Enhancements
- Author
KART is a fully functional e-commerce shopping cart application. This project demonstrates proficiency in full-stack development, covering frontend UI/UX, backend REST APIs, database integration, and real-world e-commerce workflows.
The application features a curated collection of 24 Gen Z streetwear products, complete authentication flow, persistent cart management, and email order confirmations. It showcases modern web development practices with a focus on responsive design and user experience.
-
Product Catalog
- Grid display of 24 Gen Z fashion products
- Pagination (8 products per page)
- Category badges and product descriptions
- Prices in Indian Rupees (โน)
-
Shopping Cart
- Add/Remove items with real-time updates
- Quantity increment/decrement controls
- Dynamic cart total calculation
- Persistent cart storage in MongoDB
-
User Authentication
- Secure JWT-based authentication (7-day token expiry)
- Sign Up / Sign In modal
- Password hashing with bcryptjs
- Protected cart and checkout routes
-
Checkout Flow
- Customer information form (Name & Email)
- Loading animation during order processing
- Mock order receipt generation
- Order timestamp and unique ID
-
Responsive Design
- Mobile-first approach with Tailwind CSS
- Breakpoints: Mobile (320px), Tablet (640px), Desktop (768px+)
- Touch-friendly UI elements
- Adaptive layouts for all screen sizes
- Database Persistence: MongoDB Atlas integration with Mongoose ODM
- User Sessions: JWT token-based authentication with secure HTTP-only considerations
- Email Notifications: EmailJS integration for order confirmation emails
- Error Handling: Comprehensive error handling with user-friendly toast notifications
- Loading States: Skeleton screens and spinners for better UX
- Code Quality: Clean, commented code following best practices
- Modern UI: Organic design with coral/teal/blue color scheme and rounded corners
- React 19.1.1 - UI library with hooks
- Vite 7.1.7 - Fast build tool and dev server
- Tailwind CSS 4.1.16 - Utility-first CSS framework
- Axios 1.13.2 - HTTP client for API calls
- React Hot Toast - Beautiful toast notifications
- EmailJS - Client-side email service integration
- Node.js 18+ - JavaScript runtime
- Express 5.1.0 - Web application framework
- MongoDB Atlas - Cloud-hosted NoSQL database
- Mongoose 8.19.3 - MongoDB object modeling
- JWT (jsonwebtoken 9.0.2) - Secure authentication tokens
- bcryptjs 3.0.3 - Password hashing
- CORS 2.8.5 - Cross-origin resource sharing
- ESLint - Code linting
- dotenv - Environment variable management
- Git - Version control
Kart/
โโโ Backend/
โ โโโ config/
โ โ โโโ db.js # MongoDB connection
โ โโโ controllers/
โ โ โโโ authController.js # Authentication logic
โ โ โโโ cartController.js # Cart operations
โ โ โโโ checkoutController.js # Checkout processing
โ โ โโโ productController.js # Product retrieval
โ โโโ middleware/
โ โ โโโ authMiddleware.js # JWT verification
โ โโโ models/
โ โ โโโ User.js # User schema
โ โ โโโ Product.js # Product schema
โ โ โโโ CartItem.js # Cart item schema
โ โ โโโ Order.js # Order schema
โ โโโ routes/
โ โ โโโ authRoutes.js # Auth endpoints
โ โ โโโ cartRoutes.js # Cart endpoints
โ โ โโโ checkoutRoutes.js # Checkout endpoints
โ โ โโโ productRoutes.js # Product endpoints
โ โโโ seed.js # Database seeding script
โ โโโ index.js # Express app entry
โ โโโ package.json
โ โโโ .env # Environment variables
โ
โโโ Frontend/
โ โโโ src/
โ โ โโโ components/
โ โ โ โโโ Products.jsx # Product grid & pagination
โ โ โ โโโ Cart.jsx # Shopping cart modal
โ โ โ โโโ AuthModal.jsx # Sign In/Sign Up
โ โ โ โโโ CheckoutModal.jsx # Checkout form
โ โ โ โโโ ReceiptModal.jsx # Order confirmation
โ โ โโโ context/
โ โ โ โโโ AuthContext.jsx # Global auth state
โ โ โโโ utils/
โ โ โ โโโ api.js # Axios instance
โ โ โ โโโ emailService.js # EmailJS integration
โ โ โโโ App.jsx # Main app component
โ โ โโโ main.jsx # React entry point
โ โ โโโ index.css # Global styles
โ โโโ public/
โ โโโ index.html
โ โโโ package.json
โ โโโ vite.config.js
โ โโโ tailwind.config.js
โ โโโ .env # Environment variables
โ
โโโ Screenshots/ # Application screenshots
โ โโโ Home.png
โ โโโ Signup.png
โ โโโ Cart.png
โ โโโ Reciept.png
โ โโโ Mail.png
โ
โโโ README.md # This file
- Node.js (v18 or higher)
- MongoDB Atlas account (or local MongoDB)
- Git
git clone https://github.com/yourusername/kart.git
cd kart# Navigate to backend directory
cd Backend
# Install dependencies
npm install
# Create .env file
# Copy the contents from .env.example or create manually
# Add your MongoDB URI and JWT secretBackend .env file:
PORT=4000
MONGO_URI=your_mongodb_atlas_connection_string
JWT_SECRET=jwt_key
NODE_ENV=developmentSeed the Database (First Time Only):
node seed.jsStart Backend Server:
# Development mode with auto-reload
npm run dev
# Production mode
npm startBackend will run on http://localhost:4000
# Navigate to frontend directory
cd ../Frontend
# Install dependencies
npm install
# Create .env file for EmailJS (optional)Frontend .env file (Optional - for email notifications):
VITE_EMAILJS_SERVICE_ID=your_emailjs_service_id
VITE_EMAILJS_TEMPLATE_ID=your_emailjs_template_id
VITE_EMAILJS_PUBLIC_KEY=your_emailjs_public_keyStart Frontend Development Server:
npm run devFrontend will run on http://localhost:5173
Open your browser and navigate to:
http://localhost:5173
- Go to MongoDB Atlas Dashboard
- Navigate to Network Access
- Click Add IP Address
- Choose one of:
- Add Current IP Address (for development)
- Allow Access from Anywhere (
0.0.0.0/0) (for testing)
- Click Confirm
- Wait 1-2 minutes for changes to propagate
| Variable | Description | Example |
|---|---|---|
PORT |
Backend server port | 4000 |
MONGO_URI |
MongoDB connection string | mongodb+srv://user:pass@cluster.mongodb.net/kart |
JWT_SECRET |
Secret key for JWT signing | your_secret_key_123 |
NODE_ENV |
Environment mode | development or production |
| Variable | Description | Required |
|---|---|---|
VITE_EMAILJS_SERVICE_ID |
EmailJS service ID | Optional (for emails) |
VITE_EMAILJS_TEMPLATE_ID |
EmailJS template ID | Optional (for emails) |
VITE_EMAILJS_PUBLIC_KEY |
EmailJS public key | Optional (for emails) |
http://localhost:4000/api
POST /api/auth/registerRequest Body:
{
"name": "sam",
"email": "sam@example.com",
"password": "password123"
}Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "507f1f77bcf86cd799439011",
"name": "John Doe",
"email": "john@example.com"
}
}POST /api/auth/loginRequest Body:
{
"email": "sam@example.com",
"password": "password123"
}Response: Same as Register
GET /api/products?page=1&limit=8Query Parameters:
page(optional): Page number (default: 1)limit(optional): Items per page (default: 8)
Response:
{
"products": [
{
"_id": "507f1f77bcf86cd799439011",
"name": "Oversized Graphic Tee",
"price": 1299,
"description": "Vintage-inspired streetwear essential",
"image": "https://images.unsplash.com/...",
"category": "Tops"
}
],
"pagination": {
"currentPage": 1,
"totalPages": 3,
"totalProducts": 24,
"limit": 8
}
}Note: All cart endpoints require
Authorization: Bearer <token>header
GET /api/cartHeaders:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"items": [
{
"_id": "507f1f77bcf86cd799439012",
"user": "507f1f77bcf86cd799439011",
"product": {
"_id": "507f1f77bcf86cd799439013",
"name": "Oversized Graphic Tee",
"price": 1299,
"image": "https://images.unsplash.com/..."
},
"quantity": 2
}
],
"total": "2598.00"
}POST /api/cartRequest Body:
{
"productId": "507f1f77bcf86cd799439013",
"quantity": 1
}Response:
{
"message": "Item added to cart",
"item": {
"_id": "507f1f77bcf86cd799439012",
"user": "507f1f77bcf86cd799439011",
"product": "507f1f77bcf86cd799439013",
"quantity": 1
}
}PUT /api/cart/:idRequest Body:
{
"quantity": 3
}Response:
{
"message": "Cart updated",
"item": { /* updated cart item */ }
}DELETE /api/cart/:idResponse:
{
"message": "Item removed from cart"
}POST /api/checkoutRequest Body:
{
"name": "Sam",
"email": "sam@example.com"
}Response:
{
"message": "Order placed successfully",
"receipt": {
"id": "ORD-1730983456789-ABC123",
"name": "sam",
"email": "sam@example.com",
"items": [
{
"name": "Oversized Graphic Tee",
"qty": 2,
"price": 1299
}
],
"total": "2598.00",
"timestamp": "2024-11-07T10:30:56.789Z"
}
}
Responsive product grid with pagination showing Gen Z streetwear collection
Clean authentication modal with form validation
Cart sidebar with quantity controls and real-time total calculation
Order confirmation modal with detailed receipt information
Automated order confirmation email sent via EmailJS
- MongoDB Atlas integration for production-ready cloud storage
- Mongoose schemas for Users, Products, CartItems, and Orders
- Automatic cart restoration on login
- Seeding script for initial 24 Gen Z products
- JWT-based authentication with 7-day token expiry
- Secure password hashing using bcryptjs (10 salt rounds)
- Protected routes middleware
- Persistent login state using localStorage
- Comprehensive try-catch blocks in all controllers
- User-friendly error messages with react-hot-toast
- Backend error logging for debugging
- 404 handling for invalid routes
- EmailJS integration for order confirmations
- Professional email template with order details
- Includes order ID, items list, total, and timestamp
- Fallback handling if email service is unavailable
- Loading states with spinners and animations
- Toast notifications for all user actions
- Responsive design (mobile, tablet, desktop)
- Smooth transitions and hover effects
- Organic UI with rounded corners and soft shadows
- Clean, modular code structure
- Minimal inline comments (as per requirements)
- ESLint configuration for code consistency
- Separation of concerns (MVC pattern)
- Reusable API utility with Axios interceptors
- Product search and filtering
- User profile and order history
- Product reviews and ratings
- Wishlist functionality
- Payment gateway integration (Stripe/Razorpay)
- Admin dashboard for product management
- Real-time stock tracking
- Social media authentication
- Advanced analytics and reporting
- Multi-language support
Rounak
- GitHub: [@Rounak87]
This project is created for the Vibe Commerce coding assignment and is available for educational purposes.