Skip to content

A scalable, cloud-native eCommerce backend built with Java and Spring Boot microservices. It features modular services for products, orders, payments, customers, and notifications—using service discovery, centralized config, and robust messaging for modern distributed systems.

Notifications You must be signed in to change notification settings

AdamNgazzou/SpringBoot-Microservices-EcommerceApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Microservices eCommerce Backend 🛒🚀

A scalable, cloud-native eCommerce backend built with Java and Spring Boot microservices. This project features modular services for products, orders, payments, customers, notifications, and more—leveraging service discovery, centralized configuration, and robust messaging for modern distributed architectures.

Java Spring Boot Docker PostgreSQL MongoDB Kafka JUnit Eureka Config Server


Features

  • Product Service: Manage product catalog with PostgreSQL and Flyway migrations.
  • Order Service: Place and track orders, integrates with product, payment, and customer services.
  • Payment Service: Handles payment processing and status updates.
  • Customer Service: Manages customer data using MongoDB.
  • Notification Service: Sends email notifications (MailDev for dev), listens to Kafka events.
  • Service Discovery: Eureka server for dynamic service registration and lookup.
  • API Gateway: Centralized routing and load balancing for all APIs.
  • Centralized Config: Spring Cloud Config Server for unified configuration management.
  • Event-Driven: Kafka for asynchronous communication between services.
  • Database Admin UIs: pgAdmin and Mongo Express for DB management.
  • Dockerized: All services and dependencies orchestrated via Docker Compose.

Tech Stack

  • Java 17
  • Spring Boot 3.5+ (Web, Data JPA, Data MongoDB, Validation, Mail, Thymeleaf)
  • Spring Cloud (Eureka, Config Server, OpenFeign, Gateway)
  • PostgreSQL & MongoDB
  • Kafka (Confluent Platform)
  • Docker & Docker Compose
  • JUnit 5 (Testing)
  • Lombok (Boilerplate reduction)
  • Flyway (DB migrations)
  • pgAdmin, Mongo Express, MailDev

Architecture Overview

This project follows a microservices architecture:

  • Service Discovery: All services register with Eureka for dynamic discovery.
  • API Gateway: Routes external requests to internal services, supports load balancing and path-based routing.
  • Config Server: Centralizes configuration for all services, loaded at startup.
  • Inter-Service Communication: REST (via OpenFeign) and asynchronous messaging (Kafka).
  • Persistence: PostgreSQL for transactional data (orders, products, payments), MongoDB for customer and notification data.
  • Notifications: Kafka events trigger email notifications via the notification service.

Service Communication Diagram:

[Client] → [API Gateway] → [Product/Order/Payment/Customer Services]
                             ↑           ↓
                       [Eureka Discovery]
                             ↑           ↓
                    [Config Server]   [Kafka]
                             ↑           ↓
                  [PostgreSQL/MongoDB] [Notification Service]

Project Structure

springbootEcommerceapp/
│
├── docker-compose.yml
└── services/
    ├── config.server/      # Spring Cloud Config Server
    ├── customer/           # Customer microservice (MongoDB)
    ├── discovery/          # Eureka Service Discovery
    ├── gateway/            # API Gateway
    ├── notification/       # Notification microservice (Kafka, Mail)
    ├── order/              # Order microservice (PostgreSQL, Kafka)
    ├── payment/            # Payment microservice (PostgreSQL, Kafka)
    └── product/            # Product microservice (PostgreSQL)

Installation & Setup

  1. Clone the repository:

    git clone https://github.com/yourusername/springbootEcommerceapp.git
    cd springbootEcommerceapp
  2. Configure Environment:

  3. Start Infrastructure with Docker Compose:

    docker-compose up -d

    This will start:

    • PostgreSQL, MongoDB, Kafka, Zookeeper
    • pgAdmin, Mongo Express, MailDev
    • (You can now run the Spring Boot services)
  4. Build and Run Microservices:

    In each service directory (e.g., services/product):

    ./mvnw clean package
    java -jar target/*.jar

    Or use your IDE to run each service.


Usage

  • API Gateway:
    Access all APIs via the gateway at http://localhost:8222.

    • Example: GET /api/v1/products → routed to Product Service
  • Service Endpoints:

    Service Base URL (via Gateway)
    Product /api/v1/products
    Order /api/v1/orders
    Payment /api/v1/payments
    Customer /api/v1/customers
    Notification Internal (Kafka, Email)
  • Swagger UI:
    Add Swagger/OpenAPI to each service for interactive API docs (recommended).

  • Database Admin:

  • MailDev (Email Testing):
    http://localhost:1080


Testing

  • Unit & Integration Tests:
    Each service includes tests using JUnit 5 and Spring Boot Test. Run tests with:

    ./mvnw test
  • Test Coverage:
    Add plugins like JaCoCo for coverage reports.


Results / API Examples

Example: Create Product (POST /api/v1/products)

{
  "name": "Wireless Mouse",
  "description": "Ergonomic wireless mouse",
  "price": 29.99,
  "quantity": 100
}

Example: Order Response

{
  "orderId": 123,
  "customerId": 1,
  "orderLines": [{ "productId": 10, "quantity": 2 }],
  "status": "CONFIRMED"
}

Future Improvements

  • Add JWT-based authentication and role-based authorization
  • Implement distributed tracing (Zipkin, Sleuth)
  • Add Swagger/OpenAPI documentation to all services
  • CI/CD pipeline for automated builds and deployments
  • Horizontal scaling with Kubernetes
  • Advanced monitoring (Prometheus, Grafana)
  • Payment gateway integration (Stripe, PayPal)

Contributing

Contributions, bug reports, and feature requests are welcome!
Please open an issue or submit a pull request.


License

This project is licensed under the MIT License.


About

A scalable, cloud-native eCommerce backend built with Java and Spring Boot microservices. It features modular services for products, orders, payments, customers, and notifications—using service discovery, centralized config, and robust messaging for modern distributed systems.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages