# cmeza20/spring-data-generator architecture

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

- Interactive diagram: https://gitdiagram.com/cmeza20/spring-data-generator
- Repository: https://github.com/cmeza20/spring-data-generator

## Overview

##### Project Purpose and Type
- This is a library/tool that dynamically generates JPA repositories and manager classes for Spring Data applications. It supports both runtime generation (via annotations) and a Maven plugin execution mode.
- The README shows that the primary goal is to scan JPA entity classes (using annotations like @SDGenerate, @SDNoGenerate, and @SDGenerator) and then generate repositories or managers, optionally including support for additional interfaces such as QuerydslPredicateExecutor and Lombok integration.

##### File Structure
- The core package is “com.cmeza.sdgenerator”. Under this package you find several logically segmented submodules:
- /annotation: Contains the custom annotations (SDGenerate, SDGenerator, SDNoGenerate) that mark classes for scanning.
- /plugin: Contains Maven Mojo classes (CommonsMojo, SDAllMojo, SDManagerMojo, SDRepositoryMojo); these serve as the integration point for generating code via Maven.
- /provider: Includes classes such as AbstractTemplateProvider and ClassPathScanningProvider which are responsible for scanning classpaths and providing templates for repository/manager generation.
- /support: Comprises support classes for template management (ManagerTemplateSupport, RepositoryTemplateSupport) and configuration (ScanningConfigurationSupport) as well as sub-packages for “maker” (which includes builder and values) that assemble the actual structure.
- /util: Contains utility classes (BuildUtils, Constants, CustomResourceLoader, GeneratorException, etc.) that aid in configuration, logging, exception management, and auxiliary tasks.
- The main class SDGeneratorManager is likely the entry point lying in the root of the package.
- The presence of a pom.xml, .travis.yml, and other configuration files indicates that the project is built as a Maven project and undergoes continuous integration testing.

##### Main Components
a. Core Generation Engine:
- SDGeneratorManager: This is the central manager coordinating code generation.
- Annotations: Represent the custom annotations, which are used in entity classes to trigger generation.
b. Plugin Layer:
- Maven Mojo classes (SDAllMojo, SDManagerMojo, SDRepositoryMojo, CommonsMojo): They act as adapters to trigger the generation process via Maven commands.
c. Provider & Scanning:
- Provider Layer (AbstractTemplateProvider, ClassPathScanningProvider): Responsible for scanning the project’s classpaths to locate JPA entities based on configured packages and annotations.
d. Support & Template Generation:
- Template Supports (ManagerTemplateSupport, RepositoryTemplateSupport) and configuration supports (ScanningConfigurationSupport).
- Maker submodule components (ManagerStructure, RepositoryStructure, ObjectBuilder, etc.) are tasked with constructing the code structure based on the provided templates.
e. Utility Services:
- Utility classes (SDLogger, GeneratorUtils, BuildUtils, etc.) that provide logging, constants, configuration loading and exception management to support the generation process.

##### Relationships and Interactions
- The Maven Plugin (through one of the Mojo classes) triggers the SDGeneratorManager.
- SDGeneratorManager invokes the Provider components to perform a classpath scan to locate entity classes based on custom annotations.
- Once entities are identified, the Support components (including scanning configurations and template support) process the templates and setup for generating repositories and managers.
- The Maker components along with the Builder classes then construct the actual code structure for repositories/managers, using values and definitions provided by the Support layer.
- Utility classes are used throughout the process to handle configuration, logging, and error handling.

##### Architectural Patterns and Design Principles
- Separation of concerns: The functionality is clearly divided into annotation processing, plugin integration, template provision, and code generation.
- Extensibility: The design supports extensible attributes, like additional interfaces and custom extensions (see “additionalExtends” in the configuration) for generated repositories/managers.
- Modularity: With distinct packages for provider, support, maker, and util, the architecture is modular and maintainable.
- Declarative configuration via annotations and XML (Maven plugin settings) is deeply integrated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Maven Plugin Layer
    subgraph "Maven Plugin Layer"
        Plugin["Mojo Classes:\nSDAllMojo, SDManagerMojo, SDRepositoryMojo, CommonsMojo"]:::plugin
    end

    %% Core Generation Engine
    subgraph "Core Generation Engine"
        Engine["SDGeneratorManager"]:::core
    end

    %% Annotations
    subgraph "Annotations"
        Anno["SDGenerate, SDGenerator, SDNoGenerate"]:::annotation
    end

    %% Provider & Scanning
    subgraph "Provider & Scanning"
        Provider["AbstractTemplateProvider, ClassPathScanningProvider"]:::provider
    end

    %% Support & Template Generation
    subgraph "Support & Template Generation"
        Support["ManagerTemplateSupport, RepositoryTemplateSupport, ScanningConfigurationSupport"]:::support
    end

    %% Maker Components
    subgraph "Maker Components"
        Maker["ManagerStructure, RepositoryStructure, ObjectBuilder, etc."]:::maker
    end

    %% Utility Services
    subgraph "Utility Services"
        Util["BuildUtils, Constants, CustomResourceLoader, GeneratorException, GeneratorUtils, SDLogger, SDMojoException, Tuple"]:::util
    end

    %% Connections
    Plugin -->|"triggers"| Engine
    Engine -->|"invokes scanning"| Provider
    Anno -->|"marks entities"| Provider
    Provider -->|"provides templates"| Support
    Support -->|"builds code structure"| Maker

    Util ---|"supports"| Engine
    Util ---|"supports"| Provider
    Util ---|"supports"| Support
    Util ---|"supports"| Maker

    %% Click Events
    click Engine "https://github.com/cmeza20/spring-data-generator/blob/master/src/main/java/com/cmeza/sdgenerator/SDGeneratorManager.java"
    click Anno "https://github.com/cmeza20/spring-data-generator/tree/master/src/main/java/com/cmeza/sdgenerator/annotation"
    click Plugin "https://github.com/cmeza20/spring-data-generator/tree/master/src/main/java/com/cmeza/sdgenerator/plugin"
    click Provider "https://github.com/cmeza20/spring-data-generator/tree/master/src/main/java/com/cmeza/sdgenerator/provider"
    click Support "https://github.com/cmeza20/spring-data-generator/tree/master/src/main/java/com/cmeza/sdgenerator/support"
    click Maker "https://github.com/cmeza20/spring-data-generator/tree/master/src/main/java/com/cmeza/sdgenerator/support/maker"
    click Util "https://github.com/cmeza20/spring-data-generator/tree/master/src/main/java/com/cmeza/sdgenerator/util"

    %% Styles
    classDef core fill:#ffdddd,stroke:#ff0000,stroke-width:2px;
    classDef plugin fill:#ddeeff,stroke:#0000ff,stroke-width:2px;
    classDef provider fill:#ddffdd,stroke:#00aa00,stroke-width:2px;
    classDef support fill:#ffddaa,stroke:#ff9900,stroke-width:2px;
    classDef maker fill:#eeddff,stroke:#9900ff,stroke-width:2px;
    classDef util fill:#eeeeee,stroke:#888888,stroke-width:2px;
    classDef annotation fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
```
