# shadow000902/newbee-mall-api architecture

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

- Interactive diagram: https://gitdiagram.com/shadow000902/newbee-mall-api
- Repository: https://github.com/shadow000902/newbee-mall-api

## Overview

##### Main Components
- Data Access Layer: A set of components representing the DAO (mapper interfaces in src/main/java/ltd/newbee/mall/dao and XML mapper files in resources/mapper) that interact with the database.
- Configuration & Cross-Cutting Concerns: Represent key configuration modules (under config and config/handler) such as Web MVC configurations, exception handling, Swagger configuration, and token resolvers for admin and mall users.

##### Relationships and Data Flows
- Service layer to the DAO layer to exhibit data persistence or retrieval operations. Make sure to include a link from DAO to the Database.
- Error handling or cross-cutting concerns (the exception handler) as a peripheral component that intercepts responses from various layers.

##### Architectural Patterns & Design Principles
- Layered Architecture: Clearly differentiate between the controller/API layer, business/service layer, DAO/data access layer, and the domain/entities.
- Separation of Concerns: Illustrate how administrative functions are separated from user-facing operations by their individual API packages.
- Integration Patterns: Indicate how MyBatis is used to map SQL queries (XML files in resources/mapper) to Java objects at the DAO layer.
- Security and Session Management: Include components such as token resolution (TokenToAdminUser, TokenToMallUser annotations and their respective resolvers) which support authentication/authorization.

##### Technologies & Frameworks
- Spring Boot (the backbone of the application)
- MyBatis for data persistence
- Swagger for API documentation
- Lombok (for reducing boilerplate code in entity, service, etc.)
- MySQL as the relational database (inferred from the SQL file)
- Mention any additional utility classes that facilitate common tasks (like MD5Util, PageQueryUtil, etc.)

- Clear labels for each component (for example, “Admin API Controller – NewBeeAdminCarouselAPI”, “Mall API Controller – NewBeeMallGoodsAPI”, etc.)
- Client (browser or front-end app) → API Controllers → Business Services → DAOs → Database
- Service layer → Exception Handler (global error handling)
- API layer → Swagger (for API documentation) and token resolution handlers (for authentication)
- Annotations (notes) for special components such as token resolvers and configuration components that handle cross-cutting concerns (e.g., NeeBeeMallWebMvcConfigurer, Swagger3Config).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    FE["Front-end Client (Vue Apps)"]:::client

    %% API Layer
    subgraph "API Layer"
        AdminAPI["Admin API Controller"]:::api
        MallAPI["Mall API Controller"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        ServiceInterface["Service Interface"]:::service
        ServiceImpl["Service Implementation"]:::service
        ServiceInterface --> ServiceImpl
    end

    %% DAO Layer
    subgraph "DAO Layer"
        MapperInterfaces["Mapper Interfaces"]:::dao
        XMLMappers["XML Mappers"]:::dao
        MapperInterfaces --> XMLMappers
    end

    %% Domain/Entity Layer
    EntityModel["Entity Model"]:::entity

    %% External Database
    Database["MySQL Database"]:::external

    %% Configuration & Cross-Cutting Components
    subgraph "Configuration & Cross-Cutting"
        GeneralConfig["General Configuration"]:::config
        TokenResolver["Token Resolution"]:::config
        Annotations["Token Handling Annotations"]:::config
        ExceptionHandler["Global Exception Handler"]:::config
        Swagger["Swagger API Documentation"]:::config
        WebMvc["Web MVC Configuration"]:::config
    end

    %% Utility Components
    Utility["Utility Components"]:::utility

    %% Connections
    FE -->|"HTTP Calls"| AdminAPI
    FE -->|"HTTP Calls"| MallAPI

    AdminAPI -->|"calls"| ServiceInterface
    MallAPI -->|"calls"| ServiceInterface

    ServiceImpl -->|"invokes"| MapperInterfaces
    ServiceImpl -->|"invokes"| XMLMappers

    MapperInterfaces -->|"maps to"| EntityModel
    XMLMappers -->|"maps to"| EntityModel

    MapperInterfaces ---|"queries"| Database
    XMLMappers ---|"queries"| Database

    %% Cross Cutting: Exception Handling & Token Resolution, API Documentation
    AdminAPI ---|"auth via"| TokenResolver
    MallAPI ---|"auth via"| TokenResolver

    AdminAPI ---|"docs"| Swagger
    MallAPI ---|"docs"| Swagger

    ServiceImpl ---|"error handled by"| ExceptionHandler

    %% Utility integration (used by multiple layers)
    ServiceImpl --- Utility
    MapperInterfaces --- Utility

    %% Click Events
    click AdminAPI "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/java/ltd/newbee/mall/api/admin"
    click MallAPI "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/java/ltd/newbee/mall/api/mall"
    click ServiceInterface "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/java/ltd/newbee/mall/service"
    click ServiceImpl "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/java/ltd/newbee/mall/service/impl"
    click MapperInterfaces "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/java/ltd/newbee/mall/dao"
    click XMLMappers "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/resources/mapper"
    click EntityModel "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/java/ltd/newbee/mall/entity"
    click GeneralConfig "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/java/ltd/newbee/mall/config"
    click TokenResolver "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/java/ltd/newbee/mall/config/handler"
    click Annotations "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/java/ltd/newbee/mall/config/annotation"
    click ExceptionHandler "https://github.com/shadow000902/newbee-mall-api/blob/master/src/main/java/ltd/newbee/mall/config/NewBeeMallExceptionHandler.java"
    click Swagger "https://github.com/shadow000902/newbee-mall-api/blob/master/src/main/java/ltd/newbee/mall/config/Swagger3Config.java"
    click WebMvc "https://github.com/shadow000902/newbee-mall-api/blob/master/src/main/java/ltd/newbee/mall/config/NeeBeeMallWebMvcConfigurer.java"
    click Utility "https://github.com/shadow000902/newbee-mall-api/tree/master/src/main/java/ltd/newbee/mall/util"
    click Database "https://github.com/shadow000902/newbee-mall-api/blob/master/src/main/resources/newbee_mall_db_v2_schema.sql"

    %% Styles
    classDef client fill:#ffe0b2,stroke:#d2691e,stroke-width:2px;
    classDef api fill:#fefbd8,stroke:#ff8c00,stroke-width:2px;
    classDef service fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef dao fill:#ffcdd2,stroke:#c62828,stroke-width:2px;
    classDef entity fill:#bbdefb,stroke:#1e88e5,stroke-width:2px;
    classDef config fill:#d1c4e9,stroke:#6a1b9a,stroke-width:2px;
    classDef external fill:#e1bee7,stroke:#ad1457,stroke-width:2px;
    classDef utility fill:#cfd8dc,stroke:#37474f,stroke-width:2px;
```
