# zerowdd/xiaomi architecture

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

## Overview

##### Main Components
- Frontend: Although not part of this repository, note that the frontend is implemented in Vue.js (using Vue-router, Vuex, Element UI, Axios). Indicate that it consumes RESTful APIs exposed by the backend.
- Backend Application (SpringBoot):
- Controllers Layer: Houses various controllers (e.g., CarouselController, CategoryController, OrderController, etc.) that handle HTTP requests.
- Services Layer: Implements business logic via service classes (e.g., ProductService, OrderService, UserService, etc.).
- Data Access Layer: Uses mappers (MyBatis Mappers) to interact with the database (files like ProductMapper.xml plus corresponding Mapper interfaces).
- Exception and Utility Handling: Contains custom exceptions (XmException, XmExceptionHandler) and various utility classes (ID generation, Ribbon/Redis key utilities, MD5 utility).
- Configuration: Has configuration classes like RabbitMQConfig and RedisConfig that set up external messaging and caching.
- Background Tasks and Messaging: Includes a “task” package with scheduled tasks (e.g., SeckillTask) and an “mq” package for integration with RabbitMQ.
- Persistence/Data Models: The POJO classes represent the domain model (e.g., Product, Order, User, etc.).

##### External Dependencies and Data Stores
- MySQL: The main relational database indicated in both the README and the xiaomi.sql file.
- Redis: Caching layer used to improve performance.
- RabbitMQ: Used to handle messaging (specifically for the "秒杀" or flash sale functionality).

- For the backend, split it into distinct layers:
- Business Logic Layer: Encompass the service classes that implement domain rules.
- Data Access Layer: Represent the mappers and the MyBatis XML files; show how they interact with the MySQL database.
- From Frontend → Controllers
- Controllers → Services (for processing business logic)
- Services → Mappers (for database access)
- Additionally, show how the Configuration components (RedisConfig and RabbitMQConfig) integrate:
- A connection between Services (or specific controllers) and Redis for caching.
- A messaging pathway from the application (for the flash sale logic) to RabbitMQ, where a “SeckillOrderQueue” is used.

##### Architectural Patterns & Design Principles to Highlight
- Layered Architecture: Emphasize clear separation between presentation (controllers), business logic (services), and data access (mappers).
- Use of Configuration Modules: Configuring external systems (Redis and RabbitMQ) centrally.
- Exception Handling: A dedicated package ensures consistent error management.
- Modular Design: Each feature (products, orders, shopping cart, user management, flash sales) has its own controllers, services, and corresponding mappers—this makes maintenance and potential scalability easier.

##### Additional Detail
- Repository’s entry point (Application.java) as the initiation point of the Spring Boot application.
- You might also include annotations that identify configuration classes and scheduled tasks to emphasize the dynamic aspects of the system (like the seckill functionality).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    FE["Frontend (Vue)"]:::frontend

    MySQL["MySQL"]:::database
    Redis["Redis"]:::database
    RabbitMQ["RabbitMQ"]:::rabbitmq

    %% Backend Application Entry Point
    AppEntry["Application Entry Point"]:::app

    subgraph "Backend Application" 
        direction TB

        %% Presentation Layer
        subgraph "Presentation Layer: Controllers"
            Controllers["Controllers"]:::controller
        end

        %% Business Logic Layer
        subgraph "Business Logic Layer: Services"
            Services["Services"]:::service
        end

        %% Data Access Layer
        subgraph "Data Access Layer"
            Mappers["Mappers"]:::mapper
            MyBatis["MyBatis XML Mappings"]:::xml
        end

        %% Additional Modules
        subgraph "Additional Modules"
            Exceptions["Exception Handling"]:::exception
            Utils["Utility Classes"]:::util
            Config["Configurations"]:::config
            Tasks["Background Tasks"]:::task
            Messaging["Messaging (MQ)"]:::mq
            Models["Data Models (POJOs)"]:::model
        end
    end

    %% Data Flow
    FE -->|"HTTP_API"| Controllers
    AppEntry -->|"initiates"| Controllers
    Controllers -->|"calls_logic"| Services
    Controllers -->|"handles_errors"| Exceptions
    Services -->|"executes"| Mappers
    Mappers -->|"uses_SQL_from"| MyBatis
    MyBatis -->|"queries"| MySQL
    Services -->|"utilizes_cache"| Redis
    Services -->|"publishes_msg"| Messaging
    Config -->|"configures"| Redis
    Config -->|"configures"| RabbitMQ
    Tasks -->|"triggers"| Messaging
    Messaging -->|"sends_to"| RabbitMQ

    %% Click Events
    click AppEntry "https://github.com/zerowdd/xiaomi/blob/master/src/main/java/com/mall/xiaomi/Application.java"
    click Controllers "https://github.com/zerowdd/xiaomi/tree/master/src/main/java/com/mall/xiaomi/controller"
    click Services "https://github.com/zerowdd/xiaomi/tree/master/src/main/java/com/mall/xiaomi/service"
    click Mappers "https://github.com/zerowdd/xiaomi/tree/master/src/main/java/com/mall/xiaomi/mapper"
    click MyBatis "https://github.com/zerowdd/xiaomi/tree/master/src/main/resources/mybatis"
    click Exceptions "https://github.com/zerowdd/xiaomi/tree/master/src/main/java/com/mall/xiaomi/exception"
    click Utils "https://github.com/zerowdd/xiaomi/tree/master/src/main/java/com/mall/xiaomi/util"
    click Config "https://github.com/zerowdd/xiaomi/tree/master/src/main/java/com/mall/xiaomi/config"
    click Tasks "https://github.com/zerowdd/xiaomi/tree/master/src/main/java/com/mall/xiaomi/task"
    click Messaging "https://github.com/zerowdd/xiaomi/tree/master/src/main/java/com/mall/xiaomi/mq"
    click Models "https://github.com/zerowdd/xiaomi/tree/master/src/main/java/com/mall/xiaomi/pojo"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef app fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef controller fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef service fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef mapper fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef xml fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef exception fill:#f5c6cb,stroke:#721c24,stroke-width:2px;
    classDef util fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef config fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef task fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
    classDef mq fill:#ffddcc,stroke:#d35400,stroke-width:2px;
    classDef model fill:#d7bde2,stroke:#8e44ad,stroke-width:2px;
    classDef database fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef rabbitmq fill:#ffe5b4,stroke:#e67e22,stroke-width:2px;
```
