# hzeroxium/spring-petclinic-microservices architecture

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

- Interactive diagram: https://gitdiagram.com/hzeroxium/spring-petclinic-microservices
- Repository: https://github.com/hzeroxium/spring-petclinic-microservices

## Overview

##### Core Components
- API Gateway: Represented by the “spring-petclinic-api-gateway” module, this component acts as the front door for client requests, handling routing, load balancing, circuit breaking (with Resilience4j), and fallback logic.
- Service Discovery: Mark the “spring-petclinic-discovery-server” which registers all microservices (Customers, Vets, Visits, GenAI, etc.) making them discoverable.
- Config Server: Show the “spring-petclinic-config-server” which centralizes configuration management for all services.
- Business Services:
- Customers Service: Handles customer data and related operations.
- Vets Service: Manages veterinarian information.
- Visits Service: Deals with pet visit records.
- GenAI Service: Adds artificial intelligence/chatbot capabilities for natural language interactions.
- Spring Petclinic Admin Server: Provides administrative and monitoring capabilities.
- External/Supporting Components:
- Monitoring & Metrics: Include Grafana and Prometheus containers (their Docker files and configurations are provided in the “docker” directory).
- Database: Indicate that each service (such as Customers, Vets, Visits) can use either an in-memory HSQLDB or a MySQL instance based on the active profile.
- CI/CD & Deployment: Optionally include Jenkins pipelines (Jenkinsfile) and Docker Compose orchestration that tie the system together.
- Chaos Monkey/Resilience Testing: Represent the “scripts/chaos” utilities used for fault injection.

##### Relationships and Data Flows
- From the API Gateway, illustrate request routing to each microservice.
- Dependencies with the database for data persistence.

##### Architectural Patterns and Design Principles
- Microservices Architecture: Emphasize the decoupled services each running in separate containers or pods, with their own codebases and data management strategies.
- API Gateway pattern: Centralize request handling, facilitate cross-cutting concerns such as circuit breaking, rate limiting and security.
- Service Discovery and Config Management: Highlight the usage of Eureka and Spring Cloud Config.
- Resilience Patterns: Indicate aspects like circuit breakers (as seen in the API Gateway’s fallback methods) and Chaos Monkey experiments for testing failure resilience.
- Containerization: Include Docker Compose orchestration and Dockerfiles for individual services to denote containerized deployment across platforms (both Docker and Podman are supported).

##### Specify Technologies and Frameworks
- Java 17 & Spring Boot for the microservices
- Spring Cloud, including Eureka, Cloud Gateway, Cloud Config, and Circuit Breaker (Resilience4j)
- Docker (with docker-compose) for container orchestration
- Grafana and Prometheus for monitoring and metrics gathering
- Maven for building and managing dependencies
- Jenkins for CI/CD processes
- Optional Chaos Monkey scripts for resilience testing

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients"
        client("Browser/Mobile Client"):::client
    end

    %% API & Service Layer
    subgraph "API & Service Layer"
        apiGateway("API Gateway"):::gateway
        discovery("Service Discovery (Eureka)"):::discovery
        config("Config Server"):::config
    end

    %% Business Services Layer
    subgraph "Business Services"
        customers("Customers Service"):::service
        vets("Vets Service"):::service
        visits("Visits Service"):::service
        genai("GenAI Service"):::service
        admin("Admin Server"):::service
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        database("Database (HSQLDB/MySQL)"):::infra
        grafana("Grafana"):::infra
        prometheus("Prometheus"):::infra
        jenkins("Jenkins CI/CD"):::infra
        compose("Docker Compose"):::infra
        chaos("Chaos Monkey/Resilience Testing"):::infra
    end

    %% Relationships between Layers
    client -->|"requests"| apiGateway

    apiGateway -->|"routes"| customers
    apiGateway -->|"routes"| vets
    apiGateway -->|"routes"| visits
    apiGateway -->|"routes"| genai
    apiGateway -->|"routes"| admin
    apiGateway -->|"queries"| discovery

    customers -->|"registers"| discovery
    vets -->|"registers"| discovery
    visits -->|"registers"| discovery
    genai -->|"registers"| discovery
    admin -->|"registers"| discovery

    customers <-->|"fetchesConfig"| config
    vets <-->|"fetchesConfig"| config
    visits <-->|"fetchesConfig"| config
    genai <-->|"fetchesConfig"| config
    admin <-->|"fetchesConfig"| config

    customers -->|"persistsData"| database
    vets -->|"persistsData"| database
    visits -->|"persistsData"| database
    genai -->|"persistsData"| database
    admin -->|"persistsData"| database

    customers ---|"metrics"| prometheus
    vets ---|"metrics"| prometheus
    visits ---|"metrics"| prometheus
    genai ---|"metrics"| prometheus
    admin ---|"metrics"| prometheus

    grafana ---|"visualizes"| prometheus

    jenkins ---|"orchestrates"| apiGateway
    jenkins ---|"orchestrates"| customers
    jenkins ---|"orchestrates"| vets
    jenkins ---|"orchestrates"| visits
    jenkins ---|"orchestrates"| genai
    jenkins ---|"orchestrates"| admin

    compose ---|"orchestrates"| apiGateway
    compose ---|"orchestrates"| customers
    compose ---|"orchestrates"| vets
    compose ---|"orchestrates"| visits
    compose ---|"orchestrates"| genai
    compose ---|"orchestrates"| admin

    chaos ---|"injectsFaults"| customers
    chaos ---|"injectsFaults"| vets
    chaos ---|"injectsFaults"| visits
    chaos ---|"injectsFaults"| genai
    chaos ---|"injectsFaults"| admin

    %% Click Events for Component Mapping
    click apiGateway "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/spring-petclinic-api-gateway/"
    click discovery "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/spring-petclinic-discovery-server/"
    click config "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/spring-petclinic-config-server/"
    click customers "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/spring-petclinic-customers-service/"
    click vets "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/spring-petclinic-vets-service/"
    click visits "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/spring-petclinic-visits-service/"
    click genai "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/spring-petclinic-genai-service/"
    click admin "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/spring-petclinic-admin-server/"
    click grafana "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/docker/grafana/"
    click prometheus "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/docker/prometheus/"
    click jenkins "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/Jenkinsfile"
    click compose "https://github.com/hzeroxium/spring-petclinic-microservices/blob/main/docker-compose.yml"
    click chaos "https://github.com/hzeroxium/spring-petclinic-microservices/tree/main/scripts/chaos/"

    %% Styles
    classDef client fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef gateway fill:#66CCFF,stroke:#333,stroke-width:2px;
    classDef discovery fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef config fill:#98F0FF,stroke:#333,stroke-width:2px;
    classDef service fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef infra fill:#D8BFD8,stroke:#333,stroke-width:2px;
```
