# akashbhuiyan/microservice-architecture-java architecture

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

- Interactive diagram: https://gitdiagram.com/akashbhuiyan/microservice-architecture-java
- Repository: https://github.com/akashbhuiyan/microservice-architecture-java

## Overview

##### Main Components
- Microservice Applications: “accounts”, “cards”, and “loan” – each with similar structures (controllers, services, repositories, DTOs, error handling, mapping, and domain entities).
- Shared Module: “common” – holds common DTOs and entities that are reused between services.
- Infrastructure Services:
- Config Server (“configserver”) – manages external configurations using Spring Cloud Config, with specific configuration files for each microservice and different environments (dev, qa, prod).
- Eureka Server (“eurekaserver”) – manages service registration and discovery.
- Gateway Server (“gatewayserver”) – serves as the API gateway, handling routing, filtering (with request/response trace filters) and security (with components such as the KeycloakRoleConverter and security configurations).
- External Integration and Support:
- MySQL databases – separate instances for each microservice (e.g., accountsdb, loandb, cardsdb).
- RabbitMQ – used with Spring Cloud Bus to enable dynamic refresh of configurations.
- Redis server – used for rate limiting.
- Monitoring tools – Prometheus and Micrometer for application and system metrics collection and visualization in Grafana.
- Keycloak – for authentication and authorization.

##### Relationships and Data Flows
- All microservices (accounts, cards, loan) register themselves with the Eurekaserver and are routed via the Gatewayserver.
- They source their configuration data from the Configserver, which is refreshed dynamically via RabbitMQ and Spring Cloud Bus.
- Each service communicates with its underlying MySQL database.
- The Gatewayserver also integrates with security (Keycloak) and acts as the entry point for external traffic.
- Monitoring components (Prometheus and Micrometer) collect metrics from the individual microservices, while logging is centralized through Loki, with dashboards in Grafana. Redis, acting as the rate limiter, may be used by the gateway or other service components.
- Docker-compose setups indicate multiple environments (default, prod, qa, observability) that enable deployment orchestration of these components.

##### Architectural Patterns and Design Principles
- Microservices Pattern: Each service is self-contained with its own API (e.g., controllers, DTOs) and data store.
- API Gateway: Separation of concerns by channeling external requests through the Gatewayserver.
- Service Discovery: Ensured via Eureka.
- Centralized Configuration Management: Using Spring Cloud Config Server.
- Circuit Breakers & Resilience: Actuator endpoints for circuit breaker events indicate built-in resilience.
- Containerization: Dockerfiles for each service and docker-compose ensure consistent deployment.
- Observability: Comprehensive integration of metrics and logging systems (Prometheus, Grafana, Micrometer, Loki, MinIO).

##### Technology Stack and Frameworks
- Java Spring Boot for microservices.
- Spring Cloud components for configuration, discovery, gateway routing, and dynamic refresh.
- Maven as the build and dependency management tool.
- Docker for containerization.
- External systems such as RabbitMQ, MySQL, Redis, Grafana, Loki, Prometheus, and Keycloak.

- Eureka Server centrally to show service registration/discovery.
- An API gateway (gatewayserver) as the entry point for requests, highlighting its filtering and routing capabilities.
- Integration with external systems: databases (MySQL), message broker (RabbitMQ), rate limiter (Redis), log management (Grafana – Loki – MinIO), and monitoring (Prometheus – Micrometer).
- Optionally, include indications for security integration via Keycloak.

## Diagram (Mermaid)

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

    %% Infrastructure Services
    subgraph "Infrastructure Services"
        Gateway["Gateway Server"]:::gateway
        Eureka["Eureka Server"]:::service
        Config["Config Server"]:::service
        Keycloak["Keycloak"]:::security
        Redis["Redis(RateLimiter)"]:::external
    end

    %% Microservices Cluster
    subgraph "Microservices"
        subgraph "Accounts Service"
            AccCtrl["Accounts Controller"]:::micro
            AccService["Accounts Service"]:::micro
            AccRepo["Accounts Repository"]:::micro
            AccDB["Accounts DB"]:::database
            AccCtrl --> AccService
            AccService --> AccRepo
            AccRepo -->|"stores"| AccDB
        end
        subgraph "Cards Service"
            CardsCtrl["Cards Controller"]:::micro
            CardsService["Cards Service"]:::micro
            CardsRepo["Cards Repository"]:::micro
            CardsDB["Cards DB"]:::database
            CardsCtrl --> CardsService
            CardsService --> CardsRepo
            CardsRepo -->|"stores"| CardsDB
        end
        subgraph "Loan Service"
            LoanCtrl["Loan Controller"]:::micro
            LoanService["Loan Service"]:::micro
            LoanRepo["Loan Repository"]:::micro
            LoanDB["Loan DB"]:::database
            LoanCtrl --> LoanService
            LoanService --> LoanRepo
            LoanRepo -->|"stores"| LoanDB
        end
        Common["Common Module"]:::common
    end

    %% Observability & Logging
    subgraph "Observability & Logging"
        Prometheus["Prometheus"]:::monitoring
        Micrometer["Micrometer"]:::monitoring
        Grafana["Grafana"]:::monitoring
        Loki["Loki"]:::monitoring
        MinIO["MinIO"]:::monitoring
    end

    %% External Integration
    subgraph "External Integration"
        RabbitMQ["RabbitMQ"]:::external
    end

    %% Relationships
    ExternalClient -->|"APIRequest"| Gateway

    Gateway -->|"RoutesTo"| AccCtrl
    Gateway -->|"RoutesTo"| CardsCtrl
    Gateway -->|"RoutesTo"| LoanCtrl

    %% Microservices interactions with Infrastructure
    AccService -->|"Config"| Config
    CardsService -->|"Config"| Config
    LoanService -->|"Config"| Config

    AccService -->|"Registers"| Eureka
    CardsService -->|"Registers"| Eureka
    LoanService -->|"Registers"| Eureka

    %% Gateway integrations
    Gateway -->|"SecuredBy"| Keycloak
    Gateway -->|"RateLimitedBy"| Redis

    %% Config refresh mechanism
    RabbitMQ -->|"Refreshes"| Config

    %% Observability: Metrics flow from services
    AccService -->|"Metrics"| Micrometer
    CardsService -->|"Metrics"| Micrometer
    LoanService -->|"Metrics"| Micrometer

    Micrometer --> Prometheus
    Prometheus --> Grafana

    %% Observability: Log flow from services
    AccService -->|"Logs"| Loki
    CardsService -->|"Logs"| Loki
    LoanService -->|"Logs"| Loki

    Loki --> MinIO

    %% Common Module usage
    AccService -->|"Uses"| Common
    CardsService -->|"Uses"| Common
    LoanService -->|"Uses"| Common

    %% Click Events
    click AccCtrl "https://github.com/akashbhuiyan/microservice-architecture-java/tree/main/accounts/"
    click CardsCtrl "https://github.com/akashbhuiyan/microservice-architecture-java/tree/main/cards/"
    click LoanCtrl "https://github.com/akashbhuiyan/microservice-architecture-java/tree/main/loan/"
    click Common "https://github.com/akashbhuiyan/microservice-architecture-java/tree/main/common/"
    click Config "https://github.com/akashbhuiyan/microservice-architecture-java/tree/main/configserver/"
    click Eureka "https://github.com/akashbhuiyan/microservice-architecture-java/tree/main/eurekaserver/"
    click Gateway "https://github.com/akashbhuiyan/microservice-architecture-java/tree/main/gatewayserver/"

    %% Styles
    classDef micro fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef service fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
    classDef gateway fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
    classDef security fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef database fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#F39C12,stroke-width:2px;
    classDef common fill:#D6EAF8,stroke:#5DADE2,stroke-width:2px;
    classDef monitoring fill:#EBDEF0,stroke:#AF7AC5,stroke-width:2px;

    class ExternalClient,Redis,RabbitMQ external;
    class Gateway,Config,Eureka service;
    class AccCtrl,AccService,AccRepo,CardsCtrl,CardsService,CardsRepo,LoanCtrl,LoanService,LoanRepo micro;
    class AccDB,CardsDB,LoanDB database;
    class Keycloak security;
    class Common common;
    class Prometheus,Micrometer,Grafana,Loki,MinIO monitoring;
```
