# hnjaman/complete-microservice-application architecture

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

- Interactive diagram: https://gitdiagram.com/hnjaman/complete-microservice-application
- Repository: https://github.com/hnjaman/complete-microservice-application

## Overview

##### Main Components
- Frontend: microservice-ui (an Angular-based application running on port 3000 that consumes backend services).
- Service Registry: service-registry (a Spring Boot application implementing Eureka, running on port 8761, which handles service discovery).
- API Gateway: api-gateway (a Spring Boot application that uses Zuul and Ribbon for dynamic routing, load balancing, and fault tolerance via Hystrix, running on port 8000).
- Backend Services: Two main microservices:
- product-service – exposing product endpoints, running on multiple instances (one at port 8081 and another at 8180), and connected to its own H2 database.
- offer-service – exposing offer endpoints, running on port 8082, using its own H2 database.
- Message Broker: RabbitMQ – not part of the source tree but integrated as a common messaging service for asynchronous, event-driven communication between offer-service (producer) and product-service (consumer).

##### Relationships and Interactions
- The microservice-ui frontend calls the API Gateway (http://localhost:8000) at specific paths (like “/product-service/products” and “/offer-service/offer”) to interact with the backend.
- The API Gateway receives incoming requests from clients and, using routing rules (through Zuul and Ribbon), forwards them to the appropriate backend service instance. It also provides load balancing (round-robin between product-service instances).
- Each backend service (product-service and offer-service) registers itself with the Service Registry (Eureka) for easy discovery by the API Gateway.
- The offer-service pushes event notifications (containing discount information) to RabbitMQ. The product-service subscribes to these events, receiving them asynchronously to update its database.
- Underlying databases (H2 for each microservice) and include the fact that they are independent.

##### Architectural Patterns and Design Principles
- Emphasis on microservice fundamentals: independent deployability, scalability, and inter-service communication.
- Use of API Gateway design pattern: central entry point, request routing, load balancing, centralized authentication/security.
- Service Discovery (using Eureka) is a critical pattern that allows decoupling of service endpoints.
- Event Driven Architecture (EDA) using RabbitMQ ensures asynchronous, decoupled communication, ensuring eventual consistency between services.
- Resilience patterns are also visible (e.g., Hystrix for circuit breaking) to prevent cascading failures.

##### Relevant Technologies and Frameworks
- Frontend: Angular (Angular CLI, Node, npm packages).
- Backend: Java, Spring Boot, Maven; specific libraries include Hystrix for circuit breaking in the API Gateway and Ribbon for load balancing.
- Service Registry: Eureka (Spring Cloud Netflix Eureka).
- API Gateway: Zuul (Spring Cloud Netflix Zuul).
- Messaging: RabbitMQ.
- Persistence: H2 databases for product-service and offer-service.
- Testing components and build tools including Maven and configuration files (pom.xml, application.properties/yml) show how each module is set up.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        UI["Microservice UI (Angular) (Port 3000)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        subgraph "API Gateway Service"
            APIG["API Gateway (Zuul/Ribbon/Hystrix) (Port 8000)"]:::backend
        end
        subgraph "Service Discovery"
            SR["Service Registry (Eureka) (Port 8761)"]:::infrastructure
        end
        subgraph "Product Service Cluster"
            PS1["Product Service Instance (Port 8081)"]:::backend
            PS2["Product Service Instance (Port 8180)"]:::backend
            PSDB["H2 Database (Product Service)"]:::database
        end
        subgraph "Offer Service Domain"
            OS["Offer Service (Port 8082)"]:::backend
            OSDB["H2 Database (Offer Service)"]:::database
        end
        RMQ["RabbitMQ Messaging"]:::messaging
    end

    %% Connections
    UI -->|"RESTcalls"| APIG
    APIG -->|"Routes"| PS1
    APIG -->|"Routes"| OS
    APIG -->|"Registers"| SR
    PS1 -->|"Registers"| SR
    PS2 -->|"Registers"| SR
    OS -->|"Registers"| SR
    OS -->|"PublishesEvent"| RMQ
    RMQ -->|"DeliversEvent"| PS1
    RMQ -->|"DeliversEvent"| PS2

    %% Class definitions with colours
    classDef frontend fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef backend fill:#87CEFA,stroke:#4682B4,stroke-width:2px;
    classDef infrastructure fill:#90EE90,stroke:#228B22,stroke-width:2px;
    classDef messaging fill:#FFB6C1,stroke:#DB7093,stroke-width:2px,stroke-dasharray: 5 5;
    classDef database fill:#F08080,stroke:#CD5C5C,stroke-width:2px,stroke-dasharray: 2 2;

    %% Click Events
    click UI "https://github.com/hnjaman/complete-microservice-application/tree/master/microservice-ui"
    click SR "https://github.com/hnjaman/complete-microservice-application/tree/master/service-registry"
    click APIG "https://github.com/hnjaman/complete-microservice-application/tree/master/api-gateway"
    click PS1 "https://github.com/hnjaman/complete-microservice-application/tree/master/product-service"
    click PS2 "https://github.com/hnjaman/complete-microservice-application/tree/master/product-service"
    click OS "https://github.com/hnjaman/complete-microservice-application/tree/master/offer-service"
```
