π E-Commerce Advanced Website
π Table of Contents
- Project Overview
- Technologies Used
- Project Architecture
- Detailed Features
- How the Project Works
- File Structure Explanation
- Implementation Details
- Setup and Installation
- API Integration
- Key Concepts Used
- Challenges Faced
- Future Enhancements
π― Project Overview
This is a full-featured E-Commerce website built using HTML, CSS, JavaScript for the frontend, with backend capabilities using Node.js/Express and Spring Boot integration. The project demonstrates a complete online shopping platform with product browsing, cart management, user authentication, and order processing.
Main Objectives:
- Create a responsive, user-friendly e-commerce platform
- Implement dynamic content loading and rendering
- Build a functional shopping cart with local storage
- Integrate with external APIs for product data
- Demonstrate modular code architecture
π οΈ Technologies Used
Frontend Technologies:
- HTML5 - Structure and semantic markup
- CSS3 - Styling and responsive design
- JavaScript (ES6+) - Client-side logic and DOM manipulation
Libraries and Frameworks:
- jQuery 3.4.1 - DOM manipulation and AJAX
- Slick Carousel - Image slider functionality
- Font Awesome - Icons
- Google Fonts (Lato, Poppins) - Typography
Backend Technologies:
- Node.js - JavaScript runtime
- Express.js - Web application framework
- Spring Boot (Maven wrapper included) - Java-based backend
- Axios - HTTP client for API requests
- CryptoJS - Cryptographic functions for API authentication
Data Storage:
- localStorage - Browser storage for cart and user data
- Cookies - Session management
- MockAPI - External API for product data (https://5d76bf96515d1a0014085cf9.mockapi.io/product)
- FakeStore API - Alternative product API
Development Tools:
- Maven Wrapper - Build automation for Java
- Git - Version control
- VS Code - Code editor
ποΈ Project Architecture
Architecture Pattern: Modular Component-Based Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β PRESENTATION LAYER (Frontend) β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β Header β β Slider β β Footer β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββ β
β β Product Display (content.js) β β
β ββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β BUSINESS LOGIC LAYER β
β ββββββββββββββββ ββββββββββββββββ β
β β Cart Logic β β Auth Logic β β
β ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATA LAYER β
β ββββββββββββββββ ββββββββββββββββ β
β β localStorage β β Cookies β β
β ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β EXTERNAL SERVICES LAYER β
β ββββββββββββββββ ββββββββββββββββ β
β β MockAPI β β Amazon API β β
β ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β¨ Detailed Features
1. Dynamic Component Loading
- What it does: Loads header, footer, slider, and content sections dynamically
- Why it's useful: Code reusability and easier maintenance
- How it works: Uses XMLHttpRequest to fetch HTML content and inject it into the DOM
2. Product Catalog
- Displays products fetched from external API
- Categorizes products (Clothing vs Accessories)
- Shows product preview, name, brand, and price
- Links to detailed product pages
3. Product Details Page
- Full product information display
- Multiple product images with preview functionality
- Click-to-enlarge image feature
- Add to cart functionality
- Dynamic price display
4. Shopping Cart System
- Add/remove products
- Update product quantities
- Calculate subtotals and taxes
- Persistent cart (uses localStorage)
- Cart badge counter showing total items
- Checkout functionality
5. Image Slider
- Auto-playing carousel using Slick Carousel
- Responsive design
- Touch/swipe enabled
- Dots navigation
6. User Authentication
- Login/Signin page
- User session management using localStorage
- Dynamic navigation (Sign In β Account when logged in)
7. Order Management
- Order placement page
- Clears cart after checkout
- Order confirmation
8. Responsive Design
- Mobile-first approach
- Breakpoints for different screen sizes
- Touch-friendly interface
π§ How the Project Works
Step-by-Step Flow:
1. Application Initialization (index.html)
User visits website
β
index.html loads
β
JavaScript executes load() functions
β
Header, Slider, Content, Footer components are fetched and injected
β
Slick Carousel initializes
β
Product data is fetched from API
β
Products are dynamically rendered on page
2. Dynamic Content Loading Process
function load(id, url) {
let req = new XMLHttpRequest();
req.open("GET", url, false); // Synchronous request
req.send(null);
document.getElementById(id).innerHTML = req.responseText;
}
Explanation:
- Creates XMLHttpRequest object
- Opens synchronous GET request to fetch HTML file
- Sends request
- Injects response into target element
3. Product Display Mechanism (content.js)
Process:
XMLHttpRequest β MockAPI β JSON Response β Parse Data β Loop through products β Create DOM elements β Append to container
Code breakdown:
httpRequest.onreadystatechange = function() {
if (this.readyState === 4 && this.status == 200) {
contentTitle = JSON.parse(this.responseText);
for (let i = 0; i < contentTitle.length; i++) {
if (contentTitle[i].isAccessory) {
containerAccessories.appendChild(
dynamicClothingSection(contentTitle[i])
);
} else {
containerClothing.appendChild(
dynamicClothingSection(contentTitle[i])
);
}
}
}
};
What happens:
- Sends async HTTP request to MockAPI
- Waits for readyState = 4 (complete) and status = 200 (success)
- Parses JSON response
- Loops through each product
- Checks if product is accessory or clothing
- Creates HTML structure using
dynamicClothingSection()
- Appends to appropriate container
4. Cart Management System
Data Structure (localStorage):
cart = [
{ id: 1, quantity: 2 },
{ id: 5, quantity: 1 },
{ id: 8, quantity: 3 }
]
Add to Cart Flow:
User clicks "Add to Cart"
β
Retrieve cart from localStorage
β
Check if product already exists in cart
β
If exists β Increment quantity
If not β Add new item with quantity 1
β
Save updated cart to localStorage
β
Update cart badge counter
β
Visual feedback to user
Implementation:
buttonTag.onclick = function() {
let cart = JSON.parse(localStorage.getItem('cart')) || [];
let existing = cart.find(item => item.id == ob.id);
if (existing) {
existing.quantity += 1;
} else {
cart.push({ id: ob.id, quantity: 1 });
}
localStorage.setItem('cart', JSON.stringify(cart));
let counter = cart.reduce((sum, item) => sum + item.quantity, 0);
document.getElementById('badge').innerHTML = counter;
}
5. Checkout Process
User clicks Checkout button
β
Clear cart from localStorage
β
Reset badge counter to 0
β
Redirect to orderPlaced.html
β
Show order confirmation
π File Structure Explanation
HTML Files:
index.html - Main landing page
- Entry point of application
- Loads all components dynamically
- Initializes Slick Carousel
- Contains navigation links
product.html - Product listing page
- Displays all products
- Shows cart count in header
- Standalone product browsing
cart.html - Shopping cart page
- Shows added products
- Quantity modification
- Price calculation with tax
- Checkout button
contentDetails.html - Product detail page
- Individual product information
- Image gallery
- Add to cart functionality
signin.html - User authentication
- Login form
- Input validation
- User session creation
orderPlaced.html - Order confirmation
- Thank you message
- Order summary
- Navigation back to shopping
Component Files (Loaded Dynamically):
- header.html - Navigation bar and branding
- footer.html - Footer information and links
- slider.html - Image carousel structure
- content.html - Product grid containers
JavaScript Files:
content.js - Product rendering logic
- Fetches products from API
- Creates dynamic HTML elements
- Handles product categorization
- Updates cart badge
contentDetails.js - Product detail functionality
- Displays single product information
- Image preview switching
- Add to cart implementation
- URL parameter parsing
cart.js - Cart management
- Retrieves cart from localStorage
- Renders cart items
- Calculates totals and tax
- Quantity update handlers
- Remove item functionality
product.js - Product page logic
- Server-side product routing (Express)
- Amazon API integration
- Error handling
amezonAPI.js - Amazon API integration
- AWS4-HMAC-SHA256 authentication
- Product data fetching
- API request signing with CryptoJS
index.js - React initialization (if using React components)
- React DOM rendering
- Context provider setup
- Browser router configuration
CSS Files:
- cart.css - Cart page styling
- content.css - Product grid styling
- contetDetails.css - Product detail page styling
- footer.css - Footer styling
- header.css - Header/navbar styling
- orderPlaced.css - Order confirmation styling
Configuration Files:
- mvnw, mvnw.cmd - Maven wrapper for Spring Boot
- HELP.md - Spring Boot help documentation
- .gitignore - Git ignore patterns
π‘ Implementation Details
1. Dynamic DOM Creation
Instead of static HTML, I used JavaScript to create elements programmatically:
function dynamicClothingSection(ob) {
let boxDiv = document.createElement("div");
boxDiv.id = "box";
let boxLink = document.createElement("a");
boxLink.href = "/contentDetails.html?" + ob.id;
let imgTag = document.createElement("img");
imgTag.src = ob.preview;
let h3 = document.createElement("h3");
let h3Text = document.createTextNode(ob.name);
h3.appendChild(h3Text);
boxDiv.appendChild(boxLink);
boxLink.appendChild(imgTag);
// ... more elements
return boxDiv;
}
Why this approach?
- Single source of truth for product display
- Easy to update all products at once
- Consistent styling and structure
- Scalable for hundreds of products
2. localStorage for Cart Persistence
Why localStorage?
- Data persists across browser sessions
- No server required for stor