DEV Community

Robson Muniz
Robson Muniz

Posted on

Building a Production-Ready E-Commerce Platform with React: A Complete Walkthrough

๐Ÿ›๏ธ How I Built a Production-Ready E-Commerce Platform with React (And You Can Too!)

ShopStyle Demo

TL;DR: I built a complete e-commerce frontend called ShopStyle using React 18, Tailwind CSS, and modern patterns. It features real-time search, a persistent cart, dark mode, and 60fps animations. This article breaks down the architecture, challenges, and key decisions.

Live Demo โ€ข GitHub


๐ŸŽฏ The Challenge

"How hard could it be?" I asked myself before building an e-commerce platform from scratch. The answer: delightfully challenging.

My goals were to:

  1. Create a realistic shopping experience with real product data
  2. Implement modern React patterns (not just another Todo app)
  3. Focus on performance (95+ Lighthouse score target)
  4. Make it beautiful with smooth animations and responsive design
  5. Keep the code maintainable with clean architecture

Hereโ€™s what I built and how I did it.


๐Ÿš€ The Result: ShopStyle

๐Ÿ”— Live Demo โ€ข ๐Ÿ’ป Source Code

Key Features

  • โœ… Real-time search with DummyJSON API
  • โœ… Persistent shopping cart (localStorage + cross-tab sync)
  • โœ… Dark / light mode with system preference detection
  • โœ… 60fps animations using Framer Motion
  • โœ… Fully responsive, mobile-first design
  • โœ… Performance optimized (95+ Lighthouse score)

๐Ÿ—๏ธ Architecture Overview

graph TB
    A[App.jsx] --> B[ThemeContext]
    A --> C[ProductContext]
    A --> D[CartContext]

    C --> E[ProductList]
    E --> F[ProductCard]

    D --> G[CartSidebar]
    D --> F

    H[SearchBar] --> I((DummyJSON API))
    I --> C

    B --> A
Enter fullscreen mode Exit fullscreen mode


`

Each context handles a single responsibility, keeping components focused, reusable, and easy to reason about.


โš™๏ธ Tech Stack Decisions

Technology Why I Chose It Alternative
React 18 Stable ecosystem, concurrent features Vue, Svelte
Vite Lightning-fast DX CRA
Tailwind CSS Speed + consistency Styled Components
Context API Perfect for mid-size apps Redux, Zustand
Framer Motion Declarative animations React Spring
DummyJSON Realistic fake data MSW

๐Ÿ’ก Implementation Deep Dives

๐Ÿ” Real-Time Search with Debounce

`

import { useState, useEffect } from "react";

const SearchBar = ({ onSearch }) => {
  const [query, setQuery] = useState("");
  const [debouncedQuery, setDebouncedQuery] = useState("");

  useEffect(() => {
    const timer = setTimeout(() => setDebouncedQuery(query), 300);
    return () => clearTimeout(timer);
  }, [query]);

  useEffect(() => {
    if (!debouncedQuery.trim()) {
      onSearch(null);
      return;
    }

    const search = async () => {
      try {
        const res = await fetch(
          `https://dummyjson.com/products/search?q=${debouncedQuery}`
        );
        const data = await res.json();
        onSearch(data.products);
      } catch {
        onSearch([]);
      }
    };

    search();
  }, [debouncedQuery, onSearch]);

  return (
    <input
      value={query}
      onChange={(e) => setQuery(e.target.value)}
      placeholder="Search products..."
      className="w-full px-4 py-2 border rounded-lg"
    />
  );
};
export default SearchBar;
Enter fullscreen mode Exit fullscreen mode

๐Ÿ›’ Persistent Cart with Cross-Tab Sync

import { useState, useEffect } from "react";

const [cart, setCart] = useState(() => {
  const stored = localStorage.getItem("shopstyle-cart");
  return stored ? JSON.parse(stored) : [];
});

useEffect(() => {
  localStorage.setItem("shopstyle-cart", JSON.stringify(cart));
}, [cart]);

useEffect(() => {
  const sync = (e) => {
    if (e.key === "shopstyle-cart") {
      setCart(JSON.parse(e.newValue || "[]"));
    }
  };
  window.addEventListener("storage", sync);
  return () => window.removeEventListener("storage", sync);
}, []);
Enter fullscreen mode Exit fullscreen mode

๐ŸŒ— Theme System (System-Aware)

import { useState, useEffect, useCallback } from "react";

const [theme, setTheme] = useState(() => {
  const saved = localStorage.getItem("shopstyle-theme");
  if (saved) return saved;
  return window.matchMedia("(prefers-color-scheme: dark)").matches
    ? "dark"
    : "light";
});

useEffect(() => {
  document.documentElement.className = theme;
  localStorage.setItem("shopstyle-theme", theme);
}, [theme]);

const toggleTheme = useCallback(() => {
  setTheme((prev) => (prev === "light" ? "dark" : "light"));
}, []);
Enter fullscreen mode Exit fullscreen mode

โšก Performance Optimizations

Memoized Product Cards

import { memo } from "react";

const ProductCard = memo(({ product }) => {
  return <div>{product.title}</div>;
});

export default ProductCard;
Enter fullscreen mode Exit fullscreen mode

Virtualized Lists for Large Catalogs

import { FixedSizeList as List } from "react-window";

const VirtualProductList = ({ products }) => (
  <List height={600} itemCount={products.length} itemSize={350} width="100%">
    {({ index, style }) => (
      <div style={style}>
        <ProductCard product={products[index]} />
      </div>
    )}
  </List>
);
Enter fullscreen mode Exit fullscreen mode

๐Ÿงช Lighthouse Scores

Metric Score
Performance 96
Accessibility 100
Best Practices 100
SEO 92

๐Ÿš€ Deployment

vercel --prod
Enter fullscreen mode Exit fullscreen mode

Vercel handled builds, previews, routing, and performance out of the box.


๐Ÿค” Lessons Learned

  • Cart sync across tabs requires storage events
  • Animations should stick to transform and opacity
  • Always plan for API failure and caching

๐Ÿ”ฎ Whatโ€™s Next

  1. Backend (Node + PostgreSQL)
  2. Stripe payments
  3. PWA support
  4. Internationalization

๐Ÿ› ๏ธ Run It Locally

git clone https://github.com/yourusername/shopstyle.git
cd shopstyle
npm install
npm run dev
Enter fullscreen mode Exit fullscreen mode

๐Ÿ’ฌ Letโ€™s Talk

  • What would you improve?
  • How do you manage state in large React apps?
  • Want a backend follow-up?

Drop a comment ๐Ÿ‘‡


๐Ÿ™ Thanks

Huge thanks to React, Tailwind, DummyJSON, and the DEV community โค๏ธ


โญ Star the repo
๐Ÿ”„ Share with friends
๐Ÿฆ Follow for more content

Happy coding โ€” the best project is the one you actually finish. ๐Ÿš€

react #javascript #webdev #tutorial #ecommerce #frontend

Top comments (0)