Skip to content

Ahmedabdelaziz77/Cloud-Shop

Repository files navigation

Cloud Shop – Microservices Architecture

Overview

Cloud Shop is a sample online shop application built to demonstrate modern microservices patterns using Spring Boot, Spring Cloud, Kafka, Centralized Swagger docs and an observability stack. The project focuses on reliability, security, scalability, and visibility while keeping each service small and well-defined.

The system implements:

  • Centralized configuration
  • Distributed tracing
  • Event-driven architecture
  • Centralized logging
  • Circuit breakers and retries
  • Secure microservices using Keycloak

High-Level Architecture]

Logical Flow Diagram (Flowchart)

flowchart LR
    Client[Client / Frontend]

    subgraph Docker["Docker Compose Environment"]
        Gateway[API Gateway]

        Product[Product Service]
        ProductDB[(MongoDB)]

        Order[Order Service]
        OrderDB[(MySQL)]

        Inventory[Inventory Service]
        InventoryDB[(MySQL)]

        Kafka[(Kafka Broker)]
        Notification[Notification Service]
        Email["Email Provider<br/>Mailtrap"]
    end

    Client --> Gateway

    Gateway --> Product
    Product --> ProductDB

    Gateway --> Order
    Order --> OrderDB

    Order -- "Sync HTTP + Resilience4j" --> Inventory
    Inventory --> InventoryDB

    Order -- "Async Event Kafka" --> Kafka
    Kafka --> Notification
    Notification --> Email

Loading

Technology Stack

Backend

  • Java 21
  • Spring Boot 4
  • Spring Web MVC
  • Spring Data JPA / MongoDB
  • Spring Cloud Gateway (MVC)
  • Spring Security OAuth2 Resource Server
  • Spring HTTP Interface (RestClient)
  • Resilience4j

Messaging

  • Apache Kafka
  • Schema Registry
  • Avro serialization

Databases

  • MongoDB (Product Service)
  • MySQL (Order & Inventory Services)
  • Flyway for database migrations

Observability

  • Spring Boot Actuator
  • Micrometer
  • Prometheus
  • Grafana
  • Loki
  • Tempo

Infrastructure & Tooling

  • Docker & Docker Compose
  • Testcontainers
  • WireMock
  • RestAssured
  • Springdoc OpenAPI
  • Centralized Swagger documentation via API Gateway

Frontend

  • Angular
  • Keycloak

Supporting Infrastructure

  • API Gateway with circuit breakers and fallbacks
  • Keycloak for authentication and authorization
  • Kafka + Schema Registry for asynchronous messaging
  • Prometheus for metrics
  • Loki for centralized logging
  • Tempo for distributed tracing
  • Grafana for visualization

Services

Product Service

  • Acts as the product catalog
  • Create and view products
  • MongoDB persistence
  • REST API with OpenAPI documentation
  • Centralized logging, metrics, and tracing enabled

Order Service

  • Handles order creation
  • Persists orders in MySQL
  • Synchronous inventory check using HTTP interface client
  • Resilience4j circuit breaker and retry
  • Publishes order-placed events to Kafka

Inventory Service

  • Checks product availability
  • MySQL persistence
  • Used synchronously by Order Service
  • Protected with circuit breaker

Notification Service

  • Consumes order events from Kafka
  • Uses Avro schemas via Schema Registry
  • Sends order confirmation emails using Java Mail Sender
  • Kafka observation enabled for tracing

API Gateway

  • Single entry point for all clients
  • Route configuration for backend services
  • Aggregated OpenAPI / Swagger documentation
  • Circuit breaker and fallback handling
  • Security enforcement via Keycloak

Communication Patterns

Synchronous Communication

  • Order Service → Inventory Service
  • Implemented using Spring HTTP Interfaces
  • Protected by Resilience4j (timeouts, retries, circuit breakers)

Asynchronous Communication

  • Order Service → Notification Service
  • Implemented using Kafka
  • Avro schemas managed via Schema Registry

Security

  • Keycloak used as Authorization Server
  • OAuth2 Resource Server configuration in services
  • Gateway validates JWT tokens
  • Realm configuration exported to avoid data loss

Observability

Logging

  • Centralized logging using Loki
  • Logback Loki appender configuration

Metrics

  • Spring Boot Actuator
  • Micrometer with Prometheus registry

Tracing

  • Micrometer Tracing with Brave
  • Tempo as tracing backend
  • HTTP and Kafka observation enabled

Testing Strategy

  • Integration tests with Testcontainers
  • MongoDB, MySQL, and Kafka containers
  • REST API testing using RestAssured
  • WireMock used for contract testing

Project Evolution (Journey Summary)

  1. Product Service with MongoDB and integration tests
  2. Order Service with MySQL, Flyway, and tests
  3. Inventory Service with MySQL and availability checks
  4. Synchronous communication with circuit breakers
  5. API Gateway with routing, security, and Swagger aggregation
  6. Kafka-based event-driven communication
  7. Notification Service with email delivery
  8. Observability stack integration (logs, metrics, tracing)
  9. Frontend integration using Angular and Keycloak

Screenshots and Visual Evidence

Circuit Breaker Status

Circuit Breaker Preview

Kafka Topics and Consumers

Kafka Topics Kafka Consumer

Email Notification

Email Received

Grafana Dashboards

Grafana Dashboard

Logs and Metrics

Loki Logs Prometheus Metrics


How to Run

  1. Start infrastructure using Docker Compose

  2. Start backend services

  3. Start API Gateway

  4. Start frontend service

  5. Access:

    • Gateway API
    • Swagger UI via Gateway
    • Grafana dashboards
    • Kafka UI

About

microservices online shop built as a set of small, independent services. It supports browsing products, placing orders, checking availability, and sending order confirmations, with a focus on reliable communication between services, secure access, and clear visibility into how requests and events flow through the system.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors