# dlutfangping/mall-tiny architecture

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

- Interactive diagram: https://gitdiagram.com/dlutfangping/mall-tiny
- Repository: https://github.com/dlutfangping/mall-tiny

## Overview

##### Project Type & Purpose
- This is a backend scaffold application using SpringBoot, MyBatis-Plus, and SpringSecurity. Its purpose is to offer a ready-to-use backend with robust permission management that integrates with a Vue-based front-end.
- It also includes a code generator, exception handling, caching with Redis, and is designed for deployment via Docker.

##### Analyzing the File Structure
- Top-level files such as pom.xml, Dockerfile, docker-compose.yml, and the sql script indicate that the project is Maven-based, container-ready, and deployable using Docker.
- The "src/main/java/com/macro/mall/tiny" package contains distinct subpackages:
- common: Holds shared API result classes, configurations (e.g., Swagger, Redis), common domain objects, exception handling, and shared service implementations.
- config: Contains Spring Boot Java configurations.
- modules: Breaks out business logic into modules (for example, “ums” for permission management and “fms” for other modules), where each module has separate controllers, dtos, mappers, models, and services.
- security: Encapsulates Spring Security related code, including custom annotations, aspects, components (e.g., dynamic security, JWT utilities), and configurations.
- generator: Contains a MyBatis-Plus code generator that automates the creation of boilerplate code.
- The "resources" directory provides environment-specific application configuration files alongside SQL mapper XML files for MyBatis, ensuring a complete picture of the persistence and operational configuration.

##### Core Components to Capture
a. Frontend Integration:
- Although mall-tiny is backend focused, it is built to integrate with the mall-admin-web front-end. Mark an external “Frontend UI” component that communicates over RESTful API.
b. Backend Application:
- Front Controller (via SpringBoot’s dispatcher servlet) intercepts all HTTP requests.
- API Controllers located in modules (both “ums” and “fms”) which handle incoming request routing.
- Business Logic / Service Layer: Managed within services that implement business rules. Notice the use of MyBatis-Plus ServiceImpl base that handles CRUD operations.
- Persistence Layer: Comprising mappers (and their corresponding mapper.xml files under resources/mapper). This layer communicates with a MySQL database. Also, the SQL directory holds a database initialization script.
c. Shared and Infrastructure Components:
- Common package: Handles global exception handling, configuration for Swagger (API documentation), Redis configuration for caching, and additional utility classes.
- Security Layer: SpringSecurity is set up with multiple components: custom annotations, aspects, JWT authentication filters, dynamic security management, and configuration classes. These components govern authentication, authorization, and security logging.
- Code Generator: A self-contained component that generates code for MyBatis-Plus integration. This is useful for automatic creation of entities, DAOs, etc.
d. External Services & Deployment:
- Database: MySQL – as indicated by SQL scripts and configuration
- Cache: Redis – as configured both in code (e.g., RedisService, RedisConfig) and described in the technical stack.
- Docker & Docker-Compose: Containerization is supported via Dockerfile and docker-compose.yml for production deployment.

##### Key Architectural Patterns & Design Principles
- Layered Architecture: The application uses a typical multi-layer structure (controller, service, mapper/persistence) and common/infrastructure packages.
- Modular Design: Separation of business functions into distinct modules (ums and fms) allows for clarity and scalability.
- Separation of Concerns: Security, API handling, exception management, configuration, and utility functions are decoupled into their dedicated packages.
- Use of Code Generation: Encourages DRY practices and minimizes boilerplate code.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Systems
    subgraph "External Systems"
        FE("Frontend UI (mall-admin-web)"):::frontend
        DB("MySQL Database"):::database
        RC("Redis Cache"):::cache
        DOCK("Docker Deployment"):::docker
        INIT("DB Initialization Script"):::external
    end

    %% Backend Application
    subgraph "Mall-Tiny (SpringBoot Application)"
        BA("Backend Application"):::backend
        %% Presentation Layer
        subgraph "Presentation Layer"
            UMC("Ums Controllers"):::controller
            FMC("Fms Controllers"):::controller
        end
        %% Service Layer
        subgraph "Service Layer"
            US("Ums Services"):::service
            FS("Fms Services"):::service
        end
        %% Persistence Layer
        subgraph "Persistence Layer"
            UMP("Ums Mappers"):::persistence
            FMP("Fms Mappers"):::persistence
        end
        %% Common & Helper Components
        subgraph "Common & Helper Components"
            CH("Shared API & Exception Handling"):::common
            SRC("Swagger & Redis Config"):::common
            RS("Redis Service"):::cachecomp
            RCfg("Redis Configuration"):::cachecomp
        end
        %% Security & Authorization Layer
        subgraph "Security & Authorization"
            SC("Security Core Code"):::security
            SCfg("Security Configurations"):::security
        end
        %% Code Generator Module
        CG("MyBatis-Plus Code Generator"):::generator
    end

    %% Relationships between external systems and backend layers
    FE -->|"API_call"| UMC
    FE -->|"API_call"| FMC
    DOCK --> BA
    INIT --- DB

    %% Internal Backend Flow
    BA --> UMC
    BA --> FMC
    UMC -->|"calls"| US
    FMC -->|"calls"| FS
    US -->|"invokes"| UMP
    FS -->|"invokes"| FMP
    UMP -->|"queries"| DB
    FMP -->|"queries"| DB
    US -->|"cache"| RS
    FS -->|"cache"| RS
    RS -->|"configured_by"| RCfg

    %% Common & Security Integration
    CH --- BA
    SRC --- BA
    SC --- BA
    SCfg --- SC
    SC ---|"protects"| UMC
    SC ---|"protects"| FMC

    %% Code Generation feeding into the application
    CG -->|"generates"| BA

    %% Class Styles
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:1px;
    classDef database fill:#ffcccc,stroke:#333,stroke-width:1px;
    classDef cache fill:#ffebcd,stroke:#333,stroke-width:1px;
    classDef docker fill:#d3d3d3,stroke:#333,stroke-width:1px;
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px;
    classDef backend fill:#C2F8C2,stroke:#333,stroke-width:1px;
    classDef controller fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef service fill:#FFFFC2,stroke:#333,stroke-width:1px;
    classDef persistence fill:#F9D6D5,stroke:#333,stroke-width:1px;
    classDef common fill:#F0E68C,stroke:#333,stroke-width:1px;
    classDef security fill:#FFC0CB,stroke:#333,stroke-width:1px;
    classDef generator fill:#D8BFD8,stroke:#333,stroke-width:1px;
    classDef cachecomp fill:#E6E6FA,stroke:#333,stroke-width:1px;

    %% Click Events for Component Mapping
    click BA "https://github.com/dlutfangping/mall-tiny/blob/master/src/main/java/com/macro/mall/tiny/MallTinyApplication.java"
    click UMC "https://github.com/dlutfangping/mall-tiny/tree/master/src/main/java/com/macro/mall/tiny/modules/ums/controller"
    click FMC "https://github.com/dlutfangping/mall-tiny/tree/master/src/main/java/com/macro/mall/tiny/modules/fms/controller"
    click US "https://github.com/dlutfangping/mall-tiny/tree/master/src/main/java/com/macro/mall/tiny/modules/ums/service"
    click FS "https://github.com/dlutfangping/mall-tiny/tree/master/src/main/java/com/macro/mall/tiny/modules/fms/service"
    click UMP "https://github.com/dlutfangping/mall-tiny/tree/master/src/main/java/com/macro/mall/tiny/modules/ums/mapper"
    click FMP "https://github.com/dlutfangping/mall-tiny/tree/master/src/main/java/com/macro/mall/tiny/modules/fms/mapper"
    click CH "https://github.com/dlutfangping/mall-tiny/tree/master/src/main/java/com/macro/mall/tiny/common"
    click SRC "https://github.com/dlutfangping/mall-tiny/tree/master/src/main/java/com/macro/mall/tiny/common/config"
    click SC "https://github.com/dlutfangping/mall-tiny/tree/master/src/main/java/com/macro/mall/tiny/security"
    click SCfg "https://github.com/dlutfangping/mall-tiny/tree/master/src/main/java/com/macro/mall/tiny/security/config"
    click CG "https://github.com/dlutfangping/mall-tiny/blob/master/src/main/java/com/macro/mall/tiny/generator/MyBatisPlusGenerator.java"
    click RS "https://github.com/dlutfangping/mall-tiny/blob/master/src/main/java/com/macro/mall/tiny/common/service/RedisService.java"
    click RCfg "https://github.com/dlutfangping/mall-tiny/blob/master/src/main/java/com/macro/mall/tiny/config/RedisConfig.java"
```
