Jacobchristian guanzing/fullstack 5 plus#241
Open
jacobchristian17 wants to merge 7 commits intoZeff01:mainfrom
Open
Jacobchristian guanzing/fullstack 5 plus#241jacobchristian17 wants to merge 7 commits intoZeff01:mainfrom
jacobchristian17 wants to merge 7 commits intoZeff01:mainfrom
Conversation
Author
Author
Add README.md for E-Commerce Shopping Application with details on features, architecture, API contracts, and testing notes.
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.




Author: Jacob Christian Guanzing
Date: Feb. 17, 2025
E-Commerce Shopping Application
Take home assignment for Full Stack - 5 Year plus.
Table of Contents
Demo
Home Page
Product Detail Page
Cart & Checkout
Feature Scope
Core Features
User Flows
Browse Products:
Add to Cart:
Manage Cart:
Checkout:
Project Design
Tech Stack
Data Models
Data Storage Strategy
Architecture
Project Directory
The application follows a modular structure using Next.js App Router. The
app/directory contains pages, layouts, and API route handlers. Reusable UI components live incomponents/, while state management logic is organized instore/using Redux Toolkit slices. Type definitions are centralized intypes/, and product data with server-side stock management resides indata/.UI Component
The component hierarchy starts with a root layout that wraps the app in a StoreProvider for Redux state and a ThemeProvider for dark mode detection. The Header and CartSidebar are rendered globally, while page-specific content renders in the main area.
State Management
Data flows bidirectionally between React components and the Redux store, with cart state persisted to localStorage. Stock updates are handled through async thunks that call Next.js API route handlers, which interact with an in-memory product store on the server. On checkout, stock deductions are processed server-side and updated inventory levels are returned to sync the client.
API Contract
Products
GET /api/products
Retrieve all products or filter by category.
Query Parameters:
categoryResponse:
{ "success": true, "data": [ { "id": "1", "name": "Wireless Headphones", "description": "Premium wireless headphones...", "price": 199.99, "image": "https://images.unsplash.com/...", "category": "Electronics", "stock": 15, "rating": 4.5, "reviews": 128 } ] }Status Codes:
GET /api/products/[id]
Retrieve a single product by ID.
Path Parameters:
idResponse:
{ "success": true, "data": { "id": "1", "name": "Wireless Headphones", "description": "Premium wireless headphones...", "price": 199.99, "image": "https://images.unsplash.com/...", "category": "Electronics", "stock": 15, "rating": 4.5, "reviews": 128 } }Status Codes:
PATCH /api/products/[id]
Update product stock (deduct quantity).
Path Parameters:
idRequest Body:
{ "quantity": 2 }Response:
{ "success": true, "data": { "id": "1", "name": "Wireless Headphones", "stock": 13 } }Status Codes:
Checkout
POST /api/checkout
Process checkout and update inventory for all cart items.
Request Body:
{ "items": [ { "productId": "1", "quantity": 2 }, { "productId": "3", "quantity": 1 } ] }Response:
{ "success": true, "data": { "updatedStocks": { "1": 13, "3": 24 } } }Validation:
itemsarray must not be emptyproductId(string)quantity>= 1Status Codes:
Redux Store
The store is configured with two slices:
cartandproducts. The cart slice manages shopping cart items, totals, sidebar visibility, and checkout status. The products slice holds the product catalog with current stock levels.State is designed to be minimal and derived where possible. Cart totals are recalculated on each add/update action. The cart sidebar's open/close state is colocated with cart data for unified control.
Async operations use
createAsyncThunkfor checkout processing. ThecheckoutCartthunk posts cart items to the server, handles loading states viaisCheckingOut, clears the cart on success, and triggers stock updates in the products slice through extra reducers.The StoreProvider hydrates cart state from localStorage on mount and subscribes to store changes for automatic persistence. Products are fetched from the API on initial load to ensure stock levels reflect server state.
Test Notes
Testing Cases
Product Catalog
Product Details
Shopping Cart
Checkout
Cross-Browser Checkout Testing
To verify server-side stock handling, test product checkouts across multiple browsers simultaneously:
This confirms that stock is managed server-side and synchronized across all clients, not just stored in localStorage.