# yayyz/kafka-msa-example architecture

> Architecture diagram of the GitHub repository yayyz/kafka-msa-example, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yayyz/kafka-msa-example
- Repository: https://github.com/yayyz/kafka-msa-example

## Overview

##### Project type and purpose
- This is a microservice-based, event-driven sample built with Spring Cloud and Kafka.
- Purpose: simulate an order→payment→notification workflow via Kafka events, with service discovery (Eureka), an API gateway, and each service using Spring JPA/H2 for persistence.

##### File structure
- Top-level modules:
- eureka-server: Spring Cloud Eureka registry
- gateway: Spring Cloud Gateway for routing/external access
- order, payment, notification: three business microservices
- Each business module follows a layered structure (domain, application/service, infrastructure [messaging + persistence], presentation/controller).
- A docker-compose.yml at root likely brings up Kafka (brokers + ZooKeeper), Kafka UI, Zipkin, Eureka, etc.
- Kafka clients and serializers present in each service (“EventSerializer.java”).
- application.yml in each module configures connection to Eureka, Kafka, H2, Zipkin.

##### README for additional insights
- It explicitly calls out the order→payment→notification event flow.
- Tech stack: Spring-Kafka, Kafka+ZooKeeper, Kafka-UI, Zipkin, Spring Cloud Discovery (client/server), Gateway, Spring JPA, H2.

##### Elements
- Business services (Order, Payment, Notification) in another
- Kafka ecosystem (Broker, ZooKeeper, topics) in a third
- Observability (Zipkin, Kafka-UI) in a fourth

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Service Discovery
    subgraph "Service Discovery"
        Eureka["Eureka Server"]:::discovery
    end

    %% API Layer
    subgraph "API Layer"
        Gateway["API Gateway"]:::gateway
    end

    %% Microservices
    subgraph "Microservices"
        subgraph "Order Service"
            OCtrl["OrderController"]:::service
            OApp["OrderApplication"]:::service
            ODB["H2 Database"]:::db
            OProd["Kafka Producer"]:::messaging
            OCons["Kafka Consumer"]:::messaging
        end
        subgraph "Payment Service"
            PApp["PaymentApplication"]:::service
            PCons1["OrderCreatedConsumer"]:::messaging
            PDB["H2 Database"]:::db
            PProd["PaymentCompletedProducer"]:::messaging
        end
        subgraph "Notification Service"
            NApp["NotificationApplication"]:::service
            NCons["OrderCompletedConsumer"]:::messaging
            NDB["H2 Database"]:::db
        end
    end

    %% Kafka Cluster
    subgraph "Kafka Cluster"
        Broker["Kafka Broker"]:::kafka
        ZK["ZooKeeper"]:::kafka
        topic1["OrderCreated Topic"]:::topic
        topic2["PaymentCompleted Topic"]:::topic
        topic3["OrderCompleted Topic"]:::topic
    end

    %% Observability & UI
    subgraph "Observability"
        Zipkin["Zipkin"]:::obs
        KUI["Kafka-UI"]:::obs
    end

    %% Docker Compose
    Compose["docker-compose.yml"]:::infra

    %% Client Interaction
    Client["API Client"]:::external
    Client -->|HTTP| Gateway
    Gateway -->|route to Order| OCtrl
    OCtrl -->|invoke| OApp
    OApp -->|persist| ODB
    OApp -->|publish OrderCreated| topic1
    topic1 -->|consume| PCons1
    PCons1 -->|invoke| PApp
    PApp -->|persist| PDB
    PApp -->|publish PaymentCompleted| topic2
    topic2 -->|consume| OCons
    OCons -->|publish OrderCompleted| topic3
    topic3 -->|consume| NCons
    NCons -->|invoke| NApp
    NApp -->|access| NDB

    %% Service Discovery Registrations
    Gateway -->|register| Eureka
    OApp -->|register| Eureka
    PApp -->|register| Eureka
    NApp -->|register| Eureka

    %% Observability Tracing
    Gateway -->|trace| Zipkin
    OApp -->|trace| Zipkin
    PApp -->|trace| Zipkin
    NApp -->|trace| Zipkin
    PCons1 -->|trace| Zipkin
    OCons -->|trace| Zipkin
    NCons -->|trace| Zipkin

    %% UI Connectivity
    KUI -->|connect| Broker

    %% Compose Orchestration
    Compose --> Broker
    Compose --> ZK
    Compose --> Eureka
    Compose --> Gateway
    Compose --> Zipkin
    Compose --> KUI

    %% Click Events
    click Eureka "https://github.com/yayyz/kafka-msa-example/blob/main/eureka-server/src/main/java/com/spartacoding/msa/eurekaserver/EurekaServerApplication.java"
    click Gateway "https://github.com/yayyz/kafka-msa-example/blob/main/gateway/src/main/java/com/spartacoding/msa/gateway/GatewayApplication.java"
    click OApp "https://github.com/yayyz/kafka-msa-example/blob/main/order/src/main/java/com/spartacoding/msa/order/OrderApplication.java"
    click OCtrl "https://github.com/yayyz/kafka-msa-example/blob/main/order/src/main/java/com/spartacoding/msa/order/presentaion/OrderController.java"
    click topic1 "https://github.com/yayyz/kafka-msa-example/blob/main/order/src/main/java/com/spartacoding/msa/order/OrderTopic.java"
    click PApp "https://github.com/yayyz/kafka-msa-example/blob/main/payment/src/main/java/com/spartacoding/msa/payment/PaymentApplication.java"
    click NApp "https://github.com/yayyz/kafka-msa-example/blob/main/notification/src/main/java/com/spartacoding/msa/notification/NotificationApplication.java"
    click Compose "https://github.com/yayyz/kafka-msa-example/blob/main/docker-compose.yml"

    %% Styles
    classDef discovery fill:#AED6F1,stroke:#3498DB,color:#1B4F72;
    classDef gateway fill:#D6EAF8,stroke:#5DADE2,color:#1A5276;
    classDef service fill:#A9DFBF,stroke:#28B463,color:#1D8348;
    classDef messaging fill:#F9E79F,stroke:#F4D03F,color:#7D6608;
    classDef kafka fill:#F5B7B1,stroke:#EC7063,color:#922B21;
    classDef topic fill:#E8DAEF,stroke:#AF7AC5,color:#6C3483;
    classDef db fill:#FDEBD0,stroke:#F5CBA7,color:#784212;
    classDef obs fill:#FADBD8,stroke:#EC7063,color:#7B241C;
    classDef external fill:#D5DBDB,stroke:#A6ACAF,color:#424949;
    classDef infra fill:#EBF5FB,stroke:#AED6F1,color:#21618C;
```
