Implement product page with cart functionality#253
Open
fingersandmind wants to merge 2 commits intoZeff01:mainfrom
Open
Implement product page with cart functionality#253fingersandmind wants to merge 2 commits intoZeff01:mainfrom
fingersandmind wants to merge 2 commits intoZeff01:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Full e-commerce storefront built with Next.js 16 (App Router), TypeScript, and Tailwind CSS v4.
Architecture Decisions
Server vs Client Component Split
Pages that only render data (home, product detail, confirmation) use server components by default. Interactive elements (cart drawer, add-to-cart button,
checkout page) are isolated as client components with
"use client". This keeps the JS bundle small — only interactive code ships to the browser.State Management — Context + useReducer
Cart state uses React Context with
useReducerrather than a third-party library. For a cart with a small, predictable action set(add/remove/update/clear/hydrate), this avoids unnecessary dependencies while keeping state transitions explicit and testable.
useCallbackmemoizesdispatch wrappers to prevent unnecessary re-renders.
localStorage Persistence
Cart hydrates from
localStorageon mount and syncs on every change. This gives persistence across page refreshes without needing a database or cookies, andavoids hydration mismatches by starting with an empty state and hydrating client-side via
useEffect.Static Generation with
generateStaticParamsProduct detail pages are statically generated at build time since the product catalog is fixed. This gives instant page loads with zero server cost. Dynamic
metadata (
generateMetadata) provides proper SEO for each product.API Route Validation
The
POST /api/cartendpoint validates that the product exists and has sufficient stock before confirming the add-to-cart action. This mirrors a realbackend validation layer, even though the data is in-memory.
Performance Optimizations
next/imagewith explicitsizeshints for responsive image optimization and lazy loadinggenerateStaticParams— zero runtime server costloading.tsx) for product detail page to eliminate layout shift during navigationbackdrop-blur-sm) instead of JSTrade-offs
lib/products.ts). This simplifies the assessment but means no search, filtering, or pagination. Inproduction, this would be backed by a database with proper query capabilities.
avoids the complexity of server-side session management for this scope.
Screenshots
Homepage
Product
Cart
Checkout (not included in the assessment, but why not)
Test Plan
/checkoutwith correct order summary/checkoutwith empty cart redirects to/bun run buildpasses with no errors