| Metric | Value |
|---|---|
| Total SLOC | 10,427 |
| Source Files | 56 |
| .js | 4,661 |
| .md | 2,504 |
| .tsx | 2,086 |
| .sql | 592 |
| .ts | 421 |
A simplified Amazon-like platform demonstrating product catalog management, inventory systems, recommendation engines, and order fulfillment. This educational project focuses on building a scalable e-commerce system with complex product search and ordering workflows.
- Hierarchical category system
- Product attributes and variants (size, color)
- Seller marketplace integration
- Product search and filtering with Elasticsearch
- Real-time stock tracking
- Reserved inventory for carts (prevents overselling)
- Automatic reservation expiration
- Low stock alerts
- Cart with inventory reservation
- Multi-step checkout flow
- Order confirmation
- Order status tracking
- Order history
- Order cancellation
- Product reviews with star ratings
- Verified purchase badges
- Helpful vote system
- Rating summaries
- "Customers also bought" suggestions
- Batch-computed collaborative filtering
- Redis-cached for fast retrieval
- Frontend: TypeScript, React 19, Vite, TanStack Router, Zustand, Tailwind CSS
- Backend: Node.js, Express
- Database: PostgreSQL
- Cache: Redis
- Search: Elasticsearch
- Node.js 18+
- Docker and Docker Compose
- npm or yarn
cd amazon
docker-compose up -dThis starts:
- PostgreSQL on port 5432
- Redis on port 6379
- Elasticsearch on port 9200
Wait for Elasticsearch to be ready (may take 30-60 seconds):
curl http://localhost:9200/_cluster/healthcd backend
# Copy environment file
cp .env.example .env
# Install dependencies
npm install
# Seed the database with sample data
npm run seed
# Sync products to Elasticsearch
npm run sync-es
# Start the server
npm run devBackend runs on http://localhost:3000
cd frontend
# Install dependencies
npm install
# Start development server
npm run devFrontend runs on http://localhost:5173
- Frontend: http://localhost:5173
- API: http://localhost:3000/api
- API Health Check: http://localhost:3000/api/health
| Role | Password | |
|---|---|---|
| Admin | admin@amazon.local | admin123 |
| Seller | seller@amazon.local | admin123 |
Note: Create a new account to test as a regular user.
POST /api/auth/register- Register new userPOST /api/auth/login- LoginPOST /api/auth/logout- LogoutGET /api/auth/me- Get current user
GET /api/products- List products (with pagination/filters)GET /api/products/:id- Get product detailsGET /api/products/:id/recommendations- Get product recommendationsPOST /api/products- Create product (seller/admin)PUT /api/products/:id- Update product (seller/admin)PUT /api/products/:id/inventory- Update inventory (seller/admin)
GET /api/categories- List all categories (tree structure)GET /api/categories/:slug- Get category with subcategories
GET /api/search?q=query- Search products with facetsGET /api/search/suggestions?q=query- Autocomplete suggestions
GET /api/cart- Get cartPOST /api/cart- Add to cartPUT /api/cart/:productId- Update quantityDELETE /api/cart/:productId- Remove itemDELETE /api/cart- Clear cart
GET /api/orders- List user's ordersGET /api/orders/:id- Get order detailsPOST /api/orders- Create order (checkout)POST /api/orders/:id/cancel- Cancel order
GET /api/reviews/product/:productId- Get product reviewsPOST /api/reviews- Create reviewPOST /api/reviews/:id/helpful- Mark review as helpful
GET /api/admin/stats- Dashboard statisticsGET /api/admin/orders- List all ordersGET /api/admin/users- List all usersGET /api/admin/inventory- Inventory reportPOST /api/admin/sync-elasticsearch- Sync products to ES
amazon/
├── docker-compose.yml # Infrastructure services
├── backend/
│ ├── src/
│ │ ├── index.js # Express app entry
│ │ ├── routes/ # API routes
│ │ ├── services/ # Database, Redis, ES services
│ │ ├── middleware/ # Auth, error handling
│ │ └── utils/ # Seed, sync scripts
│ └── db/
│ └── init.sql # Database schema
└── frontend/
└── src/
├── routes/ # Page components (TanStack Router)
├── components/ # Reusable UI components
├── stores/ # Zustand state management
├── services/ # API client
└── types/ # TypeScript definitions
The reserved inventory model prevents overselling:
- When adding to cart, inventory is reserved (not decremented)
- Reservations expire after 30 minutes
- Background job releases expired reservations
- Checkout atomically decrements both quantity and reserved
Elasticsearch provides:
- Full-text search with fuzzy matching
- Faceted filtering (categories, price ranges, ratings)
- Relevance scoring
- PostgreSQL fallback if ES unavailable
- Cart items stored in PostgreSQL (durable)
- Inventory reservations prevent overselling
- Automatic cleanup of expired reservations
- Collaborative filtering based on co-purchase data
- Batch computed (not real-time) for performance
- Cached in Redis for fast retrieval
# Terminal 1
npm run dev:server1 # Port 3001
# Terminal 2
npm run dev:server2 # Port 3002
# Terminal 3
npm run dev:server3 # Port 3003# Stop containers
docker-compose down -v
# Start fresh
docker-compose up -d
# Re-seed data
cd backend && npm run seed && npm run sync-esIf you prefer to run services natively:
# macOS with Homebrew
brew install postgresql@16
brew services start postgresql@16
createdb amazon_ecommerce
psql amazon_ecommerce < backend/db/init.sql# macOS with Homebrew
brew install redis
brew services start redis# macOS with Homebrew
brew tap elastic/tap
brew install elastic/tap/elasticsearch-full
brew services start elastic/tap/elasticsearch-fullUpdate .env with appropriate connection strings if using non-default ports.
See architecture.md for detailed system design documentation.
See claude.md for development insights and design decisions.
- Amazon's Dynamo Paper - Foundational distributed key-value store design from Amazon
- All Things Distributed (Werner Vogels' Blog) - Insights from Amazon's CTO on distributed systems
- Building Scalable E-Commerce with Event Sourcing - Event sourcing pattern for order tracking
- Elasticsearch for E-Commerce Search - Search implementation strategies
- Amazon Item-to-Item Collaborative Filtering - The original recommendation algorithm paper
- Inventory Management Patterns - Optimistic locking for concurrent inventory updates
- Designing a Shopping Cart - ByteByteGo deep dive on cart design
- Handling Flash Sales at Scale - Grab's approach to high-concurrency sales