# hieu-pt/fully-completed-microservices-java-springboot architecture

> Architecture diagram of the GitHub repository hieu-pt/fully-completed-microservices-java-springboot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hieu-pt/fully-completed-microservices-java-springboot
- Repository: https://github.com/hieu-pt/fully-completed-microservices-java-springboot

## Overview

##### Project Type and Purpose
- This is a Java/Spring-Boot based set of microservices implementing a typical e-commerce backend.
- Uses Spring Cloud Config Server for centralized configuration, Eureka for service discovery, Spring Cloud Gateway for API routing, Kafka for asynchronous messaging, Zipkin for tracing, and individual databases per service.

##### Key Architectural Components
a. Spring Cloud Config Server
- Centralized configuration store; all microservices fetch their `application.yml` from here at startup (and refresh if needed).
b. Eureka Discovery Service
- Service registry; all microservices (Customer, Product, Order, Payment, Notification, Gateway) register here.
c. API Gateway (Spring Cloud Gateway)
- Single entry point for all client requests; handles routing, load-balancing, circuit-breaking, distributed tracing headers.
d. Business Microservices
- Customer Service (manages customer CRUD)
- Product Service (manages product catalog; uses its own relational DB and Flyway migrations)
- Order Service (manages orders; calls Customer, Product, and Payment via REST; produces order events to Kafka)
- Payment Service (processes payments; produces payment events to Kafka; may call external payment provider)
- Notification Service (consumes Kafka topics for orders and payments; sends emails or notifications)
e. Messaging Infrastructure
- Apache Kafka cluster with topics for `order-confirmation` and `payment-confirmation`.
f. Distributed Tracing
g. Data Stores
- One database per microservice (e.g., PostgreSQL/MySQL) so that each service owns its data.

##### High-Level Relationships and Data Flow
- Client/UI → API Gateway → (discovered via Eureka) → respective microservice
- Each microservice retrieves configuration from Config Server.
- When Order Service completes an order, it publishes an `OrderConfirmation` event to Kafka.
- When Payment Service processes a payment, it publishes a `PaymentConfirmation` event to Kafka.
- Notification Service subscribes to Kafka topics, processes events, and sends emails (via SMTP) or pushes notifications.
- All inter-service calls are traced: spans emitted to Zipkin.

##### Important Architectural Patterns
- Service Discovery Pattern (Eureka)
- API Gateway Pattern (Spring Cloud Gateway + Circuit Breaker)
- Centralized Configuration Pattern (Config Server)
- Event-Driven Architecture (Kafka topics)
- Database per Service Pattern
- Distributed Tracing Pattern (Zipkin)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Configuration & Discovery"
        Config["Config Server\n(Spring Cloud Config)"]:::infra
        Eureka["Eureka Discovery\n(Eureka)"]:::infra
        Zipkin["Zipkin\n(Distributed Tracing)"]:::infra
    end

    subgraph "Clients"
        Web["Web UI"]:::client
        Mobile["Mobile App"]:::client
        Third["Third-party Systems"]:::client
    end

    Gateway["API Gateway\n(Spring Cloud Gateway)"]:::gateway

    subgraph "E-commerce Backend"
        Customer["Customer Service\n(Spring Boot)"]:::svc
        CustomerDB["Customer DB"]:::db

        Product["Product Service\n(Spring Boot + Flyway)"]:::svc
        ProductDB["Product DB"]:::db

        Order["Order Service\n(Spring Boot)"]:::svc
        OrderDB["Order DB"]:::db

        Payment["Payment Service\n(Spring Boot)"]:::svc
        PaymentDB["Payment DB"]:::db

        Notification["Notification Service\n(Spring Boot)"]:::svc
        NotificationDB["Notification DB"]:::db

        Kafka["Kafka Cluster"]:::kafka
        Compose["Docker Compose Orchestration"]:::infra
    end

    %% Client to Gateway
    Web -->|REST/HTTP| Gateway
    Mobile -->|REST/HTTP| Gateway
    Third -->|REST/HTTP| Gateway

    %% Gateway to Services
    Gateway -->|REST/HTTP| Customer
    Gateway -->|REST/HTTP| Product
    Gateway -->|REST/HTTP| Order
    Gateway -->|REST/HTTP| Payment
    Gateway -->|REST/HTTP| Notification

    %% Service Databases
    Customer --> CustomerDB
    Product --> ProductDB
    Order --> OrderDB
    Payment --> PaymentDB
    Notification --> NotificationDB

    %% Config Polling
    Customer -->|Config Polling| Config
    Product -->|Config Polling| Config
    Order -->|Config Polling| Config
    Payment -->|Config Polling| Config
    Notification -->|Config Polling| Config
    Gateway -->|Config Polling| Config
    Eureka -->|Config Polling| Config
    Zipkin -->|Config Polling| Config

    %% Service Registration & Discovery
    Customer -->|Service Registration & Discovery| Eureka
    Product -->|Service Registration & Discovery| Eureka
    Order -->|Service Registration & Discovery| Eureka
    Payment -->|Service Registration & Discovery| Eureka
    Notification -->|Service Registration & Discovery| Eureka
    Gateway -->|Service Registration & Discovery| Eureka

    %% Inter-service Calls
    Order -->|REST/HTTP| Customer
    Order -->|REST/HTTP| Product
    Order -->|REST/HTTP| Payment

    %% Event-driven Messaging
    Order -->|Kafka: order-confirmation| Kafka
    Payment -->|Kafka: payment-confirmation| Kafka
    Kafka -->|Kafka Consumer| Notification

    %% Tracing Spans
    Customer -->|Tracing Spans| Zipkin
    Product -->|Tracing Spans| Zipkin
    Order -->|Tracing Spans| Zipkin
    Payment -->|Tracing Spans| Zipkin
    Notification -->|Tracing Spans| Zipkin
    Gateway -->|Tracing Spans| Zipkin
    Eureka -->|Tracing Spans| Zipkin
    Config -->|Tracing Spans| Zipkin

    %% Click Events
    click Config "https://github.com/hieu-pt/fully-completed-microservices-java-springboot/tree/main/services/config-server"
    click Eureka "https://github.com/hieu-pt/fully-completed-microservices-java-springboot/tree/main/services/discovery"
    click Gateway "https://github.com/hieu-pt/fully-completed-microservices-java-springboot/tree/main/services/gateway"
    click Customer "https://github.com/hieu-pt/fully-completed-microservices-java-springboot/tree/main/services/customer"
    click Product "https://github.com/hieu-pt/fully-completed-microservices-java-springboot/tree/main/services/product"
    click Order "https://github.com/hieu-pt/fully-completed-microservices-java-springboot/tree/main/services/order"
    click Payment "https://github.com/hieu-pt/fully-completed-microservices-java-springboot/tree/main/services/payment"
    click Notification "https://github.com/hieu-pt/fully-completed-microservices-java-springboot/tree/main/services/notification"
    click Compose "https://github.com/hieu-pt/fully-completed-microservices-java-springboot/blob/main/docker-compose.yml"

    %% Styles
    classDef infra fill:#DDDDDD,stroke:#333,stroke-width:1px
    classDef gateway fill:#2196F3,stroke:#333,stroke-width:1px
    classDef svc fill:#8BC34A,stroke:#333,stroke-width:1px
    classDef db fill:#FFC107,stroke:#333,stroke-width:1px
    classDef kafka fill:#FFEB3B,stroke:#333,stroke-width:1px
    classDef client fill:#4CAF50,stroke:#333,stroke-width:1px
```
