A modern, responsive coffee shop e-commerce application built with React, featuring a shopping cart system with real-time updates and smooth user experience.
- Product Catalog: Browse a curated selection of coffee drinks
- Shopping Cart: Add, remove, and adjust quantities of items
- Real-time Updates: Cart count updates instantly in the navbar
- Persistent State: Cart state managed with React Context API
- Responsive Design: Mobile-first design with Tailwind CSS
- Routing: Multi-page navigation with React Router
- Clean UI: Coffee-themed color palette with smooth interactions
- React 18 - UI library with hooks
- React Router - Client-side routing
- Context API - Global state management
- Tailwind CSS - Utility-first styling
- Vite - Fast build tool and dev server
- Node.js 16+
- npm or yarn
npm installnpm run devThe app will be available at http://localhost:5173
npm run buildnpm run previewsrc/
βββ components/ # Reusable UI components
β βββ Navbar.jsx # Navigation with cart count
β βββ CoffeeList.jsx # Coffee product grid
β βββ CoffeeCard.jsx # Individual coffee item card
β βββ Cart.jsx # Cart display and management
βββ context/ # Global state management
β βββ CartContext.jsx # Cart state and operations
βββ pages/ # Page components
β βββ Home.jsx # Main store page
β βββ CartPage.jsx # Cart checkout page
βββ assets/ # Static assets
β βββ react.svg # React logo
βββ App.jsx # Main app component with routing
βββ main.jsx # App entry point
βββ index.css # Global styles (Tailwind import)
The app uses a coffee-inspired color scheme:
- Primary Brown:
#3e2723(Navbar background) - Coffee Brown:
#6f4e37(Buttons, accents) - Background:
#f5f5f5(Light gray) - White:
#ffffff(Cards, text)
Global state management for the shopping cart:
const { cart, addToCart, incrementItem, decrementItem, clearCart } = useCart();Available functions:
addToCart(coffee)- Add item to cart or increment if existsincrementItem(id)- Increase quantity by 1decrementItem(id)- Decrease quantity by 1 (removes if 0)clearCart()- Empty entire cart
Individual product card with:
- Coffee name and description
- Price display
- "Add to Cart" button
- Hover effects
Top navigation featuring:
- Store branding
- Cart link with live item count
- Clear cart button (disabled when empty)
- Responsive layout
Shopping cart display with:
- Empty state message
- Item list with quantities
- Increment/decrement controls
- Price calculations
| Coffee | Description | Price |
|---|---|---|
| Espresso | Strong and bold coffee | Rs. 149 |
| Cappuccino | Rich and foamy coffee | Rs. 199 |
| Latte | Smooth and creamy coffee | Rs. 179 |
- Click "Add to Cart" on any coffee card
- Item appears in cart with quantity 1
- Subsequent clicks increment quantity
- Use
+button to increase quantity - Use
-button to decrease quantity - Item automatically removes when quantity reaches 0
- Click "Clear Cart" in navbar to empty entire cart
- Button is disabled when cart is empty
Home Page (/)
β
Browse Coffee Selection
β
Add Items to Cart
β
View Cart Count in Navbar
β
Navigate to Cart Page (/cart)
β
Adjust Quantities
β
Clear Cart (optional)
Edit src/components/CoffeeList.jsx:
const coffees = [
// ... existing coffees
{
id: 4,
name: "Americano",
description: "Bold and smooth coffee",
price: 129,
},
];Update Tailwind classes in components:
// Example: Change button color
className="bg-[#6f4e37]" // Replace with your colorCommon enhancements:
- Product images
- Search/filter functionality
- Checkout process
- Order history
- User authentication
- Price totals and tax calculations
The app is fully responsive with breakpoints:
- Mobile: Single column layout
- Tablet: 2 columns (md: breakpoint)
- Desktop: 3 columns grid
- Cart data is not persisted (resets on page refresh)
- No backend integration
- No payment processing
- Limited to 3 products
- LocalStorage persistence
- Product images
- Checkout flow
- Order summary with totals
- Product details modal
- User reviews and ratings
- Wishlist functionality
- Backend API integration
- Payment gateway
- Order tracking
import { useCart } from './context/CartContext';
function MyComponent() {
const { cart, addToCart } = useCart();
const handleAdd = () => {
addToCart({
id: 1,
name: "Espresso",
description: "Strong coffee",
price: 149
});
};
return (
<div>
<p>Cart items: {cart.length}</p>
<button onClick={handleAdd}>Add Coffee</button>
</div>
);
}The app includes basic error boundaries:
- Context usage validation (must be inside provider)
- Empty cart state handling
- Disabled buttons for invalid states
This project demonstrates:
- React Hooks (useState, useContext, useReducer pattern)
- Context API for state management
- React Router for navigation
- Tailwind CSS utility classes
- Component composition
- Conditional rendering
- Event handling
Contributions welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add some AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open source and available under the MIT License.
- Built with React and Vite
- Styled with Tailwind CSS
- Icons and design inspired by modern e-commerce UIs
Happy Coding! β
For questions or suggestions, please open an issue or submit a pull request.