# haunguyendev/microservices architecture

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

- Interactive diagram: https://gitdiagram.com/haunguyendev/microservices
- Repository: https://github.com/haunguyendev/microservices

## Overview

##### Main Components
- API Gateway: Represented by the “OcelotApiGw” service inside the src/ApiGateways directory. This component acts as the front door routing client requests to the appropriate microservice.
- Microservices: Each service is defined under the src/Service directory and includes:
– Basket API
– Customer API
– Hangfire API
– Inventory API
– Ordering API
– Product API
- Web Applications: Specifically, the WebHealthStatus project in src/WebApps which likely provides health/status monitoring or a simple UI.
- Building Blocks/Shared Libraries: These are in the src/BuildingBlocks section and provide cross-cutting concerns such as logging (Common.Logging), contracts (interfaces, domains, DTOs), infrastructure (repository and unit-of-work implementations), and shared functionalities.
- External Dependencies & Infrastructure: The project makes use of several Dockerized external services (e.g., RabbitMQ, Kibana, Portainer and possibly SQL Server/MySQL as databases) as described in the README.

##### Relationships and Interactions
- Clients initiate requests that first hit the API Gateway.
- The API Gateway routes calls to the corresponding microservices (e.g., requests for product data go to Product API, customer data to Customer API, etc.).
- Each microservice is responsible for its domain logic and interacts with the shared building blocks for cross-cutting concerns such as logging, data access (repository pattern), and messaging (event bus messages).
- There is likely an event-driven communication aspect (see “EventBus.Messages”) that enables asynchronous interactions between services.
- The WebHealthStatus application serves as a monitoring or status dashboard, possibly interacting with the other services to display system health.
- Docker Compose is used to manage the runtime environment, with containers for microservices and external applications.

##### Architectural Patterns and Design Principles
- Microservices Architecture: The system is split into discrete, independently deployable services.
- API Gateway Pattern: Ocelot serves this role by abstracting the complexity of the underlying microservices.
- Repository and Unit-of-Work Patterns: As seen in the building blocks (IRepositoryBaseAsync, UnitOfWork) and infrastructure directories, ensuring proper data handling.
- Shared Libraries: Common contracts and DTOs ensure consistency and reduce duplicated code.
- Containerization: Docker Compose is used for orchestration, suggesting container-based deployment.
- Asynchronous Messaging/Event Bus: Include messaging components that facilitate inter-service communication.

##### Relevant Technologies
- ASP.NET Core (.NET 6 from global.json)
- Docker (with docker-compose)
- Ocelot (API Gateway)
- Hangfire (for background tasks)
- Possibly Entity Framework Core for data access (evidenced by the existence of migrations and repository patterns)
- Logging via Serilog (developers can note the Serilogger in BuildingBlocks/Common.Logging)
- External tools: RabbitMQ, Kibana, and Portainer

## Diagram (Mermaid)

```mermaid
flowchart TD
    CLIENT["Clients"]:::externalClient

    APIGW["Ocelot API Gateway"]:::gateway

    CLIENT -->|"send_request"| APIGW

    subgraph "Microservices"
        direction TB
        BASKET["Basket API"]:::service
        CUSTOMER["Customer API"]:::service
        HANGFIRE["Hangfire API"]:::service
        INVENTORY["Inventory API"]:::service
        ORDERING["Ordering API"]:::service
        PRODUCT["Product API"]:::service
    end

    APIGW -->|"routes_to"| BASKET
    APIGW -->|"routes_to"| CUSTOMER
    APIGW -->|"routes_to"| HANGFIRE
    APIGW -->|"routes_to"| INVENTORY
    APIGW -->|"routes_to"| ORDERING
    APIGW -->|"routes_to"| PRODUCT

    subgraph "Web Applications"
        direction TB
        WEBHEALTH["Health/Status Dashboard"]:::web
    end

    subgraph "Shared Building Blocks"
        direction TB
        COMMON_LOGGING["Common Logging"]:::shared
        CONTRACTS["Contracts & Domain Models"]:::shared
        INFRASTRUCTURE["Repository & Unit-of-Work"]:::shared
        SHARED_DTOS["Shared DTOs"]:::shared
        EVENT_BUS["Event Bus Messaging"]:::shared
    end

    subgraph "External Dependencies"
        direction TB
        RABBITMQ["RabbitMQ"]:::external
        KIBANA["Kibana"]:::external
        PORTAINER["Portainer"]:::external
        DB["SQL Database"]:::external
    end

    %% Microservices interactions with Shared Building Blocks
    BASKET -->|"uses"| COMMON_LOGGING
    BASKET -->|"uses"| CONTRACTS
    BASKET -->|"uses"| INFRASTRUCTURE
    BASKET -->|"publishes"| EVENT_BUS

    CUSTOMER -->|"uses"| COMMON_LOGGING
    CUSTOMER -->|"uses"| CONTRACTS
    CUSTOMER -->|"uses"| INFRASTRUCTURE
    CUSTOMER -->|"publishes"| EVENT_BUS

    HANGFIRE -->|"uses"| COMMON_LOGGING
    HANGFIRE -->|"uses"| CONTRACTS
    HANGFIRE -->|"uses"| INFRASTRUCTURE

    INVENTORY -->|"uses"| COMMON_LOGGING
    INVENTORY -->|"uses"| CONTRACTS
    INVENTORY -->|"uses"| INFRASTRUCTURE
    INVENTORY -->|"publishes"| EVENT_BUS

    ORDERING -->|"uses"| COMMON_LOGGING
    ORDERING -->|"uses"| CONTRACTS
    ORDERING -->|"uses"| INFRASTRUCTURE
    ORDERING -->|"publishes"| EVENT_BUS

    PRODUCT -->|"uses"| COMMON_LOGGING
    PRODUCT -->|"uses"| CONTRACTS
    PRODUCT -->|"uses"| INFRASTRUCTURE
    PRODUCT -->|"publishes"| EVENT_BUS

    %% Web Dashboard polling microservices
    WEBHEALTH -->|"polls"| BASKET
    WEBHEALTH -->|"polls"| CUSTOMER
    WEBHEALTH -->|"polls"| HANGFIRE
    WEBHEALTH -->|"polls"| INVENTORY
    WEBHEALTH -->|"polls"| ORDERING
    WEBHEALTH -->|"polls"| PRODUCT

    %% Microservices external interactions (messaging, logging, deployment, data storage)
    BASKET -->|"sends_to"| RABBITMQ
    CUSTOMER -->|"sends_to"| RABBITMQ
    INVENTORY -->|"sends_to"| RABBITMQ
    ORDERING -->|"sends_to"| RABBITMQ
    PRODUCT -->|"sends_to"| RABBITMQ

    BASKET -->|"logs_to"| KIBANA
    CUSTOMER -->|"logs_to"| KIBANA
    HANGFIRE -->|"logs_to"| KIBANA
    INVENTORY -->|"logs_to"| KIBANA
    ORDERING -->|"logs_to"| KIBANA
    PRODUCT -->|"logs_to"| KIBANA

    BASKET -->|"deployed_on"| PORTAINER
    CUSTOMER -->|"deployed_on"| PORTAINER
    HANGFIRE -->|"deployed_on"| PORTAINER
    INVENTORY -->|"deployed_on"| PORTAINER
    ORDERING -->|"deployed_on"| PORTAINER
    PRODUCT -->|"deployed_on"| PORTAINER

    BASKET -->|"stores_in"| DB
    CUSTOMER -->|"stores_in"| DB
    HANGFIRE -->|"stores_in"| DB
    INVENTORY -->|"stores_in"| DB
    ORDERING -->|"stores_in"| DB
    PRODUCT -->|"stores_in"| DB

    %% Click Events
    click APIGW "https://github.com/haunguyendev/microservices/tree/main/src/ApiGateways/OcelotApiGw"
    click BASKET "https://github.com/haunguyendev/microservices/blob/main/src/Service/Basket.API"
    click CUSTOMER "https://github.com/haunguyendev/microservices/blob/main/src/Service/Customer.API"
    click HANGFIRE "https://github.com/haunguyendev/microservices/blob/main/src/Service/Hangfire.API"
    click INVENTORY "https://github.com/haunguyendev/microservices/blob/main/src/Service/Inventory.API"
    click ORDERING "https://github.com/haunguyendev/microservices/blob/main/src/Service/Ordering.API"
    click PRODUCT "https://github.com/haunguyendev/microservices/blob/main/src/Service/Product.API"
    click WEBHEALTH "https://github.com/haunguyendev/microservices/tree/main/src/WebApps/WebHealthStatus"
    click COMMON_LOGGING "https://github.com/haunguyendev/microservices/blob/main/src/BuildingBlocks/Common.Logging"
    click CONTRACTS "https://github.com/haunguyendev/microservices/tree/main/src/BuildingBlocks/Contracts"
    click INFRASTRUCTURE "https://github.com/haunguyendev/microservices/tree/main/src/BuildingBlocks/Infrastructure"
    click SHARED_DTOS "https://github.com/haunguyendev/microservices/tree/main/src/BuildingBlocks/Shared/DTOs"
    click EVENT_BUS "https://github.com/haunguyendev/microservices/blob/main/src/BuildingBlocks/EventBus.Messages"

    %% Styles
    classDef gateway fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef service fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef shared fill:#abebc6,stroke:#333,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#333,stroke-width:2px;
    classDef web fill:#d2b4de,stroke:#333,stroke-width:2px;
    classDef externalClient fill:#f7dc6f,stroke:#333,stroke-width:2px;
```
