A comprehensive full-stack e-commerce project built with vanilla JavaScript, HTML, and CSS. This project demonstrates modern web development practices including object-oriented programming, asynchronous operations, state management, and automated testing with Jasmine.
- Project Overview
- Features
- Project Structure
- Technologies Used
- Getting Started
- Key Components
- Architecture
- Testing
- Git Integration
This is an Amazon-like e-commerce web application that allows users to:
- Browse a product catalog
- Add/remove items from shopping cart
- Select delivery options
- View order summary and payment details
- Process orders
- Track order history
The project demonstrates professional JavaScript development practices with modular code, separation of concerns, and comprehensive test coverage using the Jasmine testing framework.
- Product Catalog: Display products with images, ratings, and pricing
- Shopping Cart: Add, remove, and update product quantities with persistent storage
- Product Classes: Supports different product types (Clothing, Appliance) with inheritance
- Delivery Options: Multiple delivery methods with different pricing and timeframes
- Order Management: Create and track orders with detailed summaries
- Search Functionality: Filter and search products by name
- Price Formatting: Accurate currency conversion and display
- Persistent Storage: LocalStorage for cart and order data
- Responsive Design: Works on desktop, tablet, and mobile devices
- Async Operations: Fetch products from backend/API with promises
- Object-Oriented Design: Class-based architecture with inheritance
- Module System: ES6 modules for code organization
- State Management: Centralized cart and order state
- Event-Driven Architecture: Custom events for component communication
- API Integration: Support for backend data loading via XMLHttpRequest and Fetch API
- Automated Testing: Comprehensive Jasmine test suite with mocks and spies
javascript-amazon-project/
βββ amazon.html # Main product catalog page
βββ checkout.html # Checkout page
βββ orders.html # Order history page
βββ tracking.html # Order tracking page
β
βββ data/ # Data layer and state management
β βββ products.js # Product data, classes, and loader
β βββ cart.js # Cart state (functional approach)
β βββ cart-class.js # Cart state (OOP approach)
β βββ cart-oop.js # Alternative OOP implementation
β βββ orders.js # Order management and storage
β βββ deliveryOptions.js # Delivery method definitions
β βββ backend-practice.js # Backend integration examples
β
βββ Scripts/ # Business logic and UI rendering
β βββ amazon.js # Product grid rendering and cart interactions
β βββ checkout.js # Checkout page orchestration
β βββ orders.js # Order history rendering
β βββ tracking.js # Order tracking display
β βββ checkout/ # Checkout-specific modules
β β βββ orderSummary.js # Order summary rendering
β β βββ paymentSummary.js # Payment calculations and display
β βββ utils/ # Utility functions
β βββ money.js # Currency formatting
β βββ search.js # Search functionality
β
βββ styles/ # CSS styling
β βββ pages/ # Page-specific styles
β β βββ amazon.css # Product catalog styles
β β βββ orders.css # Orders page styles
β β βββ tracking.css # Tracking page styles
β β βββ checkout/ # Checkout page styles
β β βββ checkout.css
β β βββ checkout-header.css
β βββ shared/ # Shared styles
β βββ general.css # Global styles
β βββ amazon-header.css # Header component styles
β
βββ images/ # Image assets
β βββ icons/ # Icon images
β βββ products/ # Product images
β β βββ variations/ # Product variant images
β βββ ratings/ # Star rating images
β
βββ backend/
βββ products.json # JSON data for products
test-jasmine/
βββ lib/jasmine-5.1.1/ # Jasmine testing framework
β βββ tests.html # Test runner HTML
β βββ utils/ # Utility tests
β β βββ moneyTest.js # Currency formatting tests
β βββ data/ # Data layer tests
β β βββ cartTest.js # Cart functionality tests
β βββ checkout/ # Checkout module tests
β βββ orderSummaryTest.js # Order summary tests
β βββ paymentSummaryTest.js # Payment calculation tests
βββ MIT.LICENSE # Jasmine framework license
- HTML5: Semantic markup and form handling
- CSS3: Responsive design, flexbox, grid layouts
- JavaScript (ES6+): Classes, modules, arrow functions, destructuring
- DOM APIs: Element selection, event handling, manipulation
- LocalStorage API: Client-side persistent storage for cart and orders
- JSON: Data serialization and transmission
- XMLHttpRequest & Fetch API: Backend communication
- Jasmine 5.1.1: Testing framework and test runner
- Git: Version control system
- Modules: ES6 import/export for code organization
- Object-Oriented Programming: Class-based design with inheritance
- Functional Programming: Pure functions for utilities
- Module Pattern: Encapsulation and namespace management
- Observer Pattern: Event-driven component communication
- A modern web browser (Chrome, Firefox, Safari, Edge)
- Basic understanding of JavaScript, HTML, and CSS
-
Clone the repository
git clone https://github.com/yourusername/javascript-amazon-project.git cd javascript-amazon-project -
Open the main page
# On Windows start amazon.html # On macOS open amazon.html # Or open in your browser directly
-
Open the test runner
# Navigate to the test runner open test-jasmine/lib/jasmine-5.1.1/tests.html # Or open in your browser
-
View test results
- The page will display all test suites and their results
- Green checkmarks indicate passing tests
- Red X marks indicate failing tests
- Console shows detailed error messages
- Browse Products: View the product catalog on the main page
- Add to Cart: Select quantity and click "Add to Cart"
- View Cart: Click the cart icon in the header
- Checkout: Proceed to checkout and select delivery options
- Review Order: View order summary and payment details
- Place Order: Complete the purchase
- Track Orders: View order history and delivery status
Classes:
Product: Base class with common properties (id, name, price, rating, image)Clothing: Extends Product with size chart linkAppliance: Extends Product with instructions and warranty links
Key Methods:
getProduct(productId): Find product by IDgetStarsUrl(): Generate rating star image URLgetPrice(): Format price in currencyextraInfoHTML(): Generate product-specific HTML
Features:
- Product inheritance and polymorphism
- Dynamic product loading from backend
- Support for product variations
Two implementations available:
Functional Approach (cart.js):
- Uses module pattern with closures
- Export cart array and functions
- Functions: addToCart, removeFromCart, updateQuantity, updateDeliveryOption
Object-Oriented Approach (cart-class.js):
- Cart class with private properties (#localStorageKey)
- Instance methods for all operations
- Multiple cart instances support (e.g., business cart, personal cart)
Key Features:
- Persistent storage via LocalStorage
- Product quantity management
- Delivery option selection
- Cart state management
Functionality:
- Create and store orders
- Order history tracking
- Persistent storage
- Order retrieval for display
Features:
- Multiple delivery methods
- Pricing for each option
- Delivery date calculation
- Cost included in order summary
orderSummary.js:
- Renders cart items with prices
- Handles item removal
- Quantity updates
- Product details display
paymentSummary.js:
- Calculates subtotal
- Applies taxes
- Includes delivery costs
- Shows total amount due
money.js:
formatCurrency(priceCents); // Converts cents to formatted currency stringsearch.js:
- Product search and filtering functionality
[User Interaction]
β
[Event Listeners in Scripts]
β
[Cart/Orders State Management (data/)]
β
[LocalStorage Persistence]
β
[DOM Rendering via Scripts]
β
[Visual Display]
Data Layer (data/ folder):
- Manages application state
- Handles storage persistence
- Provides data access functions
Business Logic (Scripts/ folder):
- Implements features using data
- Handles user interactions
- Renders UI components
Presentation Layer (styles/ folder):
- CSS for visual presentation
- Responsive design rules
- Component styling
- Cart State: Stored in LocalStorage, managed by cart module
- Products: Loaded from backend, cached in memory
- Orders: Persisted in LocalStorage
- Delivery Options: Static data with computed properties
The project includes comprehensive Jasmine tests for:
-
Cart Operations (
cartTest.js)- Adding existing products
- Adding new products
- Removing products
- Updating quantities
- Delivery option updates
-
Money Utilities (
moneyTest.js)- Currency formatting
- Edge cases (zero, decimals)
-
Order Summary (
orderSummaryTest.js)- Rendering cart items
- Item removal functionality
- Quantity updates
- HTML structure verification
-
Payment Summary (
paymentSummaryTest.js)- Payment calculation accuracy
- Tax computation
- Delivery cost inclusion
- Spies: Mock localStorage methods
- Hooks: beforeEach, beforeAll for setup
- Matchers: toEqual, toHaveBeenCalled, toHaveBeenCalledWith
- Async Testing: Handle promises with done()
- DOM Testing: Verify HTML rendering
# Open the test runner in browser
test-jasmine/lib/jasmine-5.1.1/tests.html
# Tests will automatically run and display results
# Check browser console for detailed logs[
{
"productId": "e43638ce-6aa0-4b85-b27f-e1d07eb678c6",
"quantity": 2,
"deliveryOptionId": "1"
}
][
{
"id": "unique-order-id",
"orderTime": 1234567890,
"totalCents": 9999,
"products": [...]
}
]This project uses Git for version control:
- .git/: Git repository with full history
- Commit history: Track all changes and development progress
- Branching: Organize features and experiments
# View commit history
git log --oneline
# Check current status
git status
# Stage and commit changes
git add .
git commit -m "Description of changes"
# Push to remote
git push origin mainThis project demonstrates:
-
Object-Oriented Programming
- Classes and inheritance
- Private properties (#)
- Method overriding
-
Functional Programming
- Pure functions
- Module closures
- Higher-order functions
-
Asynchronous JavaScript
- Promises
- Async/await
- XMLHttpRequest vs Fetch
-
DOM Manipulation
- querySelector/querySelectorAll
- Event listeners
- Dynamic HTML generation
-
State Management
- Centralized state
- State persistence
- State updates and notifications
-
Testing & Quality
- Unit testing
- Test-driven development
- Mocking and spying
-
Responsive Design
- Mobile-first approach
- Flexbox layouts
- Media queries
This project is part of a learning course. See MIT.LICENSE in the test-jasmine folder for testing framework license information.
This is a learning project. Feel free to:
- Fork the repository
- Create a feature branch
- Make improvements
- Submit pull requests
Potential improvements:
- User authentication system
- Real backend API integration
- Payment gateway integration
- Email notifications
- Product reviews and ratings
- Wishlist functionality
- Order filters and sorting
- Admin dashboard
- Advanced search and filtering
- Performance optimization
Created: January 2026
Last Updated: January 13, 2026