Skip to content

manish08k/Amazon-Clone-Backend

Repository files navigation

Amazon Clone β€” Distributed E-Commerce Platform

A production-grade distributed e-commerce platform built with Java 21 and Spring Boot, implementing microservices architecture with event-driven communication.

Architecture

                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚               API Gateway                β”‚
                        β”‚        (Spring Cloud Gateway :8080)      β”‚
                        β”‚   JWT Auth β”‚ Circuit Breaker β”‚ Rate Limitβ”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚                 β”‚                     β”‚                β”‚
  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
  β”‚ User Service β”‚  β”‚Product Serviceβ”‚  β”‚ Order Serviceβ”‚  β”‚Payment Serviceβ”‚
  β”‚    :8081     β”‚  β”‚    :8082     β”‚  β”‚    :8083    β”‚  β”‚    :8084     β”‚
  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
         β”‚                 β”‚                  β”‚                   β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚                β”‚                         β”‚                β”‚
  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
  β”‚  Inventory   β”‚  β”‚Notification   β”‚  β”‚    Search     β”‚  β”‚Service Registryβ”‚
  β”‚  Service     β”‚  β”‚   Service     β”‚  β”‚   Service     β”‚  β”‚   (Eureka)     β”‚
  β”‚    :8085     β”‚  β”‚    :8086     β”‚  β”‚    :8087     β”‚  β”‚    :8761      β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚                 β”‚                     β”‚                β”‚
   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
   β”‚ PostgreSQL  β”‚   β”‚    Redis    β”‚   β”‚   Kafka    β”‚   β”‚Elasticsearch  β”‚
   β”‚ (6 DBs)    β”‚   β”‚   Cache     β”‚   β”‚  (Events)  β”‚   β”‚   (Search)    β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Services

Service Port Description
Service Registry 8761 Eureka service discovery
Config Server 8888 Centralized configuration
API Gateway 8080 Entry point β€” auth, routing, LB
User Service 8081 Auth, JWT, user profiles, addresses
Product Service 8082 Catalog, categories, reviews, images
Order Service 8083 Orders, cart (Redis), checkout
Payment Service 8084 Payments, refunds, webhooks
Inventory Service 8085 Stock management, reservations
Notification Service 8086 Email via Kafka consumers
Search Service 8087 Elasticsearch full-text search

Tech Stack

Technology Usage
Java 21 Virtual threads, records, sealed classes
Spring Boot 3.2 Core framework
Spring Security JWT authentication, method-level auth
Spring Data JPA Hibernate ORM + PostgreSQL
Spring Cloud Gateway API Gateway with circuit breakers
Eureka Service discovery and registration
Redis Cart storage, caching
Apache Kafka Event-driven async communication
RabbitMQ Message queuing
Elasticsearch Full-text product search
Docker Containerization
Kubernetes Orchestration + HPA autoscaling
AWS EKS Cloud deployment
Jenkins CI/CD pipeline
GitHub Actions CI/CD pipeline (alternative)
Prometheus Metrics collection
Grafana Metrics dashboards
Flyway Database migrations
JUnit 5 + Mockito Testing

Quick Start

Prerequisites

  • Docker Desktop
  • Java 21
  • Maven 3.9+

Run with Docker Compose

git clone https://github.com/your-org/amazon-clone.git
cd amazon-clone

# Start all infrastructure
docker-compose up -d postgres redis kafka zookeeper rabbitmq elasticsearch prometheus grafana

# Wait for infrastructure to be ready (~30 seconds), then start services
docker-compose up -d

# View running services
docker-compose ps

Run Locally (Development)

# 1. Start infrastructure only
docker-compose up -d postgres redis kafka zookeeper rabbitmq elasticsearch

# 2. Build all services
mvn clean install -DskipTests

# 3. Start services in order
java -jar service-registry/target/*.jar &
sleep 10
java -jar config-server/target/*.jar &
sleep 5
java -jar api-gateway/target/*.jar &
java -jar user-service/target/*.jar &
java -jar product-service/target/*.jar &
java -jar order-service/target/*.jar &
java -jar payment-service/target/*.jar &
java -jar inventory-service/target/*.jar &
java -jar notification-service/target/*.jar &
java -jar search-service/target/*.jar &

API Reference

Authentication

POST /api/v1/auth/register
POST /api/v1/auth/login
POST /api/v1/auth/refresh
POST /api/v1/auth/logout

Users

GET    /api/v1/users/me
GET    /api/v1/users/{id}
PUT    /api/v1/users/{id}
PATCH  /api/v1/users/{id}/password
POST   /api/v1/users/{id}/addresses
GET    /api/v1/users/{id}/addresses
DELETE /api/v1/users/{id}/addresses/{addressId}

Products

GET    /api/v1/products
GET    /api/v1/products/{id}
POST   /api/v1/products          (SELLER/ADMIN)
PUT    /api/v1/products/{id}     (SELLER/ADMIN)
DELETE /api/v1/products/{id}     (SELLER/ADMIN)
GET    /api/v1/products/search?keyword=
GET    /api/v1/products/filter?categoryId=&minPrice=&maxPrice=&brand=
GET    /api/v1/products/featured
GET    /api/v1/products/{id}/reviews
POST   /api/v1/products/{id}/reviews
GET    /api/v1/categories
POST   /api/v1/categories        (ADMIN)

Orders & Cart

POST   /api/v1/cart/items
GET    /api/v1/cart
PUT    /api/v1/cart/items/{productId}
DELETE /api/v1/cart/items/{productId}
DELETE /api/v1/cart

POST   /api/v1/orders
GET    /api/v1/orders/my
GET    /api/v1/orders/{id}
POST   /api/v1/orders/{id}/cancel
PATCH  /api/v1/orders/{id}/status   (ADMIN)

Payments

POST   /api/v1/payments
GET    /api/v1/payments/my
GET    /api/v1/payments/{id}
GET    /api/v1/payments/order/{orderNumber}
POST   /api/v1/payments/{id}/refund
POST   /api/v1/payments/webhook

Inventory

POST   /api/v1/inventory
GET    /api/v1/inventory/product/{productId}
PUT    /api/v1/inventory/product/{productId}/stock
GET    /api/v1/inventory/low-stock
POST   /api/v1/inventory/check
POST   /api/v1/inventory/reserve
POST   /api/v1/inventory/release

Search

GET /api/v1/search?q=laptop&categoryId=1&minPrice=100&maxPrice=2000&sortBy=price
GET /api/v1/search/suggest?q=lap
GET /api/v1/search/category/{categoryId}

Kafka Topics

Topic Producer Consumer(s)
user-registered User Service Notification Service
user-updated User Service β€”
product-events Product Service Search Service, Notification Service
order-events Order Service Notification Service
payment-events Payment Service Notification Service
payment-order-events Payment Service Order Service
inventory-alerts Inventory Service Notification Service

Monitoring

Tool URL Credentials
Grafana http://localhost:3000 admin / admin123
Prometheus http://localhost:9090 β€”
Eureka http://localhost:8761 β€”
Kafka UI http://localhost:8090 β€”
RabbitMQ http://localhost:15672 guest / guest
Kibana http://localhost:5601 β€”

Running Tests

# All tests
mvn test

# Single service
mvn test -pl user-service

# With coverage
mvn test jacoco:report -pl user-service
open user-service/target/site/jacoco/index.html

Deploy to Kubernetes

# Create namespace and secrets
kubectl apply -f k8s/namespace.yml
kubectl apply -f k8s/secrets.yml

# Deploy infrastructure
kubectl apply -f k8s/infrastructure.yml

# Deploy services
kubectl apply -f k8s/services.yml

# Check status
kubectl get pods -n amazon-clone
kubectl get services -n amazon-clone

# Scale a service
kubectl scale deployment product-service --replicas=3 -n amazon-clone

Project Structure

amazon-clone/
β”œβ”€β”€ pom.xml                          # Parent POM
β”œβ”€β”€ docker-compose.yml               # Local development
β”œβ”€β”€ Jenkinsfile                      # Jenkins CI/CD
β”œβ”€β”€ .github/workflows/ci-cd.yml     # GitHub Actions CI/CD
β”œβ”€β”€ service-registry/                # Eureka Server
β”œβ”€β”€ config-server/                   # Spring Cloud Config
β”œβ”€β”€ api-gateway/                     # Spring Cloud Gateway
β”œβ”€β”€ user-service/                    # Users + Auth + JWT
β”œβ”€β”€ product-service/                 # Products + Categories + Reviews
β”œβ”€β”€ order-service/                   # Orders + Cart
β”œβ”€β”€ payment-service/                 # Payments + Refunds
β”œβ”€β”€ inventory-service/               # Stock + Reservations
β”œβ”€β”€ notification-service/            # Email via Kafka
β”œβ”€β”€ search-service/                  # Elasticsearch
β”œβ”€β”€ k8s/                            # Kubernetes manifests
β”œβ”€β”€ monitoring/                      # Prometheus + Grafana
└── docker/                         # Shared Dockerfiles

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors