Skip to content

Cloderaldo pampanga/fullstack 5 plus#274

Open
letsclode wants to merge 27 commits intoZeff01:mainfrom
letsclode:cloderaldo-pampanga/fullstack-5-plus
Open

Cloderaldo pampanga/fullstack 5 plus#274
letsclode wants to merge 27 commits intoZeff01:mainfrom
letsclode:cloderaldo-pampanga/fullstack-5-plus

Conversation

@letsclode
Copy link
Copy Markdown

@letsclode letsclode commented Mar 21, 2026

Architecture Decisions

  1. Hybrid Component Architecture
    Strategic use of Next.js App Router to balance SEO, performance, and interactivity:

    • Server Components: Used for primary layouts (layout.tsx) and pages (page.tsx, products/[id]/page.tsx) to ensure minimal JavaScript is sent to the client, improving Core Web Vitals (LCP/FCP).
    • Client Components: Isolated to interactive elements (e.g., ProductContent for Cart logic, QuantitySelector, Navbar) keeping the client-side bundle lean.
  2. State Management & Optimistic Updates
    Chose Zustand for the Shopping Cart state:

    • Lightweight & Persistent: Minimal boilerplate compared to Redux, with persist middleware to automatically sync cart state to localStorage.
    • Optimistic Updates: Implemented optimistic UI updates for cart modifications (adding/removing, updating quantities) to provide instant feedback before server confirmation.
    • Modern Integration: Integrates seamlessly with React 19 concurrent features.
  3. API & Data Layer

    • Strict Boundaries: Components fetch data through API Routes (/api/products, /api/cart) rather than direct mock data access, enforcing separation of concerns.
    • Graceful Error Handling: Handlers for 404s (Product not found) and 400s (Invalid requests) with clear user feedback via React Hot Toast.

Performance Optimizations

  1. Advanced Image Optimization

    • Leveraged next/image equipped with proper priority, sizes, and alt properties.
    • Implemented Skeleton Loaders (ProductImageSkeleton) to mitigate Cumulative Layout Shift (CLS) during load times.
  2. Caching Strategies

    • Server-Side Caching: Utilized Cache-Control headers (stale-while-revalidate) in API routes.
    • TanStack Query: Applied for client-side data fetching and mutations ensuring immediate UI updates, robust caching, and background synchronization.
  3. Realistic UX Simulation

    • Mock APIs incorporate artificial delays to simulate real-world networking, allowing thorough testing of Suspense boundaries and loading states for a smooth perceived performance.

Technology Choices & Trade-offs

Technology Choices

  • Next.js 16.2 (App Router): Best-in-class SEO, Server Components support.
  • Tailwind CSS 4: Utility-first CSS for fast, modern styling.
  • TanStack Query: Powerful async state caching and synchronization.
  • Zustand: Lightweight global state management.
  • TypeScript: Strict type safety to catch bugs at compile-time.

Trade-offs

  1. Mock Data vs. Real Database: Utilized a modular mock data layer instead of a real database to speed up implementation logic while still proving data-fetching patterns works.
  2. Client-Side Persistence: Cart data is stored via localStorage for simplicity. A production environment might demand a server-side storage (e.g., Redis/Postgres) to sync a user's cart across multiple devices.
  3. Zustand vs. React Context: Although Context is built-in, Zustand prevents unnecessary re-renders of the entire component tree when only atomic state (like quantity) updates.

Uploading localhost_3000_products_1 (1).png…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants