# dohongkien/mall architecture

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

## Overview

##### High-Level Components
- Backend Services:
– mall‑admin: Handles management interfaces and administrative operations.
– mall‑portal: Provides the public storefront, shopping cart, orders, and user-related functionalities.
– mall‑search: Implements product search capabilities using Elasticsearch.
– mall‑mbg: Contains the MyBatis Generator output for data access and mapping.
– mall‑common: Provides shared utilities, API response wrappers, error handling and configurations.
– mall‑security: Encapsulates authentication, authorization, and security-related cross-cutting concerns.
- Frontend/Client Applications:
– Although not part of the provided file tree, the README refers to separate front‑end projects (mall‑admin‑web and mall‑app‑web) which should be noted as clients interacting with the backend.
- Data & External Infrastructure:
– Databases: MySQL (primary datastore), Redis (caching), MongoDB (NoSQL support mentioned), etc.
– Message Queue: RabbitMQ.
– Search Engine: Elasticsearch.
– File/Object Storage: OSS/MinIO for static resources (as per configuration files).
– Log Infrastructure: ELK stack (Logstash, Kibana) for log aggregation and visualization.
– Web Server and Reverse Proxy: Nginx (with provided configuration in document/docker/nginx.conf).
– Containerization & Deployment: Docker (with Dockerfiles, docker-compose and Jenkins deployment scripts).

##### Depicting Component Relationships
– Add a “Data Layer” block that shows MySQL and Redis, plus optionally MongoDB and the ELK stack.
- External service interactions:
– Connect the client applications (mall‑admin‑web, mall‑app‑web) with the corresponding backend services using API calls.
- Integration points:
– mall‑mbg outputs integration with the database.
– mall‑common is used across modules.
– mall‑security applies authentication filters and JWT handling across all services.
- Containerization:

##### Architectural Patterns & Design Principles
- Separation of concerns – each module (administration, portal, search, security, etc.) encapsulates a distinct business functionality.
- Use of Spring Boot micro‑service principles (even if running in a monolithic style, the project is modularized) with clear boundaries.
- API design, with the separation between front‑end (client) and backend (service) through RESTful endpoints.
- The layered architecture is evident: presentation layer (clients), application/service layer (mall‑admin, mall‑portal, mall‑search), data access layer (mall‑mbg, connection to databases), and cross‑cutting security and common utilities (mall‑security, mall‑common).

- Below that, display the API gateway/reverse proxy (Nginx) receiving HTTP requests.
- To the side or bottom, include the “Data & Infrastructure” layer showing MySQL, Redis, RabbitMQ, Elasticsearch, and logging (ELK).
- Optionally, include an outer layer or overlay that indicates deployment via Docker and orchestration via Docker Compose (referencing the docker files in document/docker).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    A1["mall-admin-web (Client)"]:::client
    A2["mall-app-web (Client)"]:::client

    %% API Gateway / Reverse Proxy
    NG["Nginx (Reverse Proxy)"]:::infra

    %% Backend Services
    subgraph "Backend Services"
        MA["mall-admin (SpringBoot Application)"]:::backend
        MP["mall-portal (SpringBoot Application)"]:::backend
        MS["mall-search (SpringBoot Application)"]:::backend
        MBG["mall-mbg (Database Code Generation)"]:::backend
        MC["mall-common (Utility Module)"]:::backend
        MSec["mall-security (SpringBoot Application)"]:::backend
    end

    %% Data & Infrastructure
    subgraph "Data & Infrastructure"
        DB["MySQL (Primary Datastore)"]:::infra
        RD["Redis (Caching Service)"]:::infra
        ES["Elasticsearch (Search Engine)"]:::infra
        MQ["RabbitMQ (Messaging)"]:::infra
        MDB["MongoDB (NoSQL)"]:::infra
        ELK["ELK (Log Aggregation)"]:::infra
        FS["OSS/MinIO (File Storage)"]:::infra
    end

    %% Docker Deployment
    DD["Docker Deployment (Docker Compose)"]:::container

    %% Flow from Clients to API Gateway
    A1 -->|"HTTP"| NG
    A2 -->|"HTTP"| NG

    %% API Gateway routes to Backend Services
    NG -->|"Routes"| MA
    NG -->|"Routes"| MP
    NG -->|"Routes"| MS

    %% Backend internal dependencies
    MA -->|"uses"| MC
    MP -->|"uses"| MC
    MA -->|"auth"| MSec
    MP -->|"auth"| MSec

    %% Messaging interactions
    MA -->|"msg"| MQ
    MP -->|"msg"| MQ

    %% Database and caching interactions
    MA -->|"DB_Access"| DB
    MP -->|"DB_Access"| DB
    MBG -->|"Generates"| DB
    MA -->|"cache"| RD
    MP -->|"cache"| RD

    %% Search integration
    MS -->|"search"| ES

    %% Containerization (dashed connections)
    MA ---|"containerized"| DD
    MP ---|"containerized"| DD
    MS ---|"containerized"| DD
    MBG ---|"containerized"| DD
    MC ---|"containerized"| DD
    MSec ---|"containerized"| DD
    NG ---|"containerized"| DD
    DB ---|"containerized"| DD
    RD ---|"containerized"| DD
    ES ---|"containerized"| DD
    MQ ---|"containerized"| DD
    MDB ---|"containerized"| DD
    ELK ---|"containerized"| DD
    FS ---|"containerized"| DD

    %% Click Events
    click MA "https://github.com/dohongkien/mall/tree/master/mall-admin"
    click MP "https://github.com/dohongkien/mall/tree/master/mall-portal"
    click MS "https://github.com/dohongkien/mall/tree/master/mall-search"
    click MBG "https://github.com/dohongkien/mall/tree/master/mall-mbg"
    click MC "https://github.com/dohongkien/mall/tree/master/mall-common"
    click MSec "https://github.com/dohongkien/mall/tree/master/mall-security"
    click DD "https://github.com/dohongkien/mall/tree/master/document/docker"

    %% Class Definitions
    classDef client fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef backend fill:#8be9fd,stroke:#333,stroke-width:2px;
    classDef infra fill:#bd93f9,stroke:#333,stroke-width:2px;
    classDef container fill:#ff79c6,stroke:#333,stroke-width:2px;
```
