# wujunjie521/ruoyi architecture

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

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

## Overview

##### Main Components
- Frontend/UI Layer: Although it is mainly a backend system, static resources, templates (HTML, CSS, JavaScript) and client-side assets are stored under src/main/resources/static and src/main/resources/templates. This layer delivers the user interface to browsers.
- Web/Application Layer: The Java code under src/main/java/com/ruoyi handles incoming HTTP requests. This includes:
- Controllers (e.g., controllers under com.ruoyi.framework/web/controller, com.ruoyi/project/*/controller) that manage HTTP endpoints.
- Service layer implementations (in various “service” packages) that encapsulate business logic.
- Utility and common packages (com.ruoyi/common) that provide shared functions and error handling.
- Security & Middleware: The project uses Apache Shiro for security (repositories under com.ruoyi.framework/shiro) with filters for login, captcha verification, online session tracking, and more. There’s also integration with Druid for database connection pooling and configuration via the configuration classes.
- Persistence/Data Access Layer: MyBatis mappers (files under src/main/resources/mybatis/…) and mapper interfaces in various packages (e.g., system, monitor) interact with the database. Database configuration is defined in resource files (application.yml, application-druid.yml).
- Job Scheduling & Logging: Components for task scheduling (Quartz integration) and logging, as seen from the job packages (com.ruoyi/project/monitor/job) and log configuration.
- Code Generation/Tooling Module: Modules under com.ruoyi/project/tool provide functionalities like code generation and online builder utilities.

##### Relationships and Interactions
- The client (web browser) interacts with the Frontend UI, which in turn communicates with the backend controllers managed by Spring MVC.
- Controllers call Service layer methods to process business logic.
- Service methods, in turn, delegate operations to the data access layer using MyBatis mappers.
- The security filters (using Apache Shiro) guard access to controllers and services, ensuring authenticated and authorized access.
- Job scheduling components interact with the database to persist job logs and configurations.
- Static resources and templates are served as part of the presentation layer.

##### Architectural Patterns and Design Principles
- Layered Architecture: Clear separation into presentation (views), application (controllers and services), and persistence (mappers and database) layers.
- MVC Pattern: Controllers, views (HTML templates), and models/dtos (domain objects) are well separated.
- Modular Design: Sub-packages within com.ruoyi (framework, project, common, tool) indicate separation of concerns and encapsulation.
- Use of Cross-Cutting Concerns: Aspects (e.g., LogAspect in framework/aspectj) allow centralized logging, auditing, and exception handling.
- Security Integration: Apache Shiro is used to control authentication and authorization across layers.

##### Technologies, Frameworks, and Libraries
- Spring Boot / Spring MVC (implied by the overall project structure and configuration files)
- Apache Shiro for security management
- MyBatis for ORM and database interaction
- Druid for database connection pooling
- Quartz for scheduling tasks
- Frontend libraries: hplus, inspinia themes along with jQuery, Bootstrap, and various JS libraries (for dynamic behavior and validation)
- Code generation tools that produce Java, HTML, JS, XML, and SQL artifacts

##### Instructing the Principal Software Engineer
- Use clear, descriptive labels for each component: e.g., “UI/Static Resources”, “Controller Layer”, “Business Service Layer”, “Data Mapper Layer”, “Security (Shiro)”, “Scheduling/Job Module”, and “Database”.
- From Client Browser > UI/Static Files > Controllers.
- Controllers > Services > Data Mappers > Database.
- Scheduled tasks sending logs and alerts to the monitoring/logging module.
- Rectangles for modules (e.g., Presentation, Business, Persistence).
- Diamonds or parallelograms for decision points (e.g., authentication filtering).
- Annotations to highlight architectural principles such as “Separation of Concerns”, “Layered Design”, and “Modular Integration”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        Browser("Browser"):::client
    end

    %% UI Layer
    subgraph "UI Layer"
        Static("UI/Static Resources"):::ui
        Templates("UI Templates"):::ui
    end

    %% Web/Application Layer
    subgraph "Web/Application Layer"
        Controllers("Controllers"):::controller
        Service("Business Service Layer"):::service
        Util("Utility & Common Functions"):::utility
    end

    %% Security & Middleware
    subgraph "Security & Middleware"
        Shiro("Apache Shiro"):::security
    end

    %% Persistence/Data Access Layer
    subgraph "Persistence/Data Access"
        Mappers("MyBatis Mappers"):::data
        DBConfig("Database Config Files"):::data
        Database("Database"):::database
    end

    %% Job Scheduling & Logging
    subgraph "Job Scheduling & Logging"
        Scheduler("Job Scheduling (Quartz)"):::job
        Logging("Logging & Monitoring"):::job
    end

    %% Code Generation & Tooling Module
    subgraph "Code Generation & Tooling"
        CodeGen("Code Generation Module"):::tool
        BuildTool("Build & Swagger Tooling"):::tool
    end

    %% Flow connections
    Browser -->|"HTTP-request"| Static
    Browser -->|"HTTP-request"| Templates
    Static -->|"Delivers UI"| Controllers
    Templates -->|"Delivers UI"| Controllers
    Browser ---|"Security Filter"| Shiro
    Shiro -->|"Validates"| Controllers
    Controllers -->|"Invokes"| Service
    Service -->|"Uses"| Util
    Service -->|"Delegates to"| Mappers
    Mappers -->|"Performs CRUD"| Database
    Service -->|"Reads Config"| DBConfig
    Scheduler -->|"Logs Jobs"| Logging
    Scheduler -->|"Persists Job Data"| Database
    Logging -->|"Stores Logs"| Database
    CodeGen -->|"Generates Code"| Service
    BuildTool -->|"Assists in Build"| CodeGen

    %% Click Events
    click Static "https://github.com/wujunjie521/ruoyi/tree/master/src/main/resources/static"
    click Templates "https://github.com/wujunjie521/ruoyi/tree/master/src/main/resources/templates"
    click Controllers "https://github.com/wujunjie521/ruoyi/tree/master/src/main/java/com/ruoyi/framework/web/controller"
    click Shiro "https://github.com/wujunjie521/ruoyi/blob/master/src/main/java/com/ruoyi/framework/shiro/realm/UserRealm.java"
    click Mappers "https://github.com/wujunjie521/ruoyi/tree/master/src/main/resources/mybatis"
    click DBConfig "https://github.com/wujunjie521/ruoyi/blob/master/src/main/resources/application.yml"
    click Scheduler "https://github.com/wujunjie521/ruoyi/tree/master/src/main/java/com/ruoyi/project/monitor/job"
    click Logging "https://github.com/wujunjie521/ruoyi/tree/master/src/main/java/com/ruoyi/framework/aspectj"
    click CodeGen "https://github.com/wujunjie521/ruoyi/tree/master/src/main/java/com/ruoyi/project/tool/gen"
    click BuildTool "https://github.com/wujunjie521/ruoyi/tree/master/src/main/java/com/ruoyi/project/tool/swagger"

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef ui fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef controller fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef service fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef utility fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef security fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef data fill:#fefefe,stroke:#818182,stroke-width:2px;
    classDef database fill:#fff,stroke:#343a40,stroke-width:2px,stroke-dasharray: 5 5;
    classDef job fill:#fde2e4,stroke:#b02a37,stroke-width:2px;
    classDef tool fill:#e8daef,stroke:#6f42c1,stroke-width:2px;
```
