# phunguyen-byte/mall architecture

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

- Interactive diagram: https://gitdiagram.com/phunguyen-byte/mall
- Repository: https://github.com/phunguyen-byte/mall

## Overview

##### Project type and purpose
- This is a comprehensive e-commerce platform that includes both backend administration (mall-admin) and front-end consumer (mall-portal) systems. There is also a dedicated search service (mall-search) built using Elasticsearch, a security module (mall-security) for authentication/authorization, common utilities (mall-common), as well as MyBatisGenerator (mall-mbg) for data access code generation.
- The project is designed as a modular/multi-module backend based on Spring Boot (with modules separated by concerns), with each module addressing a specific responsibility (administration, portal/frontend, search, security, etc.). The README also distinguishes the mobile and web frontend implementations, and the project supports Docker containerization and deployment automation.

##### Analyzing the file structure
- At the top level you have sub-directories like mall-admin, mall-portal, mall-search, mall-security, mall-common, mall-mbg, and mall-demo. This indicates that the backend is split into logical modules with clearly defined responsibilities.
- Each module follows standard Spring Boot structure with src/main/java (for controllers, services, DAO, configuration, etc.), src/main/resources (for configuration) and src/test for testing. The existence of dedicated Docker, document, and configuration directories further suggests that deployment and environmental configurations (e.g., Docker Compose files, nginx.conf for proxying, and logstash/Kibana configurations) are integral parts of the project.
- The separated modules also hint at a microservices or modular monolith style architecture where distinct functionalities (admin functions, user-facing API, etc.) are encapsulated in different components.

##### Review of the README for additional insights
- The README explains that the platform covers an entire e-commerce workflow including product management, order process, user management, promotions/marketing, and search.
- The technology stack is clearly listed: Spring Boot, Spring Security, MyBatis, Elasticsearch, RabbitMQ, Redis etc., along with containerization via Docker and deployment tools such as Jenkins. This informs the external dependencies and supporting infrastructure.

a. Main Components:
- Backend Modules:
- mall-admin: Admin REST APIs for product management, order management, member management, etc.
- mall-portal: Frontend consumer APIs for browsing products, managing user sessions, checkout, etc.
- mall-search: Dedicated search service using Elasticsearch for product search functionality.
- mall-security: Security and authentication module (JWT, Spring Security) that other modules depend on.
- mall-common: Common utilities, global configurations, logging, exception handling, etc.
- mall-mbg: Auto-generated MyBatis data access layer interacting with the database.
- Frontend Systems:
- mall-admin-web and mall-app-web (referenced by README links) for backend management UI and consumer app, respectively.
- Supporting Infrastructure:
- Database(s): MySQL for transactional data
- Redis: Caching layer and session management
- Elasticsearch: Handling search queries from mall-search
- RabbitMQ: Asynchronous message queues for order processing, notifications, etc.
- Object Storage Services: OSS/MinIO for file storage (images, static resources)
- Other external tools: Nginx (as a reverse proxy or static server), Jenkins (for CI/CD), Docker (container orchestration)

b. Relationships and interactions:
- How the web UIs (admin-web and app-web) interface with their corresponding backend APIs (mall-admin and mall-portal).
- Link the mall-portal and mall-admin modules to the MySQL database via the MyBatis/MBG layer.
- Integration between mall-search and the Elasticsearch cluster.
- That mall-security provides JWT token verification and permission management that interconnects with all other modules.
- Lines from the Docker deployment configuration components, Nginx, and Jenkins to the microservices to illustrate deployment and external access.

c. Architectural patterns and design principles:
- The use of Spring Boot and a modular structure points to a layered (or MVC) architecture: controllers → services → DAOs.
- The separation of modules (admin vs. portal vs. search) clearly delineates responsibilities.
- Asynchronous communication via RabbitMQ is a key design element.
- Security concerns are distinctly handled in the mall-security module, facilitating token-based auth (JWT) and centralized access management.
- Containerization and infrastructure-as-code principles with Docker and related deployment scripts.

d. Relevant technologies and frameworks:
- Java/Spring Boot, Spring Security, MyBatis/MyBatisGenerator, Elasticsearch, Redis, RabbitMQ, Docker, Jenkins, and third-party integrations (OSS, MinIO).

##### Specific elements
– HTTP/API requests from frontend UIs to the backend services.
– Database connections from the modules (via mall-mbg/MyBatis).
– Message flows from services to RabbitMQ and from RabbitMQ to asynchronous consumers.
– Integration with caching (Redis) and search (Elasticsearch).
– Presentation layer (web frontends)
– Business logic layer (backend services)
– Data layer (MySQL, Redis, etc.)
– Infrastructure components (Docker, Jenkins, Nginx) and external services.
- Interactions (e.g., “JWT Authentication”, “Data CRUD via MyBatis”, “Search query”, etc.) to add more context.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        AUI["Admin Web UI"]:::presentation
        CUI["Consumer App Web UI"]:::presentation
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Admin["Admin API (mall-admin)"]:::backend
        Portal["Consumer API (mall-portal)"]:::backend
        Search["Search Service (mall-search)"]:::backend
        Security["Security Module (mall-security)"]:::backend
        Common["Common Utilities (mall-common)"]:::backend
        MBG["Data Access (mall-mbg)"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        DB[(MySQL DB)]:::data
        Cache[(Redis Cache)]:::data
        ES[(Elasticsearch)]:::data
        MQ[(RabbitMQ)]:::data
        OSS[(Object Storage)]:::data
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure"
        Docker["Docker Containers"]:::infra
        Jenkins["Jenkins CI/CD"]:::infra
        Nginx["Nginx Reverse Proxy"]:::infra
    end

    %% Connections from Presentation to Business Logic
    AUI -->|"HTTP/API"| Admin
    CUI -->|"HTTP/API"| Portal

    %% Business Logic Interactions with Security and Common Utilities
    Admin -->|"JWTAuth"| Security
    Portal -->|"JWTAuth"| Security
    Search -->|"JWTAuth"| Security

    Admin -->|"Utilizes"| Common
    Portal -->|"Utilizes"| Common
    Search -->|"Utilizes"| Common
    Security -->|"Utilizes"| Common

    %% Data Access and Persistence
    Admin -->|"CRUDviaMBG"| MBG
    Portal -->|"CRUDviaMBG"| MBG
    MBG -->|"DBOps"| DB
    Search -->|"SearchQuery"| ES

    %% Asynchronous Messaging
    Admin -->|"SendsMessage"| MQ
    Portal -->|"SendsMessage"| MQ

    %% Caching Operations
    Admin -->|"CacheOps"| Cache
    Portal -->|"CacheOps"| Cache

    %% Infrastructure & Deployment Relationships
    Docker --> Admin
    Docker --> Portal
    Docker --> Search
    Docker --> Security
    Docker --> Common
    Docker --> MBG
    Nginx --> AUI
    Nginx --> CUI
    Jenkins --> Docker

    %% Click Events for Component Mapping
    click Admin "https://github.com/phunguyen-byte/mall/tree/master/mall-admin/"
    click Portal "https://github.com/phunguyen-byte/mall/tree/master/mall-portal/"
    click Search "https://github.com/phunguyen-byte/mall/tree/master/mall-search/"
    click Security "https://github.com/phunguyen-byte/mall/tree/master/mall-security/"
    click Common "https://github.com/phunguyen-byte/mall/tree/master/mall-common/"
    click MBG "https://github.com/phunguyen-byte/mall/tree/master/mall-mbg/"

    %% Styles
    classDef presentation fill:#DDEBF7,stroke:#6C8EBF,stroke-width:2px;
    classDef backend fill:#FFF2CC,stroke:#D6B656,stroke-width:2px;
    classDef data fill:#FCE4D6,stroke:#F1A340,stroke-width:2px;
    classDef infra fill:#E2EFDA,stroke:#78A865,stroke-width:2px;
```
