# phuocphan13/microservices architecture

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

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

## Overview

##### Main Components
- API Gateways: There are at least two API gateway projects – “OcelotApiGw” and “Shopping.Aggregator” – that centrally route requests to internal services.
- Microservices: Under the “Services” folder, you have multiple domain-specific services:
– Basket Service (Services/Basket/Basket.API)
– Catalog Service (Services/Catalog/Catalog.API)
– Discount Service (Services/Discount/Discount.API and the associated gRPC service)
– Logging Service (Services/Logging/Logging.Api)
– Ordering Service (Services/Ordering/Ordering.API along with application, domain and infrastructure layers)
- Identity Service: Found under the “Identity” directory, providing authentication, token management, roles, and permissions.
- Common Libraries: Modules like “Common”, “EventBus.Messages”, “Common/Platform”, and “Common/Worker” encapsulate shared functionalities (e.g., API client code, integration framework, OpenTelemetry, worker jobs) to support cross-service needs.
- Frontend Client: The “WebApps/AngularClient” indicates an Angular-based client application that interacts with the backend services.
- Configuration & Deployment: Docker files, docker-compose files, and configuration files under “Configs” and “config” directories drive deployment and environment configuration.
- Messaging: The “EventBus.Messages” folder and related gRPC projects under Discount indicate an internal eventing system to enable service-to-service communication using messaging, including state machines for logging and order processing.

##### Relationships and Interactions
- The API gateways (Ocelot and Shopping Aggregator) serve as a single entry point for clients by forwarding requests to appropriate microservices.
- Each microservice exposes REST or gRPC endpoints used for business operations (e.g., basket management, catalog querying, discount processing, and order placement).
- The Identity service is central to securing these communication paths (with token generation, role and permission management).
- Shared “Common” libraries support cross-cutting concerns such as API client call abstractions, logging, messaging integration, unit-of-work, and more.
- The Angular Client communicates with the API gateways (and possibly directly with some services) to provide a GUI for the ecommerce functionalities.

##### Architectural Patterns and Design Principles
- Microservices Architecture: Each bounded context—basket, catalog, discount, logging, ordering, identity—resides in its own service, supporting independent development and deployment.
- Event-Driven Communication: The event bus components, state machines, and gRPC integrations are used for decoupled, asynchronous interactions.
- Shared Libraries: Common functionality (such as API clients, configuration options, logging, and database access) is centralized in shared libraries that all microservices interact with.

##### Final Recommendations to the Principal Software Engineer
- Shared libraries and message/event bus architecture that bridges different microservices, highlighting its role in decoupling and asynchronous communications.
- Cross-cutting concerns like authentication (integrating the Identity service), logging (Logging.Api along with events and state machines), and monitoring infrastructure (reflecting the configs for Grafana, Jaeger, Prometheus which are in the configuration folders).
- Remember that the goal is to be as detailed as necessary so that any stakeholder can understand the major components, their interactions, and how the system operates both at a high-level and in key subsystems.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        angular["Angular Client"]:::frontend
    end

    subgraph "API Gateways"
        ocelot["Ocelot API Gateway"]:::apiGateway
        aggregator["Shopping Aggregator"]:::apiGateway
    end

    subgraph "Microservices"
        basket["Basket Service"]:::microservice
        catalog["Catalog Service"]:::microservice
        discountRest["Discount Service (REST API)"]:::microservice
        discountGrpc["Discount Service (gRPC Service)"]:::microservice
        logging["Logging Service"]:::microservice
        ordering["Ordering Service"]:::microservice
    end

    subgraph "Identity and Security"
        identity["Identity Service"]:::externalService
    end

    subgraph "Shared Components"
        common["Common Libraries"]:::shared
        eventBus["Messaging/Event Bus"]:::shared
    end

    subgraph "Configuration & Deployment"
        config["Configs & Deployment Artifacts"]:::config
    end

    %% Frontend to API Gateways
    angular -->|"Calls"| ocelot
    angular -->|"Calls"| aggregator

    %% API Gateways to Microservices
    ocelot -->|"REST-API"| basket
    ocelot -->|"REST-API"| catalog
    ocelot -->|"REST-API"| discountRest
    ocelot -->|"REST-API"| logging
    ocelot -->|"REST-API"| ordering

    aggregator -->|"Aggregates"| basket
    aggregator -->|"Aggregates"| catalog
    aggregator -->|"Aggregates"| discountRest
    aggregator -->|"Aggregates"| logging
    aggregator -->|"Aggregates"| ordering

    %% Internal Microservice Interactions
    discountRest -->|"Calls-gRPC"| discountGrpc

    %% Microservices interact with Identity Service for authentication
    basket -->|"Auth"| identity
    catalog -->|"Auth"| identity
    discountRest -->|"Auth"| identity
    discountGrpc -->|"Auth"| identity
    logging -->|"Auth"| identity
    ordering -->|"Auth"| identity

    %% Microservices use shared components
    basket -->|"Uses"| common
    catalog -->|"Uses"| common
    discountRest -->|"Uses"| common
    discountGrpc -->|"Uses"| common
    logging -->|"Uses"| common
    ordering -->|"Uses"| common

    %% Microservices publish or subscribe to events
    basket -->|"Publishes/Event"| eventBus
    catalog -->|"Subscribes/Event"| eventBus
    logging -->|"Logs/Event"| eventBus
    ordering -->|"Publishes/Event"| eventBus

    %% Configuration manages deployments and monitoring
    config -->|"Manages"| angular
    config -->|"Manages"| ocelot
    config -->|"Manages"| aggregator
    config -->|"Manages"| basket
    config -->|"Manages"| catalog
    config -->|"Manages"| discountRest
    config -->|"Manages"| discountGrpc
    config -->|"Manages"| logging
    config -->|"Manages"| ordering
    config -->|"Monitors"| identity

    %% Click Events
    click ocelot "https://github.com/phuocphan13/microservices/tree/master/ApiGateways/OcelotApiGw"
    click aggregator "https://github.com/phuocphan13/microservices/blob/master/ApiGateways/Shopping.Aggregator"
    click basket "https://github.com/phuocphan13/microservices/blob/master/Services/Basket/Basket.API"
    click catalog "https://github.com/phuocphan13/microservices/blob/master/Services/Catalog/Catalog.API"
    click discountRest "https://github.com/phuocphan13/microservices/blob/master/Services/Discount/Discount.API"
    click discountGrpc "https://github.com/phuocphan13/microservices/blob/master/Services/Discount/Discount.Grpc"
    click logging "https://github.com/phuocphan13/microservices/blob/master/Services/Logging/Logging.Api"
    click ordering "https://github.com/phuocphan13/microservices/blob/master/Services/Ordering/Ordering.API"
    click identity "https://github.com/phuocphan13/microservices/tree/master/Identity/IdentityServer"
    click common "https://github.com/phuocphan13/microservices/tree/master/Common"
    click eventBus "https://github.com/phuocphan13/microservices/blob/master/EventBus.Messages"
    click angular "https://github.com/phuocphan13/microservices/tree/master/WebApps/AngularClient"
    click config "https://github.com/phuocphan13/microservices/tree/master/Configs"

    %% Styles
    classDef frontend fill:#FFEB3B,stroke:#000,stroke-width:2px;
    classDef apiGateway fill:#90CAF9,stroke:#000,stroke-width:2px;
    classDef microservice fill:#A5D6A7,stroke:#000,stroke-width:2px;
    classDef externalService fill:#E1BEE7,stroke:#000,stroke-width:2px;
    classDef shared fill:#FFCC80,stroke:#000,stroke-width:2px;
    classDef config fill:#F48FB1,stroke:#000,stroke-width:2px;
```
