# pagehelper/mybatis-pagehelper architecture

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

- Interactive diagram: https://gitdiagram.com/pagehelper/mybatis-pagehelper
- Repository: https://github.com/pagehelper/mybatis-pagehelper

## Overview

##### Project type and purpose
- This is a Java library—specifically a MyBatis plugin (“PageHelper”)—that transparently adds pagination capabilities to MyBatis‐powered data access. It hooks into MyBatis’s Executor via interceptors, parses and rewrites SQL, and supports a wide range of database dialects.

##### File structure
- Top level:
- pom.xml, .github/, LICENSE, README.md (project meta, CI, release)
- wikis/ (usage guides, changelog)
- src/main/java/com/github/pagehelper:
- PageHelper API entry (PageHelper, PageInterceptor, QueryInterceptor)
- Dialect packages (auto, helper, replace, rowbounds, AbstractDialect classes)
- parser (CountSqlParser, OrderBySqlParser, SqlParserUtil, etc.)
- cache (CacheFactory, GuavaCache, SimpleCache)
- util (ClassUtil, SqlSafeUtil, MetaObjectUtil, etc.)
- src/test : exhaustive test suites against multiple databases and configurations.

##### README for additional insights
- Targets MyBatis 3.1.0+ and JDK 8+
- Depends on pagehelper-x.y.z.jar and jsqlparser-x.y.z.jar
- Registers “alias→Dialect” mappings for many DBs, plus auto‐dialect resolution
- Illustrates interceptor usage, configuration properties, and extension points

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef core fill:#cff,stroke:#333,stroke-width:1px
    classDef parser fill:#fcf,stroke:#333,stroke-width:1px
    classDef dialect fill:#cfc,stroke:#333,stroke-width:1px
    classDef cache fill:#ffc,stroke:#333,stroke-width:1px
    classDef db fill:#ccf,stroke:#333,stroke-width:1px

    App["Client Application / Service Layer"]:::external
    MyBatis["MyBatis Core\nSqlSessionFactory, Executor"]:::core

    subgraph "PageHelper Plugin"
        PageHelperNode["PageHelper API"]:::core
        PageInt["PageInterceptor"]:::core
        QueryInt["QueryInterceptor"]:::core
        Chain["BoundSqlInterceptorChain"]:::core
    end

    subgraph "SQL Parser Subsystem"
        CountParser["CountSqlParser"]:::parser
        OrderParser["OrderBySqlParser"]:::parser
        ParserUtil["SqlParserUtil"]:::parser
        Defaults["Default Parsers"]:::parser
    end

    subgraph "Dialect Strategy Module"
        DialectInterface["Dialect Interface"]:::dialect
        AbsDialect["AbstractDialect"]:::dialect
        AbsHelperDialect["AbstractHelperDialect"]:::dialect
        AbsRowDialect["AbstractRowBoundsDialect"]:::dialect
        subgraph "Helper Dialects"
            HelperPkg["helper dialects"]:::dialect
        end
        subgraph "Auto Dialect"
            AutoPkg["auto dialects"]:::dialect
            PageAuto["PageAutoDialect"]:::dialect
        end
        subgraph "RowBounds Dialects"
            RowPkg["rowbounds dialects"]:::dialect
        end
        subgraph "Replace Dialects"
            ReplacePkg["replace dialects"]:::dialect
        end
    end

    subgraph "Cache Subsystem"
        CacheFactory["CacheFactory"]:::cache
        GuavaCache["GuavaCache"]:::cache
        SimpleCache["SimpleCache"]:::cache
    end

    JSQL["jSQLParser Library"]:::external

    DataSource["DataSource / JDBC"]:::core
    DB["Database"]:::db

    App -->|"calls SqlSession"| MyBatis
    MyBatis -->|"Executor.query() intercepted"| PageInt
    PageInt -->|delegates| QueryInt
    QueryInt -->|passes to| Chain
    Chain -->|"uses"| CountParser
    Chain -->|"uses"| OrderParser
    Chain -->|"utilizes"| ParserUtil
    Chain -->|Falls back| Defaults
    CountParser -->|"parses SQL"| JSQL
    OrderParser -->|"parses SQL"| JSQL
    Chain -->|"resolves dialect"| DialectInterface
    DialectInterface --> AbsDialect
    AbsDialect --> AbsHelperDialect
    AbsDialect --> AbsRowDialect
    DialectInterface --> HelperPkg
    DialectInterface --> AutoPkg
    AutoPkg --> PageAuto
    DialectInterface --> RowPkg
    DialectInterface --> ReplacePkg
    Chain -->|"caches metadata"| CacheFactory
    CacheFactory --> GuavaCache
    CacheFactory --> SimpleCache
    Chain -->|"outputs rewritten SQL"| DataSource
    DataSource -->|"executes SQL"| DB

    click PageHelperNode "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/PageHelper.java"
    click PageInt "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/PageInterceptor.java"
    click QueryInt "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/QueryInterceptor.java"
    click Chain "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/BoundSqlInterceptorChain.java"
    click CountParser "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/parser/CountSqlParser.java"
    click OrderParser "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/parser/OrderBySqlParser.java"
    click ParserUtil "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/parser/SqlParserUtil.java"
    click Defaults "https://github.com/pagehelper/mybatis-pagehelper/tree/master/src/main/java/com/github/pagehelper/parser/defaults"
    click DialectInterface "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/Dialect.java"
    click AbsDialect "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/dialect/AbstractDialect.java"
    click AbsHelperDialect "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/dialect/AbstractHelperDialect.java"
    click AbsRowDialect "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/dialect/AbstractRowBoundsDialect.java"
    click HelperPkg "https://github.com/pagehelper/mybatis-pagehelper/tree/master/src/main/java/com/github/pagehelper/dialect/helper"
    click AutoPkg "https://github.com/pagehelper/mybatis-pagehelper/tree/master/src/main/java/com/github/pagehelper/dialect/auto"
    click PageAuto "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/page/PageAutoDialect.java"
    click RowPkg "https://github.com/pagehelper/mybatis-pagehelper/tree/master/src/main/java/com/github/pagehelper/dialect/rowbounds"
    click ReplacePkg "https://github.com/pagehelper/mybatis-pagehelper/tree/master/src/main/java/com/github/pagehelper/dialect/replace"
    click CacheFactory "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/cache/CacheFactory.java"
    click GuavaCache "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/cache/GuavaCache.java"
    click SimpleCache "https://github.com/pagehelper/mybatis-pagehelper/blob/master/src/main/java/com/github/pagehelper/cache/SimpleCache.java"
```
