# gz-yami/mall4cloud architecture

> Architecture diagram of the GitHub repository gz-yami/mall4cloud, 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/gz-yami/mall4cloud
- Repository: https://github.com/gz-yami/mall4cloud

## Overview

This project is a fully featured microservices-based B2B2C ecommerce system. Its architecture uses a modern Spring Cloud ecosystem (with Spring Boot, Nacos, Seata, and more) combined with popular third‐party middlewares such as MySQL, Redis, RocketMQ, Canal, ElasticSearch, and Minio for storage. The readme makes it clear that the system is designed to support a full ecommerce flow including platform management, store (merchant) management, product management, order processing, payment, and user (rbac and customer) management.

##### Main Components
– mall4cloud-gateway (API Gateway)
– mall4cloud-auth (Authorization and authentication service)
– mall4cloud-biz (Business utility and infrastructure functions such as image uploads and SMS)
– mall4cloud-leaf (ID generation service based on a Meituan Leaf implementation)
– mall4cloud-multishop (Merchant/service side)
– mall4cloud-order (Order service)
– mall4cloud-payment (Payment processing)
– mall4cloud-product (Product/commodity service)
– mall4cloud-rbac (User roles and permissions management)
– mall4cloud-search (Search functionality based on ElasticSearch and Canal integration)
– mall4cloud-user (User service)

- Shared Components – In addition to the core microservices, show centers for common or cross-cutting concerns. For example:
– The central service registry/discovery (Nacos)
– Distributed transaction management (Seata)
– Caching (Redis)
– Messaging system (RocketMQ)
– Persistence layer (MySQL with supporting modules for database interaction)
– File Management (Minio) and search indices (ElasticSearch)
– Common libraries (mall4cloud-common modules with aspects like caching, security, database, etc.) that are used by many services.

##### Relationships and Interactions
- That the service registry (Nacos) is central to dynamic discovery, and that configuration management and distributed transactions (via Seata) connect to many services.
- Messaging flows using RocketMQ that may trigger events (such as order cancel notifications, stock updates, etc.) across services and in the search module.

##### Architectural Patterns and Design Principles
- API Gateway Pattern – Clearly position mall4cloud-gateway as the entry point.
- Distributed Transaction Management – Highlight the usage of Seata for handling consistent business transactions across multiple services (e.g., order and payment consistency).
- Service Discovery – Emphasize the role of Nacos for registry and discovery.
- Event-Driven Communication – Represent RocketMQ (and Canal for database log streaming) signaling event based interactions.
- Layered Approach – Indicate how each service implements a structure that commonly spans from Controllers, through Service/Manager layers, down to Mappers/DAO layers.

##### Technologies
- External integrations such as Canal feeding changes into the Search module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        Platform["Platform Client"]:::client
        Merchant["Merchant Client"]:::client
        Mobile["Mobile Client"]:::client
        FRONTEND["Front-end Client Applications"]:::client
    end

    %% API Gateway
    GATEWAY["mall4cloud-gateway (API Gateway)"]:::blue

    %% Microservices
    subgraph "Microservices"
        AUTH["mall4cloud-auth (Auth)"]:::blue
        BIZ["mall4cloud-biz (Business)"]:::blue
        LEAF["mall4cloud-leaf (ID Generator)"]:::blue
        MULTISHOP["mall4cloud-multishop (Merchant)"]:::green
        ORDER["mall4cloud-order (Order)"]:::green
        PAYMENT["mall4cloud-payment (Payment)"]:::green
        PRODUCT["mall4cloud-product (Product)"]:::green
        RBAC["mall4cloud-rbac (RBAC)"]:::green
        SEARCH["mall4cloud-search (Search)"]:::green
        USER["mall4cloud-user (User)"]:::green
    end

    %% Infrastructure & Shared Components
    subgraph "Infrastructure & Shared Components"
        NACOS["Nacos (Service Registry)"]:::orange
        SEATA["Seata (Distributed Transaction)"]:::orange
        ROCKETMQ["RocketMQ (Messaging)"]:::orange
        REDIS["Redis (Caching)"]:::orange
        MYSQL["MySQL (Database)"]:::orange
        MINIO["Minio (File Storage)"]:::orange
        ELASTIC["ElasticSearch (Search Index)"]:::orange
        CANAL["Canal (DB Log Streaming)"]:::orange
        COMMON_LIBS["Common Libraries"]:::orange
        DB_SCRIPTS["DB Scripts"]:::orange
        DOCS["Infra Docs"]:::orange
    end

    %% Connections from Clients to API Gateway
    Platform -->|"Request"| GATEWAY
    Merchant -->|"Request"| GATEWAY
    Mobile -->|"Request"| GATEWAY
    FRONTEND -->|"Request"| GATEWAY

    %% Gateway routes to Microservices
    GATEWAY -->|"HTTP"| AUTH
    GATEWAY -->|"HTTP"| BIZ
    GATEWAY -->|"HTTP"| LEAF
    GATEWAY -->|"HTTP"| MULTISHOP
    GATEWAY -->|"HTTP"| ORDER
    GATEWAY -->|"HTTP"| PAYMENT
    GATEWAY -->|"HTTP"| PRODUCT
    GATEWAY -->|"HTTP"| RBAC
    GATEWAY -->|"HTTP"| SEARCH
    GATEWAY -->|"HTTP"| USER

    %% Inter-service communications
    ORDER -->|"Feign"| PAYMENT
    ORDER -->|"Message"| ROCKETMQ
    ROCKETMQ -->|"Message"| PAYMENT
    ROCKETMQ -->|"Message"| SEARCH

    %% Service discovery via Nacos
    GATEWAY -->|"Discovery"| NACOS
    AUTH -->|"Discovery"| NACOS
    BIZ -->|"Discovery"| NACOS
    LEAF -->|"Discovery"| NACOS
    MULTISHOP -->|"Discovery"| NACOS
    ORDER -->|"Discovery"| NACOS
    PAYMENT -->|"Discovery"| NACOS
    PRODUCT -->|"Discovery"| NACOS
    RBAC -->|"Discovery"| NACOS
    SEARCH -->|"Discovery"| NACOS
    USER -->|"Discovery"| NACOS

    %% Distributed Transactions using Seata
    ORDER -->|"TX"| SEATA
    PAYMENT -->|"TX"| SEATA

    %% Database interactions with MySQL
    GATEWAY -->|"DB"| MYSQL
    AUTH -->|"DB"| MYSQL
    BIZ -->|"DB"| MYSQL
    MULTISHOP -->|"DB"| MYSQL
    ORDER -->|"DB"| MYSQL
    PAYMENT -->|"DB"| MYSQL
    PRODUCT -->|"DB"| MYSQL
    RBAC -->|"DB"| MYSQL
    SEARCH -->|"DB"| MYSQL
    USER -->|"DB"| MYSQL

    %% Caching with Redis (selected services)
    AUTH -->|"Cache"| REDIS
    BIZ -->|"Cache"| REDIS
    ORDER -->|"Cache"| REDIS
    PRODUCT -->|"Cache"| REDIS

    %% File storage via Minio
    BIZ -->|"File"| MINIO

    %% Search service integrations
    SEARCH -->|"Index"| ELASTIC
    SEARCH -->|"Logs"| CANAL

    %% Common Libraries used by many services (dotted connections)
    COMMON_LIBS ---|"usedBy"| GATEWAY
    COMMON_LIBS ---|"usedBy"| AUTH
    COMMON_LIBS ---|"usedBy"| BIZ
    COMMON_LIBS ---|"usedBy"| LEAF
    COMMON_LIBS ---|"usedBy"| MULTISHOP
    COMMON_LIBS ---|"usedBy"| ORDER
    COMMON_LIBS ---|"usedBy"| PAYMENT
    COMMON_LIBS ---|"usedBy"| PRODUCT
    COMMON_LIBS ---|"usedBy"| RBAC
    COMMON_LIBS ---|"usedBy"| SEARCH
    COMMON_LIBS ---|"usedBy"| USER

    %% Click Events for Component Mapping
    click GATEWAY "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-gateway/"
    click AUTH "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-auth/"
    click BIZ "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-biz/"
    click LEAF "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-leaf/"
    click MULTISHOP "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-multishop/"
    click ORDER "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-order/"
    click PAYMENT "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-payment/"
    click PRODUCT "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-product/"
    click RBAC "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-rbac/"
    click SEARCH "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-search/"
    click USER "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-user/"
    click DB_SCRIPTS "https://github.com/gz-yami/mall4cloud/tree/master/db/"
    click COMMON_LIBS "https://github.com/gz-yami/mall4cloud/tree/master/mall4cloud-common/"
    click DOCS "https://github.com/gz-yami/mall4cloud/tree/master/doc/"
    click FRONTEND "https://github.com/gz-yami/mall4cloud/tree/master/front-end/"

    %% Styles
    classDef blue fill:#ccf,stroke:#000,stroke-width:2px;
    classDef green fill:#cfc,stroke:#000,stroke-width:2px;
    classDef orange fill:#fc9,stroke:#000,stroke-width:2px;
    classDef client fill:#fdd,stroke:#000,stroke-width:2px;
```
