# saiupadhyayula/spring-boot-microservices architecture

> Architecture diagram of the GitHub repository saiupadhyayula/spring-boot-microservices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saiupadhyayula/spring-boot-microservices
- Repository: https://github.com/saiupadhyayula/spring-boot-microservices

## Overview

##### Project type and overall purpose
- This is a containerized, Kubernetes-oriented Spring Boot microservices ecosystem.
- It demonstrates: service discovery (Eureka), an API Gateway, synchronous REST calls, asynchronous eventing via Kafka, per-service data stores, observability (Prometheus, Grafana, Zipkin), and centralized auth (Keycloak).

##### File structure to extract main components
- Infrastructure folder (k8s/infrastructure) defines core platform services:
– discovery-server (Eureka)
– api-gateway (Spring Cloud Gateway)
– kafka + zookeeper (event broker)
– keycloak + mysql (identity, auth)
– prometheus, grafana, zipkin (observability, tracing)
– mongo, postgres-inventory, postgres-order (databases)
- Services folder (k8s/services) deploys individual business microservices:
– inventory-service (manages inventory, backed by Postgres)
– product-service (manages product catalog, backed by e.g. Mongo or Postgres)
– order-service (manages orders, backed by Postgres)
– notification-service (listens for OrderPlacedEvent on Kafka, sends notifications)
- Source code folders correspond exactly to these runtimes.

##### Extract architectural patterns from the README and code
- API Gateway routes all external traffic
- Eureka server enables service registration & discovery
- Microservices communicate:
– Synchronously via REST (through WebClient configs in order-service)
– Asynchronously via Kafka topics (OrderPlacedEvent)
- Each service has its own database (Postgres or Mongo) – database per microservice pattern
- Cross-cutting concerns handled by infrastructure: security (Keycloak), tracing (Zipkin), metrics (Prometheus), dashboards (Grafana)

##### Components & relationships
– API Gateway
– Discovery Server
– Product Service
– Inventory Service
– Order Service
– Notification Service
– Kafka Cluster + Zookeeper
– Keycloak (with MySQL)
– Postgres (Order DB)
– Postgres (Inventory DB)
– MongoDB (Product DB)
– Prometheus, Grafana, Zipkin
– Client → API Gateway → Discovery Server (for routing lookup) → Services
– Order Service → Inventory Service (REST call)
– Order Service publishes OrderPlacedEvent → Kafka → Notification Service
– Services connect to their own DBs
– Services / Gateway send metrics & traces → Prometheus & Zipkin
– Grafana reads metrics from Prometheus
– Keycloak secures API Gateway and microservices (OIDC tokens)
c. Key architectural patterns to note:
– API Gateway pattern
– Service Discovery (Eureka)
– Circuit breaker / resilient calls (if present in WebClientConfig)
– Event-driven architecture (Kafka topics)
– Database per service
– Observability pipeline (metrics, tracing, dashboards)
– Centralized authentication/authorization
d. Technologies (annotate each component):
– Spring Cloud Gateway, Eureka Server, Spring Boot
– Spring WebFlux or WebClient, Spring Kafka
– PostgreSQL, MongoDB
– Apache Kafka, Zookeeper
– Keycloak, MySQL
– Prometheus, Grafana, Zipkin
– Kubernetes (Deployments, Services in k8s folder), Docker

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External
    User["External Client"]:::external

    subgraph "Kubernetes Cluster"
        subgraph "Infrastructure"
            Gateway["API Gateway\n(Spring Cloud Gateway)"]:::service
            Eureka["Discovery Server\n(Spring Eureka)"]:::service
            Kafka["Kafka Cluster"]:::bus
            ZK["Zookeeper"]:::bus
            Keycloak["Keycloak"]:::security
            KCMySQL["MySQL"]:::db
            PostOrderDB["Postgres\n(Order DB)"]:::db
            PostInvDB["Postgres\n(Inventory DB)"]:::db
            MongoDB["MongoDB\n(Product DB)"]:::db
        end

        subgraph "Business Services"
            Prod["Product Service"]:::service
            Inv["Inventory Service"]:::service
            Order["Order Service"]:::service
            Notif["Notification Service"]:::service
        end

        subgraph "Observability"
            Prom["Prometheus"]:::obs
            Grafana["Grafana"]:::obs
            Zipkin["Zipkin"]:::obs
        end
    end

    %% Client to Gateway
    User --> Gateway

    %% API Gateway flows
    Gateway --> Eureka
    Gateway --> Prod
    Gateway --> Inv
    Gateway --> Order
    Gateway --> Notif

    %% Service Discovery registration
    Prod --> Eureka
    Inv --> Eureka
    Order --> Eureka
    Notif --> Eureka

    %% Synchronous REST call
    Order -->|REST call| Inv

    %% Asynchronous Kafka events
    Order -->|publish order-placed| Kafka
    Kafka -->|consume order-placed| Notif
    ZK --> Kafka

    %% Databases per service
    Prod --> MongoDB
    Inv --> PostInvDB
    Order --> PostOrderDB

    %% Security (OIDC)
    Gateway -->|OIDC auth| Keycloak
    Prod -->|validate token| Keycloak
    Inv -->|validate token| Keycloak
    Order -->|validate token| Keycloak
    Notif -->|validate token| Keycloak
    Keycloak --> KCMySQL

    %% Observability pipeline
    Gateway --> Prom
    Prod --> Prom
    Inv --> Prom
    Order --> Prom
    Notif --> Prom
    Gateway --> Zipkin
    Prod --> Zipkin
    Inv --> Zipkin
    Order --> Zipkin
    Notif --> Zipkin
    Grafana -->|reads metrics| Prom

    %% Click Events
    click Gateway "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/api-gateway/"
    click Eureka "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/discovery-server/"
    click Prod "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/product-service/"
    click Inv "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/inventory-service/"
    click Order "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/order-service/"
    click Notif "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/notification-service/"
    click Kafka "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/k8s/infrastructure/kafka/"
    click ZK "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/k8s/infrastructure/zookeeper/"
    click Keycloak "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/k8s/infrastructure/keycloak/"
    click KCMySQL "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/k8s/infrastructure/keycloak-mysql/"
    click PostOrderDB "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/k8s/infrastructure/postgres-order/"
    click PostInvDB "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/k8s/infrastructure/postgres-inventory/"
    click MongoDB "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/k8s/infrastructure/mongodb/"
    click Prom "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/k8s/infrastructure/prometheus/"
    click Grafana "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/k8s/infrastructure/grafana/"
    click Zipkin "https://github.com/saiupadhyayula/spring-boot-microservices/tree/master/k8s/infrastructure/zipkin/"

    %% Styles
    classDef service fill:#D0E6FF,stroke:#2B579A,color:#000
    classDef db fill:#DFFFE0,stroke:#237804,color:#000
    classDef bus fill:#FFE6A8,stroke:#d46b08,color:#000
    classDef obs fill:#EBDDFC,stroke:#5B2C6F,color:#000
    classDef security fill:#FFD2D2,stroke:#992D22,color:#000
    classDef external fill:#C0C0C0,stroke:#606060,color:#000
```
