GitHunt
PR

ProgrammerSiam/ps-Ecommerce

A modern, full-featured e-commerce dashboard built with Next.js 15, TypeScript, Tailwind CSS, and React Context for state management.

E-Commerce Dashboard

A modern, full-featured e-commerce dashboard built with Next.js 15, TypeScript, Tailwind CSS, and React Context for state management.

๐Ÿš€ Features

Core Functionality

  • Product Listing: Browse all products with responsive grid layout
  • Product Details: Comprehensive product pages with add-to-cart functionality
  • Category Filtering: Filter products by category with real-time updates
  • Search Functionality: Search products by title and description
  • Sorting Options: Sort by name, price (low/high), and rating
  • Shopping Cart: Add, remove, and update quantities with persistent state
  • Add Products: Form to add new products with validation
  • Pagination: Navigate through large product catalogs

Technical Features

  • Next.js 15 with App Router for modern React development
  • TypeScript for type safety and better developer experience
  • Tailwind CSS for responsive, utility-first styling
  • React Context for global state management
  • TanStack Query for efficient data fetching and caching
  • Image Optimization with Next.js Image component
  • Responsive Design that works on all devices

๐Ÿ› ๏ธ Tech Stack

  • Framework: Next.js 15 (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS
  • State Management: React Context + TanStack Query
  • API: FakeStore API (https://fakestoreapi.com)
  • Deployment: Vercel-ready

๐Ÿ“ฆ Installation & Setup

Prerequisites

  • Node.js 18+
  • npm or yarn

Quick Start

  1. Clone the repository

    git clone <repository-url>
    cd yoooooo
  2. Install dependencies

    npm install
  3. Run the development server

    npm run dev
  4. Open your browser
    Navigate to http://localhost:3000

Available Scripts

  • npm run dev - Start development server
  • npm run build - Build for production
  • npm run start - Start production server
  • npm run lint - Run ESLint

๐Ÿ—๏ธ Project Structure

src/
โ”œโ”€โ”€ app/                    # Next.js App Router pages
โ”‚   โ”œโ”€โ”€ layout.tsx         # Root layout with providers
โ”‚   โ”œโ”€โ”€ page.tsx           # Home page
โ”‚   โ”œโ”€โ”€ products/          # Product pages
โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx       # Product listing
โ”‚   โ”‚   โ””โ”€โ”€ [id]/          # Dynamic product detail
โ”‚   โ”œโ”€โ”€ cart/              # Cart page
โ”‚   โ””โ”€โ”€ add-product/       # Add product form
โ”œโ”€โ”€ components/            # Reusable components
โ”‚   โ””โ”€โ”€ Header.tsx         # Navigation header
โ”œโ”€โ”€ context/              # React Context providers
โ”‚   โ””โ”€โ”€ CartContext.tsx    # Cart state management
โ”œโ”€โ”€ hooks/                # Custom React hooks
โ”‚   โ””โ”€โ”€ useProducts.ts     # Data fetching hooks
โ””โ”€โ”€ styles/               # Global styles
    โ””โ”€โ”€ globals.css        # Tailwind CSS imports

๐ŸŽจ Design Choices & Architecture

State Management

  • React Context: Used for cart state management due to its simplicity and built-in React support
  • TanStack Query: Implemented for server state management with caching, retries, and background updates

Component Architecture

  • Functional Components: Modern React with hooks
  • TypeScript: Full type safety for better development experience
  • Responsive Design: Mobile-first approach with Tailwind CSS

Data Fetching Strategy

  • TanStack Query: Provides caching, background updates, and error handling
  • Optimistic Updates: Cart updates are immediate for better UX
  • Error Boundaries: Graceful error handling with retry mechanisms

Performance Optimizations

  • Image Optimization: Next.js Image component with proper sizing
  • Code Splitting: Automatic with Next.js App Router
  • Caching: TanStack Query provides intelligent caching
  • Lazy Loading: Images and components load as needed

๐Ÿ”ง Configuration

Environment Variables

No environment variables required for this demo. The app uses the public FakeStore API.

Tailwind Configuration

Custom Tailwind config with:

  • Custom color palette
  • Responsive breakpoints
  • Custom utilities

Next.js Configuration

  • Image domains configured for FakeStore API
  • TypeScript strict mode enabled
  • ESLint configuration

๐Ÿš€ Deployment

  1. Push your code to GitHub
  2. Connect your repository to Vercel
  3. Deploy automatically

Manual Deployment

npm run build
npm run start

๐ŸŽฏ Features Breakdown

1. Product Listing (/products)

  • Search: Real-time search by title and description
  • Filtering: Category-based filtering
  • Sorting: Multiple sort options (name, price, rating)
  • Pagination: 12 items per page with navigation
  • Responsive Grid: Adapts to screen size

2. Product Details (/products/[id])

  • Comprehensive Info: Title, price, description, category, rating
  • Add to Cart: Quantity selection and cart integration
  • Image Gallery: Optimized product images
  • Error Handling: Graceful 404 and error states

3. Shopping Cart (/cart)

  • Item Management: Add, remove, update quantities
  • Price Calculation: Real-time total calculation
  • Empty State: Helpful messaging when cart is empty
  • Order Summary: Subtotal, shipping, and total

4. Add Product (/add-product)

  • Form Validation: Client-side validation with error messages
  • API Integration: POST request to FakeStore API
  • Success Feedback: Success message with auto-redirect
  • Category Selection: Dropdown with predefined categories

๐Ÿ”ฎ Future Improvements

Performance Enhancements

  • Server-Side Rendering: Implement SSR for better SEO
  • Static Generation: Pre-render product pages
  • Incremental Static Regeneration: Update content without full rebuild
  • Bundle Optimization: Code splitting and tree shaking

Feature Additions

  • User Authentication: Login/signup system
  • Wishlist: Save products for later
  • Product Reviews: User-generated reviews and ratings
  • Advanced Search: Filters, price range, ratings
  • Checkout Process: Payment integration
  • Order History: Track past purchases
  • Admin Dashboard: Manage products and orders

Technical Improvements

  • Testing: Unit and integration tests
  • Error Monitoring: Sentry or similar service
  • Analytics: User behavior tracking
  • PWA: Progressive Web App features
  • Internationalization: Multi-language support
  • Accessibility: WCAG compliance improvements

State Management

  • Zustand: Consider replacing Context for complex state
  • Redux Toolkit: For larger applications
  • Server State: Expand TanStack Query usage

๐Ÿ› Known Issues

  • FakeStore API is for demo purposes only
  • No real backend integration
  • Cart state resets on page refresh (could be fixed with localStorage)

๐Ÿ“ Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿ™ Acknowledgments


Built with โค๏ธ using Next.js, TypeScript, and Tailwind CSS