# lerry903/ruoyi architecture

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

- Interactive diagram: https://gitdiagram.com/lerry903/ruoyi
- Repository: https://github.com/lerry903/ruoyi

## Overview

##### Project Type and Purpose
- This is a full-stack, modular, monolithic web application built with Spring Boot.
- Purpose: a generic, extensible “后台管理系统” (back-office management system) supporting user/role/dept/menu management, logging, scheduled jobs, code generation, server monitoring, etc.

##### High-Level Module Analysis
- Multi-module Maven project:
- ruoyi-admin: Spring Boot web application (controllers, Thymeleaf templates, static assets)
- ruoyi-system: Domain models, MyBatis mappers, system service implementations
- ruoyi-quartz: Quartz scheduler module (job config, domain, mappers, service)
- ruoyi-generator: Code-generation module (reads DB metadata, Velocity templates, produces Java/HTML/XML/SQL)
- ruoyi-framework: Cross-cutting concerns (AOP aspects, security via Shiro, dynamic data source, global exception handling, filters)
- ruoyi-common: Shared annotations, utils, exception classes, constants, JSON support, pagination, XSS filters
- Top-level: Dockerfile, pom.xml, SQL scripts (schema/seeds), images and documentation.

##### Core Architectural Layers and Components
a. Presentation Layer
- Browser clients (desktop/mobile)
- Static resources: JavaScript/CSS libraries under ruoyi-admin/src/main/resources/static
- Thymeleaf templates under ruoyi-admin/src/main/resources/templates
- Swagger UI (generated API docs)
b. Web & Controller Layer
- Spring MVC controllers in ruoyi-admin/src/main/java/com/ruoyi/web/controller
- Interceptors (LoginAuthInterceptor), argument resolvers (LoginUserArgumentResolver) via ruoyi-admin → ruoyi-framework
c. Service Layer
- ruoyi-system and ruoyi-quartz implement business logic via service interfaces (ISysUserService, ISysJobService, etc.)
- ruoyi-generator service (IGenService) reads DB metadata and drives template engine
- Cross-cutting: AsyncManager, logging aspects, data-scope aspects in ruoyi-framework
d. Persistence Layer
- MyBatis mappers in ruoyi-system and ruoyi-quartz modules
- DynamicDataSource managing multiple DBs (dev/run/uat profiles) via ruoyi-framework
- Caching via Ehcache (ehcache-shiro.xml)
e. Scheduler & Batch
- Quartz jobs configured in ruoyi-quartz (ScheduleConfig, CronUtils, AbstractQuartzJob)
f. Security & Cross-Cutting
- Apache Shiro (realm, filters, session management) in ruoyi-framework
- AOP aspects: @Log, @DataScope, @DataSource switching
- Global exception handler, JSON util, XSS filter
g. Database
- MySQL (or any JDBC) using scripts in sql/ directory
- Tables for users, roles, menus, jobs, logs, etc.

##### Relationships and Data Flow
- Browser → HTTP request → DispatcherServlet (Spring MVC)
- Request passes through Shiro filters → Interceptors → Controller
- Controller invokes service layer → AOP aspects apply (logging, data-scope, transaction)
- Service calls MyBatis mapper → SQL → DB
- Response propagates back through same chain → view resolver (Thymeleaf) or JSON output
- Scheduled tasks run independently via Quartz scheduler bean
- Code generator module called via “在线构建器” controller, reads DB metadata, applies Velocity templates, returns downloadable code

##### Architectural Patterns & Design Principles
- Layered MVC architecture
- Modular monolith (clear separation of concerns into modules)
- AOP for cross-cutting concerns (logging, security, dynamic data source, exception handling)
- DAO pattern via MyBatis mappers
- Template-based code generation
- Pluggable scheduler via Quartz
- Dynamic configuration via Spring profiles (dev/run/uat) and application.yml

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Browser (Desktop/Mobile)"]:::ui
        Static["Static Resources"]:::ui
        Templates["Thymeleaf Templates"]:::ui
        Swagger["Swagger UI"]:::ui
    end

    %% Web Layer
    subgraph "Web & Controller Layer"
        direction TB
        Dispatcher["DispatcherServlet"]:::web
        ShiroFilter["Shiro Filters"]:::web
        Controllers["Controllers"]:::web
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        rsysSI["ISysUserService, etc."]:::service
        rsysImpl["System Service Impl"]:::service
        rquartzSI["Quartz Service Interfaces"]:::service
        rquartzImpl["Quartz Service Impl"]:::service
        geSI["IGenService"]:::service
        geImpl["GenServiceImpl"]:::service
        GenController["Gen Controller"]:::service
    end

    %% Cross-Cutting
    subgraph "Cross-Cutting Concerns"
        direction TB
        AOPAspects["AOP Aspects (@Log, @DataScope, @DataSource)"]:::cross
        DynamicDS["DynamicDataSource"]:::cross
        ShiroConf["Shiro Config"]:::cross
        GlobalEx["GlobalExceptionHandler"]:::cross
        AsyncMgr["Async Manager & Factory"]:::cross
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        rsysMapperIntf["MyBatis Mapper Interfaces"]:::pers
        rsysMapperXML["Mapper XMLs"]:::pers
        rquartzMapperIntf["Quartz Mapper Interfaces"]:::pers
        rquartzMapperXML["Quartz XMLs"]:::pers
        genMapper["GenMapper & XML"]:::pers
    end

    %% Scheduler
    subgraph "Scheduler"
        direction TB
        quartzScheduler["Quartz Scheduler"]:::sched
    end

    %% Database
    DB["Database (MySQL)"]:::db

    %% Flow Arrows
    Browser -->|requests| Dispatcher
    Browser --> Static
    Browser --> Templates
    Browser --> Swagger

    Dispatcher -->|through| ShiroFilter
    ShiroFilter --> Controllers
    Controllers -->|invoke| rsysSI
    Controllers -->|invoke| rquartzSI
    Controllers -->|invoke| geSI
    Controllers -->|invoke| GenController

    GenController -->|calls| geSI
    geSI -->|reads metadata| DB
    geSI -->|writes code| Templates

    rsysSI -->|implemented by| rsysImpl
    rquartzSI -->|implemented by| rquartzImpl
    geSI -->|implemented by| geImpl

    %% Services to Persistence
    rsysImpl -->|uses| rsysMapperIntf
    rsysMapperIntf --> rsysMapperXML
    rquartzImpl -->|uses| rquartzMapperIntf
    rquartzMapperIntf --> rquartzMapperXML
    geImpl -->|uses| genMapper
    genMapper -->|XML| genMapper

    %% Persistence to DB
    rsysMapperXML -->|SQL| DB
    rquartzMapperXML -->|SQL| DB
    genMapper -->|SQL| DB

    %% Scheduler triggers
    quartzScheduler -->|triggers| rquartzSI

    %% Cross-cutting weaving
    AOPAspects -.-> Controllers
    AOPAspects -.-> rsysImpl
    AOPAspects -.-> rquartzImpl
    DynamicDS -.-> rsysMapperIntf
    DynamicDS -.-> rquartzMapperIntf
    ShiroConf -.-> Dispatcher
    GlobalEx -.-> Controllers
    AsyncMgr -.-> rsysSI

    %% Click Events
    click Static "https://github.com/lerry903/ruoyi/tree/master/ruoyi-admin/src/main/resources/static"
    click Templates "https://github.com/lerry903/ruoyi/tree/master/ruoyi-admin/src/main/resources/templates"
    click Controllers "https://github.com/lerry903/ruoyi/tree/master/ruoyi-admin/src/main/java/com/ruoyi/web/controller"
    click rsysSI "https://github.com/lerry903/ruoyi/tree/master/ruoyi-system/src/main/java/com/ruoyi/system/service"
    click rsysImpl "https://github.com/lerry903/ruoyi/tree/master/ruoyi-system/src/main/java/com/ruoyi/system/service/impl"
    click rsysMapperIntf "https://github.com/lerry903/ruoyi/tree/master/ruoyi-system/src/main/java/com/ruoyi/system/mapper"
    click rsysMapperXML "https://github.com/lerry903/ruoyi/tree/master/ruoyi-system/src/main/resources/mapper/system"
    click rquartzSI "https://github.com/lerry903/ruoyi/tree/master/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service"
    click rquartzImpl "https://github.com/lerry903/ruoyi/tree/master/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl"
    click quartzScheduler "https://github.com/lerry903/ruoyi/blob/master/ruoyi-quartz/src/main/java/com/ruoyi/quartz/config/ScheduleConfig.java"
    click rquartzMapperIntf "https://github.com/lerry903/ruoyi/tree/master/ruoyi-quartz/src/main/java/com/ruoyi/quartz/mapper"
    click rquartzMapperXML "https://github.com/lerry903/ruoyi/tree/master/ruoyi-quartz/src/main/resources/mapper/quartz"
    click GenController "https://github.com/lerry903/ruoyi/blob/master/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/GenController.java"
    click geSI "https://github.com/lerry903/ruoyi/blob/master/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenService.java"
    click geImpl "https://github.com/lerry903/ruoyi/blob/master/ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/GenServiceImpl.java"
    click genMapper "https://github.com/lerry903/ruoyi/blob/master/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenMapper.java"
    click genMapper "https://github.com/lerry903/ruoyi/blob/master/ruoyi-generator/src/main/resources/mapper/generator/GenMapper.xml"
    click AOPAspects "https://github.com/lerry903/ruoyi/tree/master/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj"
    click DynamicDS "https://github.com/lerry903/ruoyi/blob/master/ruoyi-framework/src/main/java/com/ruoyi/framework/datasource/DynamicDataSource.java"
    click ShiroConf "https://github.com/lerry903/ruoyi/blob/master/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ShiroConfig.java"
    click GlobalEx "https://github.com/lerry903/ruoyi/blob/master/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java"
    click AsyncMgr "https://github.com/lerry903/ruoyi/blob/master/ruoyi-framework/src/main/java/com/ruoyi/framework/manager/AsyncManager.java"
    click AsyncMgr "https://github.com/lerry903/ruoyi/blob/master/ruoyi-framework/src/main/java/com/ruoyi/framework/manager/factory/AsyncFactory.java"
    click DB "https://github.com/lerry903/ruoyi/tree/master/sql/"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef web fill:#85C1E9,stroke:#1B4F72,color:#1B2631
    classDef service fill:#A9DFBF,stroke:#145A32,color:#0E2618
    classDef cross fill:#F9E79F,stroke:#7D6608,color:#4D2600
    classDef pers fill:#F5CBA7,stroke:#943126,color:#3E1F10
    classDef db fill:#F0B27A,stroke:#7D6608,color:#512E21
    classDef sched fill:#D2B4DE,stroke:#6C3483,color:#2C0A2D
```
