A simple, modular e-commerce frontend built with HTML, CSS, and vanilla JavaScript (ES Modules). It lists products from a public API, supports filtering and search, and includes a cart UI with localStorage persistence. It also ships with basic login/register/contact forms and validation.
- Product listing: Fetches products from
fakestoreapi.comand renders responsive cards. - Product details: Deep link to a product page using URL query params (no backend required).
- Cart with localStorage: Add/remove items, increment/decrement quantity, total price, persistent across reloads.
- Filtering & search: Filter by rating count, rating score, price > average, and live text search.
- Responsive filters UI: Sidebar on desktop, slide-in panel on small screens.
- Forms & validation: Register/Login/Contact forms with live validation feedback.
- Animations & icons: Animate.css (with optional WOW.js) and Font Awesome icons.
- Languages: HTML5, CSS3, JavaScript (ES6 modules)
- Libraries (CDN):
- Bootstrap 5.3.x (layout & components)
- Font Awesome 7.x (icons)
- Animate.css 4.x (CSS animations)
- WOW.js (optional JS trigger for Animate.css; initialized only if present)
- SweetAlert2 (user-friendly alerts; used in forms)
- APIs:
- FakeStore API for products:
https://fakestoreapi.com/products - REST Countries (register form country list):
https://restcountries.com/v3.1/all?fields=name,cca2
- FakeStore API for products:
final project - remove card and filters/
├─ index.html # Landing page with hero + calls to action
├─ home.html # Products list + filters + cart panel
├─ product.html # Single product page
├─ contactus.html # Contact form page
├─ login.html # Login page
├─ register.html # Register page
├─ css/
│ ├─ index.css # Landing/marketing styles
│ ├─ cart.css # Cart-related styles
│ ├─ contactus.css # Contact page styles
│ └─ style.css # Shared/product page styles
├─ images/ # Static images
├─ js/
│ ├─ api.js # Base API URL (FakeStore)
│ ├─ createDom.module.js # Small DOM helper to create elements
│ ├─ filtering.module.js # All filtering logic
│ ├─ products.module.js # Load & render product list (cards)
│ ├─ cart.module.js # Cart state, rendering, persistence
│ ├─ script.js # Page glue: load, filter, totals, responsive filters
│ ├─ product.js # Product details page logic
│ ├─ validation.module.js # Reusable validation helpers
│ ├─ login.js # Login form logic + validation
│ ├─ register.js # Register form logic + validation + countries fetch
│ └─ contact.js # Contact form logic + validation
- Option A (recommended): Use VS Code Live Server (or any static server) and open
index.html. - Option B: Open
index.htmldirectly in a modern browser.
Notes:
- APIs are remote (CORS-enabled). A static server is recommended for a smoother experience.
- Ensure internet connectivity for CDNs (Bootstrap, Font Awesome, Animate.css, SweetAlert2) and APIs.
- Landing:
index.htmlincludes marketing hero and navigation tohome.html. - Products: Visit
home.htmlto load products and interact with filters/search. - Product details: Click “See More” on a product card to open
product.htmlwith all details passed via URL params. - Cart: Click the cart button (top-right) to open the offcanvas cart. Update quantities or remove items. Data persists in
localStorage. - Forms:
login.html,register.html,contactus.htmlinclude validation and SweetAlert2 feedback.
-
js/api.js- Exposes
API_URLpointing tohttps://fakestoreapi.com/products. - Customize this to switch product data source.
- Exposes
-
js/createDom.module.js- Tiny DOM factory:
createdom(tag, parent, text, classes, id, href, src, alt, cssText). - Returns the created element. Helps build UIs declaratively.
- Tiny DOM factory:
-
js/products.module.jsloadObjects(): Synchronously fetchesAPI_URLviaXMLHttpRequestand caches the array inobjects.- Returns
[]on failure. - Note: synchronous XHR blocks the main thread. It’s kept to match the original behavior; consider migrating to
fetch()async.
- Returns
takelist(list): Renders responsive product cards into#products. Each card includes image, title, price, category, a “See More” link, and an Add/Remove Cart button that reacts to current cart state.
-
js/cart.module.jsproductCart: Array state loaded fromlocalStorage.getItem("products").locaStorageSetter(list): Persists the cart.addToCart(product): Adds with defaults forquantityandtotal, persists, re-renders, and dispatchescart-updatedevent.removeProduct(id): Removes item by id.clearCart(): Empties the cart, persists, re-renders, and dispatchescart-updated.renderCart(list): Builds the cart UI in#cart. Supports +/- quantity and per-item total. Shows an empty state when applicable.
-
js/filtering.module.jsfiltering(objects, count, rate, price, input, avg, takelist)filters products:- Reviews > 300 (if
#countis checked) - Rating > 3 (if
#rateis checked) - Price > average (if
#priceis checked) - Live text match in title/description/category/price
- Reviews > 300 (if
- Calls
takelist()with the filtered array.
-
js/script.js- Page orchestrator used by
home.html:- Loads products and initially renders a loader then the grid via
takelist(). - Computes average price for the price filter display.
- Binds filter and search events to update the list.
- Manages cart offcanvas: renders, total price, clear button visibility, and
#productNumcounter. - Handles responsive filters panel for small screens.
- Subscribes to
cart-updatedto keep the UI in sync. - Initializes WOW.js if present:
new WOW({ animateClass: 'animate__animated', offset: 0 }).init();.
- Loads products and initially renders a loader then the grid via
- Page orchestrator used by
-
js/product.js- Reads all product details from URL params and populates the product page (
#img,#title,#description,#price,#cate,#rating). - Controls a single Add/Remove Cart button (
#productcart) based on cart membership. Reacts tocart-updated.
- Reads all product details from URL params and populates the product page (
-
js/validation.module.jscheckinputEmpty(id): Emptiness + error message/toggling classes.checkRegex(id, pattern, errorMsg): Regex validation with success/error UI feedback.
-
js/login.js- Validates email and password non-empty, email regex. On success shows SweetAlert then redirects to
home.html.
- Validates email and password non-empty, email regex. On success shows SweetAlert then redirects to
-
js/register.js- Loads country list from REST Countries API and populates a datalist.
- Validates all fields (emptiness + regex), checks terms & password confirmation.
- On success shows SweetAlert then redirects to
login.html.
-
js/contact.js- Validates Name/Email/Subject/Message with basic patterns, shows SweetAlert on success, and resets the form.
-
Root HTML pages
home.html: product grid, filters, offcanvas cart, totals, and clear button.product.html: single product details and add/remove cart button.login.html,register.html,contactus.html: respective forms and SweetAlert feedback; include cart offcanvas so the cart icon/num stays consistent.
-
css/*.cssindex.css: hero/landing section and general marketing styles used byindex.html.style.css: shared styles for product grid, filters, etc.cart.css: cart layout, item rows, totals.contactus.css: dedicated styling for the contact page.
-
FakeStore API
- Base URL:
https://fakestoreapi.com/products - Used in
js/api.js→ consumed injs/products.module.jsvialoadObjects(). - Expected shape per product (simplified):
{ "id": 1, "title": "...", "price": 10.99, "description": "...", "category": "...", "image": "https://...", "rating": { "rate": 3.9, "count": 120 } }
- Base URL:
-
REST Countries
- URL:
https://restcountries.com/v3.1/all?fields=name,cca2 - Used in
js/register.jsto populate the countries datalist. Falls back to a static subset if the API fails.
- URL:
- Change product API source: Edit
js/api.js→API_URL. - Initial loading UX: Update the loader markup in
js/script.js(products.innerHTMLblock) and its CSS. - Product card UI: Edit markup generation inside
js/products.module.js→takelist(); adjust classes and structure as needed. - Cart storage key:
localStoragekey is"products"injs/cart.module.js. Rename if you need multiple carts. - Cart behavior: Tweak quantity logic and totals in
js/cart.module.js(renderCart()andaddToCart()). - Filters thresholds: Update checks in
js/filtering.module.js(e.g., rating count> 300, rate> 3). - Search fields: Modify the fields used in text filtering in
js/filtering.module.js. - Responsive filters: CSS and toggle behavior live in
css/style.cssandjs/script.js(filterMeda()andbindToggle()). - Form regex rules: Update patterns & messages in
js/validation.module.js,js/login.js,js/register.js,js/contact.js. - CDN versions: You can pin or upgrade Bootstrap/FA/Animate/SweetAlert2 in each HTML file’s
<head>or before</body>.
loadObjects()uses a synchronous XHR to keep the original behavior. For production, preferfetch()with proper loading states.- Some pages use SweetAlert2 (
Swal). Ensure its CDN script is included on those pages. - WOW.js is initialized only if present. If you want scroll-triggered animations, include WOW.js CDN before
js/script.js.
This project is for educational/demo purposes (workshop). Use and adapt freely.
- End-user licensing: see
LICENSE.md(Commercial EULA). You are granted a non-transferable license to create one End Product per license. - Third-party licenses and attributions: see
CREDITS.md(Bootstrap, Font Awesome, Animate.css, WOW.js, SweetAlert2, FakeStore API, REST Countries).
- Scope: installation help, usage questions for built-in features, and bug fixes reproducible in a clean copy.
- Exclusions: custom features, backend integrations, server configuration.
- Response time: within 2 business days. See
SUPPORT.mdfor details.
- Tested on latest stable versions of Chrome, Edge, and Firefox.
- Progressive enhancement: animations and certain APIs are optional; the core experience (listing, cart, forms) works without WOW.js.
- Fallbacks: if external APIs are unavailable, consider adding
data/products.jsonand switchingAPI_URLto local data.
Suggested distribution structure:
item/
├─ main/
│ ├─ index.html
│ ├─ home.html
│ ├─ product.html
│ ├─ contactus.html
│ ├─ login.html
│ ├─ register.html
│ ├─ css/
│ ├─ js/
│ ├─ vendor/ # local copies of Bootstrap/FA/Animate/WOW/SweetAlert2 (optional)
│ ├─ images/
│ └─ data/ # products.json fallback (optional)
├─ documentation/
│ └─ index.html
├─ CHANGELOG.md
├─ LICENSE.md
├─ CREDITS.md
└─ SUPPORT.md