# softghostgu/secondhandhub architecture

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

## Overview

##### Main Components
- Frontend: This is located under the "fronted" directory and built using Vue 3 with Vite, Pinia for state management, and various Vue components and views (e.g. Login.vue, Layout.vue, Goods-related views). It communicates with the back end via HTTP APIs.
- Backend: Found in "backend/second_hand", this Java Spring Boot application follows common layered architecture with packages for configuration, controllers, services, mappers (data access), and utilities. The backend handles business logic such as user authentication (JWT, MD5 encryption), goods management, mail services for chat/communication, and error handling (GlobalExceptionHandler).
- Database & Cache: There’s an SQL script file (SecondHand.sql) for initializing the application’s relational database and a Redis server executable (redis-server.exe plus dump.rdb) to support caching or session management.
- External Services: In addition to the main application logic, there are elements for file upload and emailing (as seen by MailController and MailService) that likely interact with external email systems.

##### And Represent Architectural Layers & Interactions
- For the Backend, show multiple layers:
– Controllers (REST endpoints): Represented by various controllers (CategoryController, GoodsController, UserController, FileUploadController, MailController) that receive HTTP requests.
– Services: Business logic is encapsulated here (CategoryService, GoodsService, UserService, MailService) which call the data layer.
– Data Layer/Mappers: Mappers (e.g., CategoryMapper, GoodsMapper, UserMapper with associated XML files) that interface with the database.
– Utility/Support Components: Utilities such as JwtUtil, MD5Utils, and custom validations in the validation package.
– Component and View structure: How Vue components and pages (views) are interconnected; API modules (under fronted/src/api) dedicated to goods, mail, and user operations.
– Client-side Routing: Show that the router module manages navigations.
– Global State Management: Illustrate the use of stores (e.g., token and userInfo) for managing session data.

##### Architectural Patterns & Design Principles
- The separation of concerns is evident: the frontend is strictly responsible for rendering and capturing user input, while the backend handles business logic and data persistence.
- Mention authentication and security measures, like JWT for user sessions and MD5-based password handling.
- Deployment and configuration management: include representations of configuration files (YML files) that customize application behavior for different environments (dev, test, production).

##### Relevant Technologies & Frameworks
- Frontend: Vue 3, Vite, Pinia.
- Backend: Java with Spring Boot; Maven for build management (pom.xml); integration with external services such as Redis and SMTP/email systems.
- Database: A relational database represented by the SQL script, plus the usage of XML-based MyBatis mappers.
- Utility Tools: Redis for caching, and JWT for secure authentication.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side (Frontend)
    subgraph "Client Side (Frontend)"
        FE["Frontend (Vue 3)"]:::frontend
        API_GOODS["API: Goods"]:::api
        API_MAIL["API: Mail"]:::api
        API_USER["API: User"]:::api
    end

    %% Server Side (Backend Layers)
    subgraph "Server Side (Backend Layers)"
        BkendApp["Backend (Spring Boot Application)"]:::external
        %% Controller Layer
        subgraph "Controller Layer"
            CTRL_CAT["CategoryController"]:::controller
            CTRL_FILE["FileUploadController"]:::controller
            CTRL_GOODS["GoodsController"]:::controller
            CTRL_MAIL["MailController"]:::controller
            CTRL_USER["UserController"]:::controller
        end
        EXC["GlobalExceptionHandler"]:::controller
        INTER["LoginInterceptor"]:::controller

        %% Service Layer
        subgraph "Service Layer"
            SVC_CAT["CategoryService"]:::service
            SVC_GOODS["GoodsService"]:::service
            SVC_USER["UserService"]:::service
            SVC_MAIL["MailService"]:::service
        end

        %% Data Mapper Layer
        subgraph "Data Mapper Layer"
            MAPPER_CAT["CategoryMapper"]:::mapper
            MAPPER_GOODS["GoodsMapper"]:::mapper
            MAPPER_USER["UserMapper"]:::mapper
            MAPPER_XML["GoodsMapper.xml"]:::mapper
        end

        %% Utilities & Validations
        subgraph "Utilities & Validations"
            JWT["JwtUtil"]:::utils
            MD5["MD5Utils"]:::utils
            THREAD["ThreadLocalUtil"]:::utils
            VALIDATION["StateValidation"]:::utils
        end
    end

    %% Database and External Systems
    DB["Relational Database"]:::db
    REDIS["Redis Cache"]:::db
    EMAIL["External Email/File Service"]:::external

    %% Data Flow Connections
    %% Frontend to Backend Controllers (HTTP Requests)
    FE -->|"HTTP_Request"| CTRL_CAT
    FE -->|"HTTP_Request"| CTRL_FILE
    FE -->|"HTTP_Request"| CTRL_GOODS
    FE -->|"HTTP_Request"| CTRL_MAIL
    FE -->|"HTTP_Request"| CTRL_USER

    %% Backend Internal Flow: Controllers to Services
    CTRL_CAT --> SVC_CAT
    CTRL_FILE --> SVC_CAT
    CTRL_GOODS --> SVC_GOODS
    CTRL_MAIL --> SVC_MAIL
    CTRL_USER --> SVC_USER

    %% Services to Data Mappers
    SVC_CAT --> MAPPER_CAT
    SVC_GOODS --> MAPPER_GOODS
    SVC_USER --> MAPPER_USER
    SVC_GOODS --> MAPPER_XML

    %% Mappers to Database
    MAPPER_CAT --> DB
    MAPPER_GOODS --> DB
    MAPPER_USER --> DB
    MAPPER_XML --> DB

    %% Service Layer also interacts with Redis for caching/session
    SVC_USER --> REDIS
    SVC_GOODS --> REDIS

    %% Controllers interact with External Email/File Service
    CTRL_MAIL --> EMAIL
    CTRL_FILE --> EMAIL

    %% Exception Handler and Interceptor attached to Controllers
    CTRL_CAT --- EXC
    CTRL_FILE --- EXC
    CTRL_GOODS --- EXC
    CTRL_MAIL --- EXC
    CTRL_USER --- EXC

    CTRL_CAT --- INTER
    CTRL_FILE --- INTER
    CTRL_GOODS --- INTER
    CTRL_MAIL --- INTER
    CTRL_USER --- INTER

    %% Backend Application Entry Point
    BkendApp --> CTRL_CAT

    %% Click Events for Frontend
    click FE "https://github.com/softghostgu/secondhandhub/tree/main/fronted"
    click API_GOODS "https://github.com/softghostgu/secondhandhub/blob/main/fronted/src/api/goods.js"
    click API_MAIL "https://github.com/softghostgu/secondhandhub/blob/main/fronted/src/api/mailSender.js"
    click API_USER "https://github.com/softghostgu/secondhandhub/blob/main/fronted/src/api/user.js"

    %% Click Event for Backend Application Root
    click BkendApp "https://github.com/softghostgu/secondhandhub/tree/main/backend/second_hand"

    %% Click Events for Backend Controllers
    click CTRL_CAT "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/controller/CategoryController.java"
    click CTRL_FILE "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/controller/FileUploadController.java"
    click CTRL_GOODS "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/controller/GoodsController.java"
    click CTRL_MAIL "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/controller/MailController.java"
    click CTRL_USER "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/controller/UserController.java"

    %% Click Events for Exception Handler and Interceptor
    click EXC "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/exception/GlobalExceptionHandler.java"
    click INTER "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/interceptors/LoginInterceptor.java"

    %% Click Events for Backend Services
    click SVC_CAT "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/service/CategoryService.java"
    click SVC_GOODS "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/service/GoodsService.java"
    click SVC_USER "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/service/UserService.java"
    click SVC_MAIL "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/service/MailService.java"

    %% Click Events for Data Mappers
    click MAPPER_CAT "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/mapper/CategoryMapper.java"
    click MAPPER_GOODS "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/mapper/GoodsMapper.java"
    click MAPPER_USER "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/mapper/UserMapper.java"
    click MAPPER_XML "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/resources/com/GHOST/mapper/GoodsMapper.xml"

    %% Click Events for Utilities & Validations
    click JWT "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/utils/JwtUtil.java"
    click MD5 "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/utils/MD5Utils.java"
    click THREAD "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/utils/ThreadLocalUtil.java"
    click VALIDATION "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/src/main/java/com/GHOST/validation/StateValidation.java"

    %% Click Events for Database and Redis
    click DB "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/database_scripts/SecondHand.sql"
    click REDIS "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/redis-server.exe"
    click EMAIL "https://github.com/softghostgu/secondhandhub/blob/main/backend/second_hand/dump.rdb"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef api fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef controller fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef service fill:#d1ecf1,stroke:#17a2b8,stroke-width:2px;
    classDef mapper fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef utils fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef db fill:#fdfd96,stroke:#ffeb3b,stroke-width:2px;
    classDef external fill:#d3d3d3,stroke:#808080,stroke-width:2px;
```
