# atjiu/pybbs architecture

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

- Interactive diagram: https://gitdiagram.com/atjiu/pybbs
- Repository: https://github.com/atjiu/pybbs

## Overview

##### Project type and purpose
- This is a full-stack, modular web application (“pybbs” forum) built on Spring Boot.
- It provides both a public front-end (Freemarker + static assets) and an admin back-end.
- It exposes REST APIs under `/api/*`, integrates real-time chat via WebSocket, and supports plugins (Redis caching, ElasticSearch, comment layers, file upload, themes, etc.).
- It uses MySQL (with Flyway migrations), Redis, ElasticSearch, Shiro for RBAC, SMTP/SMS/Telegram for notifications, and Docker for containerization.

##### File structure
- Top-level:
- `src/main/java` – Spring Boot application code (config, controllers, services, mappers, models, directives, hooks, interceptors, plugins).
- `src/main/resources` – YAML configurations (dev/prod/docker), Flyway migrations, Freemarker templates, static assets (JS/CSS/images).
- `plugins/` – separate Maven modules, each implements a plugin extension (e.g. `redis-cache-plugin`, `comment-layer-plugin`, `theme-simple-plugin`).
- `docs/` – Asciidoc documentation project building the user guide.
- `Dockerfile` & `docker-compose.yml` – container and deployment definitions.
- `pom.xml` – dependency management (Spring Boot, MyBatis-Plus, Shiro, Redis, ES, WebSocket, etc.).
- `fronts/` – placeholder for front-end artifacts (readme only).
- Architectural patterns:
- Layered MVC: Controllers → Services → Mappers/Repositories → Database.
- Plugin SPI: custom plugins are discovered and wired at runtime via Spring Context.
- Event/Hooks: service hooks augment core behavior.
- API layer separating web views vs REST endpoints.

##### Extract insights from the README
- Lists the technology stack: Spring-Boot, Shiro, MyBatis-Plus, Bootstrap, MySQL, Freemarker, Redis, Elasticsearch, WebSocket, I18N.
- Documents how to run (jar, Docker), where to find front-end (`/`), admin (`/adminlogin`), and API.
- Mentions plugin architecture and customization points (system settings, external login, messaging).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Docker Deployment Boundary
    subgraph "Docker Deployment" 
        direction TB
        subgraph "pybbs Container" 
            direction TB
            %% Core Spring Boot Application
            subgraph "Spring Boot Application" 
                direction TB
                App["PybbsApplication"]:::core
            end

            %% Configuration
            Config["YAML & Spring Config"]:::config
            App -->|load configs| Config
            click Config "https://github.com/atjiu/pybbs/blob/master/src/main/resources/application-dev.yml"

            %% Security
            subgraph "Security Layer"
                direction TB
                ShiroCfg["ShiroConfig"]:::security
                MyShiroFilter["MyShiroFilter"]:::security
                MyShiroRealm["MyShiroRealm"]:::security
                MyCredentialsMatcher["MyCredentialsMatcher"]:::security
            end
            App --> ShiroCfg
            ShiroCfg --> MyShiroFilter
            ShiroCfg --> MyShiroRealm
            MyShiroRealm --> MyCredentialsMatcher
            click ShiroCfg "https://github.com/atjiu/pybbs/blob/master/src/main/java/co/yiiu/pybbs/config/ShiroConfig.java"
            click MyShiroFilter "https://github.com/atjiu/pybbs/blob/master/src/main/java/co/yiiu/pybbs/config/realm/MyShiroFilter.java"
            click MyShiroRealm "https://github.com/atjiu/pybbs/blob/master/src/main/java/co/yiiu/pybbs/config/realm/MyShiroRealm.java"
            click MyCredentialsMatcher "https://github.com/atjiu/pybbs/blob/master/src/main/java/co/yiiu/pybbs/config/realm/MyCredentialsMatcher.java"

            %% Web Controllers
            subgraph "Web Layer (Freemarker + Static)" 
                direction TB
                FrontCtrl["Front Controller"]:::controller
                AdminCtrl["Admin Controller"]:::controller
                Templates["Freemarker Templates"]:::view
                StaticAssets["Static Assets"]:::view
            end
            App --> FrontCtrl
            App --> AdminCtrl
            FrontCtrl --> Templates
            FrontCtrl --> StaticAssets
            AdminCtrl --> Templates
            AdminCtrl --> StaticAssets
            click Templates "https://github.com/atjiu/pybbs/tree/master/src/main/resources/templates/"
            click StaticAssets "https://github.com/atjiu/pybbs/tree/master/src/main/resources/static/"
            click FrontCtrl "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/controller/front/"
            click AdminCtrl "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/controller/admin/"

            %% API Controllers
            API["API Controller"]:::api
            App --> API
            click API "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/controller/api/"

            %% WebSocket Endpoint
            WS["WebSocket Endpoint"]:::websocket
            App --> WS
            click WS "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/config/websocket/"

            %% Service Layer
            subgraph "Service Layer"
                direction TB
                ServiceIntf["Service Interfaces"]:::service
                ServiceImpl["Service Implementations"]:::service
            end
            App --> ServiceIntf
            ServiceIntf --> ServiceImpl
            click ServiceIntf "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/service/"
            click ServiceImpl "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/service/impl/"

            %% Hooks & Interceptors & Utils
            Hook["Hooks"]:::aux
            Interceptor["Interceptors"]:::aux
            Util["Utilities"]:::aux
            ServiceImpl --> Hook
            FrontCtrl --> Interceptor
            AdminCtrl --> Interceptor
            ServiceImpl --> Util
            click Hook "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/hook/"
            click Interceptor "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/interceptor/"
            click Util "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/util/"

            %% Data Access
            subgraph "Data Access Layer"
                direction TB
                Mappers["MyBatis Mappers"]:::db
                XMLMap["XML Mappings"]:::db
                Flyway["Flyway Migrations"]:::db
            end
            ServiceImpl --> Mappers
            Mappers --> XMLMap
            App --> Flyway
            click Mappers "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/mapper/"
            click XMLMap "https://github.com/atjiu/pybbs/blob/master/src/main/java/co/yiiu/pybbs/mapper/**/*.xml"
            click Flyway "https://github.com/atjiu/pybbs/tree/master/src/main/resources/db/migration/"

            %% Plugins SPI
            subgraph "Plugin SPI & Plugins" 
                direction TB
                CoreSPI["Core SPI"]:::plugin
                RedisPlugin["RedisCachePlugin"]:::plugin
                ESPlugin["ElasticSearchPlugin"]:::plugin
                FilePlugin["FileUploadPlugin"]:::plugin
            end
            ServiceImpl --> CoreSPI
            CoreSPI --> RedisPlugin
            CoreSPI --> ESPlugin
            CoreSPI --> FilePlugin
            click CoreSPI "https://github.com/atjiu/pybbs/tree/master/src/main/java/co/yiiu/pybbs/plugin/"
            click RedisPlugin "https://github.com/atjiu/pybbs/blob/master/src/main/java/co/yiiu/pybbs/plugin/RedisCachePlugin.java"
            click ESPlugin "https://github.com/atjiu/pybbs/blob/master/src/main/java/co/yiiu/pybbs/plugin/ElasticSearchPlugin.java"
            click FilePlugin "https://github.com/atjiu/pybbs/blob/master/src/main/java/co/yiiu/pybbs/plugin/FileUploadPlugin.java"

            %% External Plugin Modules
            subgraph "External Plugins" 
                direction TB
                RedisExt["redis-cache-plugin"]:::plugin
                CommentExt["comment-layer-plugin"]:::plugin
                ThemeExt["theme-simple-plugin"]:::plugin
            end
            CoreSPI --> RedisExt
            CoreSPI --> CommentExt
            CoreSPI --> ThemeExt
            click RedisExt "https://github.com/atjiu/pybbs/tree/master/plugins/redis-cache-plugin/"
            click CommentExt "https://github.com/atjiu/pybbs/tree/master/plugins/comment-layer-plugin/"
            click ThemeExt "https://github.com/atjiu/pybbs/tree/master/plugins/theme-simple-plugin/"

        end

        %% Supporting Services
        subgraph "External Services"
            direction TB
            MySQL[(MySQL)]:::database
            Redis[(Redis Cache)]:::database
            ES[(ElasticSearch)]:::database
            SMTP["SMTP API"]:::external
            SMS["SMS Provider"]:::external
            Telegram["Telegram Bot API"]:::external
        end

        %% Networking
        subgraph "Network"
            direction TB
            MySQL <-->|JDBC| Mappers
            Redis <--> RedisPlugin
            ES <--> ESPlugin
            ServiceImpl -->|send email| SMTP
            ServiceImpl -->|send sms| SMS
            ServiceImpl -->|send message| Telegram
        end

        %% Docker Compose Links
        MySQL ---|linked| Redis
        Redis ---|linked| ES

    end

    %% Documentation
    Docs["Asciidoc Docs"]:::docs
    click Docs "https://github.com/atjiu/pybbs/tree/master/docs/src/main/asciidoc/"

    %% Styles
    classDef core fill:#f9f,stroke:#333,stroke-width:1px
    classDef controller fill:#bbf,stroke:#333
    classDef api fill:#bbf,stroke:#333
    classDef websocket fill:#bbf,stroke:#333,stroke-dasharray: 5 5
    classDef service fill:#bfb,stroke:#333
    classDef db fill:#ffb,stroke:#333,stroke-width:2px
    classDef database fill:#ffb,stroke:#333,stroke-width:2px
    classDef plugin fill:#fbf,stroke:#933,stroke-width:2px
    classDef view fill:#cff,stroke:#333
    classDef config fill:#fcf,stroke:#333
    classDef security fill:#fbb,stroke:#333
    classDef aux fill:#ddd,stroke:#333
    classDef docs fill:#eee,stroke:#333,stroke-dasharray: 2 2
    classDef external fill:#fdf,stroke:#933,stroke-width:2px
```
