# mybatis/spring-boot-starter architecture

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

- Interactive diagram: https://gitdiagram.com/mybatis/spring-boot-starter
- Repository: https://github.com/mybatis/spring-boot-starter

## Overview

##### And delineate the key modules
- Auto‑Configuration Module: The “mybatis-spring-boot-autoconfigure” directory contains the core auto‑configuration logic. It defines components (like MyBatisAutoConfiguration, ConfigurationCustomizer, MybatisProperties, etc.) that are wired into the Spring Boot startup via spring.factories and additional metadata in the META-INF directories.
- Starter Module: In “mybatis-spring-boot-starter” you have the module that acts as the entry point (a “starter”) for applications to easily integrate MyBatis. This module depends on the auto‑configuration module and exposes it to end users.
- Test & Test‑Autoconfigure Modules: “mybatis-spring-boot-starter-test” and “mybatis-spring-boot-test-autoconfigure” provide support for testing your MyBatis integrations and demonstrate proper configurations.
- Samples: The “mybatis-spring-boot-samples” folder contains several sub‑modules (annotation, freemarker, groovy, kotlin, thymeleaf, velocity, war, web, xml, etc.) that illustrate various ways to use MyBatis in a Spring Boot environment. They help illustrate usage patterns and validate that the starter works as expected in different scenarios.
- Build and Configuration Infrastructure: The project root itself holds configuration files for Maven, CI/CD pipelines (inside .github/workflows), licensing, and formatting. These ensure consistency and quality across modules.

##### Relationships and Data Flows
- Input Flow: A Spring Boot application starts up and (via Spring Boot’s auto‑configuration mechanism) loads the auto‑configuration classes from the “mybatis-spring-boot-autoconfigure” module.
- Integration: The auto‑configuration module reads external properties (e.g., via MybatisProperties) and creates/injects beans such as SqlSessionFactoryBeanCustomizer, using Spring’s dependency injection mechanism.
- Starter Role: The starter module acts as the facade, bundling the necessary auto‑configuration and in some cases providing default dependencies that the Spring Boot application will consume.
- Testing: The test modules simulate scenarios and use test-specific configurations to ensure that the auto‑configuration works as intended. There is an interaction between the test modules and the framework’s auto-configuration testing support.
- Samples: The samples demonstrate complete application examples. They connect the user interface (if any) or REST endpoints with the data layer that uses MyBatis, thereby showcasing the typical lifecycle and integration with Spring Boot applications.

##### Architectural Patterns and Design Principles
- Modular Design: The separation into auto‑configuration, starter, testing, and samples helps ensure that the core functionality is decoupled from demonstration projects and testing utilities.
- Convention over Configuration: The use of Spring Boot auto‑configuration leverages Spring’s “magic” where properties and metadata (e.g., in spring.factories) reduce the need for manual wiring.
- Dependency Injection and Inversion of Control: The design takes full advantage of Spring’s container to manage component lifecycles and dependencies.
- Extensibility: The design provides extension points (e.g., ConfigurationCustomizer, SqlSessionFactoryBeanCustomizer) so that users can override or extend default behavior.

##### Relevant Technologies
- MyBatis: The underlying data mapper.
- Spring Boot: Provides the auto-configuration and dependency injection framework.
- Maven: The build tool organizing the multi-module structure.
- Testing Frameworks: JUnit and spring-boot-test support modules for integration and unit testing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build and Configuration Infrastructure
    subgraph "Infrastructure"
        Build["Build & Configuration\n(pom.xml, .github/workflows, .mvn)"]:::build
    end

    %% Spring Boot Runtime
    subgraph "Spring Boot Runtime"
        Boot["Spring Boot"]:::boot
    end

    %% Production Modules
    subgraph "Production Modules"
        Auto["Auto-Configuration"]:::core
        Starter["Starter"]:::core
    end

    %% Supplementary Modules
    subgraph "Supplementary Modules"
        TestStarter["Starter Test"]:::supp
        TestAutoconfigure["Test Autoconfigure"]:::supp
        Samples["Samples"]:::supp
    end

    %% Relationships
    Boot -->|"loads_auto-config_via_spring.factories"| Auto
    Starter -->|"depends_on"| Auto

    TestStarter -->|"tests_integration"| Starter
    TestStarter -->|"validates_auto-config"| Auto

    TestAutoconfigure -->|"covers_auto-config"| Auto
    TestAutoconfigure -->|"covers_starter"| Starter

    Samples -->|"demonstrates_usage"| Starter

    Build -->|"builds"| Auto
    Build -->|"builds"| Starter
    Build -->|"builds"| TestStarter
    Build -->|"builds"| TestAutoconfigure
    Build -->|"builds"| Samples

    %% Styles
    classDef core fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef supp fill:#ffecb3,stroke:#ff6f00,stroke-width:2px;
    classDef build fill:#e1bee7,stroke:#6a1b9a,stroke-width:2px;
    classDef boot fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;

    %% Click Events
    click Auto "https://github.com/mybatis/spring-boot-starter/tree/master/mybatis-spring-boot-autoconfigure"
    click Starter "https://github.com/mybatis/spring-boot-starter/tree/master/mybatis-spring-boot-starter"
    click TestStarter "https://github.com/mybatis/spring-boot-starter/tree/master/mybatis-spring-boot-starter-test"
    click TestAutoconfigure "https://github.com/mybatis/spring-boot-starter/tree/master/mybatis-spring-boot-test-autoconfigure"
    click Samples "https://github.com/mybatis/spring-boot-starter/tree/master/mybatis-spring-boot-samples"
    click Build "https://github.com/mybatis/spring-boot-starter/tree/master/project root"
```
