# baka-world/chengdafourmbackend architecture

> Architecture diagram of the GitHub repository baka-world/chengdafourmbackend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/baka-world/chengdafourmbackend
- Repository: https://github.com/baka-world/chengdafourmbackend

## Overview

##### Project type and purpose
- This is a monolithic backend application written in Java with Spring Boot 3.4.6.
- It implements a forum system: user management, article publishing, comments, topics, and an admin dashboard.

##### File structure
- src/main/java/org/dacheng/forum – root package
- config/ – application-wide configuration (CORS, JSON, OpenAPI, security)
- controller/ – REST controllers for public API and admin endpoints
- entity/ – JPA entities and VO (view objects) under vo/
- exception/ – custom exceptions and global handler
- repository/ – Spring Data JPA repositories
- service/ + impl/ – service interfaces and implementations
- utils/ – misc. helper classes (encryption, avatar, data fix)
- resources/ – application.yml, SQL scripts
- test/ – unit & integration tests for controllers, services, utils

##### README for architecture insights
- Layered architecture following MVC + service + repository pattern
- Uses MySQL 8.0 (+ JPA), Redis (cache), Sa-Token (auth), FastJSON2, SpringDoc (Swagger)
- Dockerfile + optional docker-compose for containerized deployment

##### Main components & their relationships
a. Public API Layer
- Controllers (ArticleController, CommentController, UserController, TopicController, CommunityController)
- Admin Controllers (AdminArticleController, AdminCommentController, AdminDashboardController, AdminTopicController, AdminUserController)
b. Business Logic Layer
- Services (ArticleService, CommentService, UserService, TopicService, CommunityService) and their Impl classes
c. Data Access Layer
- Repositories (ArticleRepository, CommentRepository, UserRepository, TopicRepository, LikeRecordRepository, ViewRecordRepository)
- JPA Entities (Article, Comment, User, Topic, LikeRecord, ViewRecord)
d. Cross‐cutting Modules
- Configurations (CorsFilter, WebConfig, JacksonConfig, OpenApiConfig, StpInterfaceImpl for Sa-Token, GlobalExceptionHandler)
- Utils (Encrypt, GravatarUtil, DataHandle, DatabaseFixUtil, MessageHandle)
e. Persistence & Cache
- MySQL database for core data
- Redis for caching (optional/per configuration)
f. External Interfaces
- Swagger UI / OpenAPI docs
- Local file storage for avatars + Gravatar integration
- Docker (container deployment)

##### Architectural patterns & principles
- Layered architecture (Controller → Service → Repository)
- RESTful API design
- Exception handling via GlobalExceptionHandler
- Dependency injection for config, services, repos
- Use of DTO/VO for request/response separation from entities

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client & External Layer
    subgraph "Client & External"
        direction TB
        WebMobileClients["Web/Mobile Clients"]:::external
        SwaggerUI["Swagger UI / OpenAPI"]:::external
        DockerHost["Docker Host"]:::external
    end

    %% API / Web Layer
    subgraph "API Layer"
        direction TB
        PublicControllers["Public REST Controllers\n(ArticleController, CommentController, UserController, TopicController, CommunityController)\nSpring Boot, FastJSON2, Sa-Token"]:::api
        AdminControllers["Admin REST Controllers\n(AdminArticleController, AdminCommentController, AdminDashboardController, AdminTopicController, AdminUserController)\nSpring Boot, FastJSON2, Sa-Token"]:::api
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        ServiceInterfaces["Service Interfaces\n(ArticleService, CommentService, UserService, TopicService, CommunityService)"]:::business
        ServiceImpl["Service Implementations\n(impl classes)"]:::business
    end

    %% Data & Infrastructure Layer
    subgraph "Data & Infrastructure Layer"
        direction TB
        Repositories["JPA Repositories\n(ArticleRepository, CommentRepository, UserRepository, TopicRepository, LikeRecordRepository, ViewRecordRepository)"]:::data
        Entities["JPA Entities\n(Article, Comment, User, Topic, LikeRecord, ViewRecord)"]:::data
        VO_DTO["View Objects & DTOs\n(vo, restBean)"]:::data
        MySQL[(MySQL Database)]:::database
        RedisCache[(Redis Cache)]:::cache
        Resources["Resources\n(application.yml, SQL scripts)"]:::infra
        BackendApp["Application Entry Point\nBackendApp.java\nSpring Boot Application"]:::infra
        Docker["Dockerfile & Compose"]:::infra
    end

    %% Cross-cutting Modules
    GlobalConfig["Global Configurations\n(CORS, JSON, OpenAPI, Security, Exception)"]:::config
    HibernateMixin["Hibernate JSON Mixin"]:::config
    Utilities["Utility Classes\n(encryption, avatar, data fix, messaging)"]:::config

    %% Connections
    WebMobileClients -->|calls REST API| PublicControllers
    WebMobileClients -->|calls Admin API| AdminControllers
    SwaggerUI -->|docs endpoint| PublicControllers
    DockerHost -->|runs container| BackendApp

    PublicControllers -->|uses| ServiceInterfaces
    AdminControllers -->|uses| ServiceInterfaces
    ServiceInterfaces -->|implemented by| ServiceImpl
    ServiceImpl -->|calls| Repositories
    ServiceImpl -->|optional cache ops| RedisCache
    Repositories -->|reads/writes| MySQL
    Resources -->|initialization scripts| MySQL

    PublicControllers -->|global exception handling| GlobalConfig
    AdminControllers -->|global exception handling| GlobalConfig
    PublicControllers -->|cross-cutting config| GlobalConfig
    AdminControllers -->|cross-cutting config| GlobalConfig

    ServiceImpl -->|utility methods| Utilities

    GlobalConfig -->|includes mixin| HibernateMixin

    %% Click Events
    click PublicControllers "https://github.com/baka-world/chengdafourmbackend/tree/main/src/main/java/org/dacheng/forum/controller"
    click AdminControllers "https://github.com/baka-world/chengdafourmbackend/tree/main/src/main/java/org/dacheng/forum/controller/admin"
    click ServiceInterfaces "https://github.com/baka-world/chengdafourmbackend/tree/main/src/main/java/org/dacheng/forum/service"
    click ServiceImpl "https://github.com/baka-world/chengdafourmbackend/tree/main/src/main/java/org/dacheng/forum/service/impl"
    click Repositories "https://github.com/baka-world/chengdafourmbackend/tree/main/src/main/java/org/dacheng/forum/repository"
    click Entities "https://github.com/baka-world/chengdafourmbackend/tree/main/src/main/java/org/dacheng/forum/entity"
    click VO_DTO "https://github.com/baka-world/chengdafourmbackend/tree/main/src/main/java/org/dacheng/forum/entity/vo"
    click GlobalConfig "https://github.com/baka-world/chengdafourmbackend/tree/main/src/main/java/org/dacheng/forum/config"
    click HibernateMixin "https://github.com/baka-world/chengdafourmbackend/blob/main/src/main/java/org/dacheng/forum/config/jackson/HibernateProxyMixin.java"
    click Utilities "https://github.com/baka-world/chengdafourmbackend/tree/main/src/main/java/org/dacheng/forum/utils"
    click BackendApp "https://github.com/baka-world/chengdafourmbackend/blob/main/src/main/java/org/dacheng/forum/BackendApp.java"
    click Resources "https://github.com/baka-world/chengdafourmbackend/tree/main/src/main/resources"
    click Docker "https://github.com/baka-world/chengdafourmbackend/tree/main/Dockerfile"

    %% Styles
    classDef external fill:#EFEFEF,stroke:#999,stroke-width:1px
    classDef api fill:#D6EAF8,stroke:#3498DB,stroke-width:2px
    classDef business fill:#D5F5E3,stroke:#27AE60,stroke-width:2px
    classDef data fill:#FCF3CF,stroke:#D68910,stroke-width:2px
    classDef database fill:#F9E79F,stroke:#B9770E,stroke-width:2px,shape:cylinder
    classDef cache fill:#FADBD8,stroke:#C0392B,stroke-width:2px,shape:cylinder
    classDef infra fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px
    classDef config fill:#F2F3F4,stroke:#BDC3C7,stroke-width:2px
```
