A production-grade backend E-Commerce system built with Spring Boot, featuring transactional checkout with ACID guarantees and asynchronous order fulfillment.
- Homebrew - Package manager for macOS (install from https://brew.sh)
- Java 8 - Install via
brew install java8 - Maven - Install via
./install-maven.shorbrew install maven - PostgreSQL - Install via
brew install postgresql@14and start withbrew services start postgresql@14 - Node.js - Install via
brew install node(includes npm)
# Create database
psql postgres
CREATE DATABASE ecommerce_db;
\qOption 1: Using provided scripts (Recommended for macOS. If errors, try option 2.)
# Build the project
./build.sh
# Run the application
./run.shOption 2: Using Maven directly (Ensure Java 8 is set as the default Java version)
# Build
mvn clean install
# Run
mvn spring-boot:runThe application will start at http://localhost:8080/api
The project includes a React + TypeScript frontend located in the frontend/ directory.
# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Start development server
npm run devThe frontend will run on http://localhost:3000 and automatically proxy API requests to the backend.
- Swagger UI: http://localhost:8080/api/swagger-ui.html
- API Docs: http://localhost:8080/api/api-docs
GET /api/products- Get all productsGET /api/products/{id}- Get product by IDGET /api/products/search?query={term}- Search products
GET /api/cart- Get current cartPOST /api/cart/items- Add item to cartPUT /api/cart/items/{itemId}- Update item quantityDELETE /api/cart/items/{itemId}- Remove item from cart
POST /api/orders/checkout- Process checkout (creates order)GET /api/orders- Get user's ordersGET /api/orders/{id}- Get order by ID
- REST API - Full CRUD operations for products, cart, and orders
- Database - Database persistence using ORM (JPA/Hibernate) with PostgreSQL.
- ACID Transactions - SERIALIZABLE isolation for checkout
- Pessimistic Locking - Prevents overselling in concurrent scenarios
- Async Order Fulfillment - Background worker processes orders (PENDING β PROCESSING β FULFILLED)
- Thread-Safe - Concurrent order processing with proper locking
- Product Browsing - Browse and search products with real-time updates
- Shopping Cart - Add, update, and remove items with quantity management
- Order Management - View order history and track order status
Update database credentials in src/main/resources/application.yml:
spring:
datasource:
url: jdbc:postgresql://localhost:5432/ecommerce_db
username: your_username
password: your_password
app:
order-fulfillment:
thread-pool-size: 5 # Worker threads
processing-delay-seconds: 10 # Fulfillment delay to simulate real-world order fulfillment# 1. Get products
curl http://localhost:8080/api/products
# 2. Add to cart
curl -X POST http://localhost:8080/api/cart/items \
-H "Content-Type: application/json" \
-d '{"productId": 1, "quantity": 2}'
# 3. Checkout
curl -X POST http://localhost:8080/api/orders/checkout
# 4. View orders
curl http://localhost:8080/api/orders- Spring Boot 2.7.18 - Application framework
- JPA/Hibernate - ORM with PostgreSQL
- PostgreSQL - Database
- Maven - Build tool
- Java 8 - Runtime
- React 18 - UI framework
- TypeScript - Type-safe JavaScript
- Vite - Build tool and dev server
- React Router - Client-side routing
- Axios - HTTP client
The application automatically initializes with 10 sample products on first run.
Database Connection Issues:
- Verify PostgreSQL is running:
brew services list | grep postgresql - Check database exists:
psql postgres -c "\l" | grep ecommerce_db
pgAdmin 4 provides a graphical interface to manage and explore the PostgreSQL database.
brew install --cask pgadmin4-
Launch pgAdmin 4 and set a master password (first time only)
-
Create Server Connection:
- Right-click "Servers" β "Register" β "Server..."
- General Tab: Name =
E-Commerce Local - Connection Tab:
- Host:
localhost - Port:
5432 - Database:
ecommerce_db - Username:
jason-ariel(or your PostgreSQL username) - Password: (your password, if set)
- Host:
- Click "Save"
-
Explore Database:
- Navigate to:
Servers β E-Commerce Local β Databases β ecommerce_db β Schemas β public β Tables - Right-click any table β "View/Edit Data" β "All Rows"
- Navigate to:
View Products:
SELECT id, name, price, stock_quantity FROM products ORDER BY name;View Recent Orders:
SELECT order_number, user_id, total_amount, status, created_at
FROM orders
ORDER BY created_at DESC
LIMIT 10;Check Inventory:
SELECT name, stock_quantity,
CASE WHEN stock_quantity = 0 THEN 'Out of Stock'
WHEN stock_quantity < 10 THEN 'Low Stock'
ELSE 'In Stock' END as status
FROM products;