# martinsjavacode/avro-gradle-plugin architecture

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

- Interactive diagram: https://gitdiagram.com/martinsjavacode/avro-gradle-plugin
- Repository: https://github.com/martinsjavacode/avro-gradle-plugin

## Overview

##### Project Type & Overview
- Type: Gradle Plugin – a build tool extension that integrates with Gradle.
- Purpose: Simplify the process of converting Avro schema files (*.avsc) into Java classes by introducing a custom Gradle task (generateAvroClasses) along with customizable plugin configurations.

##### Main Components
a. Gradle Build Lifecycle:
- Gradle build process that triggers the plugin.
- How users incorporate the plugin via their build.gradle (or build.gradle.kts) files with the "avro" configuration block.

b. Plugin Core:
- AvroGradlePlugin (found in src/main/kotlin/io/github/martinsjavacode/avro/AvroGradlePlugin.kt). This is the entry point that registers the plugin and its tasks into the Gradle ecosystem.

c. Plugin Configuration/Extension:
- AvroPluginExtension (from AvroPluginExtension.kt) where users define parameters (sourceDir, outputDir, fieldVisibility, stringType, optionalGetters, etc.) that drive the behavior of the task.

d. Task Execution:
- Reads Avro schema files from a configurable source directory (default: src/main/resources/avro, but can be updated)
- Processes these schemas (with potential dependency on Apache Avro libraries)
- Generates Java source files into a specified output directory (default: build/generated/java).

e. External Dependencies & Environment:
- External tools and technologies such as Java (version 21+), Gradle (version 8.0+), and Apache Avro (1.12.0+).
- Test components (src/test) to show how the functionality is verified.

##### Relationships & Interactions
- The user writes configuration in the build script. This configuration block (avro {}) gets passed to the AvroPluginExtension.
- The AvroGradlePlugin, upon initialization, registers “generateAvroClasses” with the build lifecycle. It reads the configurations and instructs the task behavior.
- During the task execution, the plugin reads schema files from the designated source directory, processes them (using Avro libraries and applying configuration options like string type or field visibility), and then outputs the generated Java classes to the output directory.
- The task is invoked either directly via ./gradlew generateAvroClasses or indirectly when running ./gradlew build.

##### Architectural Patterns & Design Principles
- Modularity: Separation between configuration (extension) and execution (plugin and task) facilitates flexibility and customization.
- Integration with Gradle’s convention-over-configuration: The plugin auto-registers tasks based on established Gradle lifecycle hooks.
- Extensibility: Users can customize behavior via the provided parameters.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Gradle Build Environment
    subgraph "Gradle Build Environment"
        BGS1("build.gradle.kts"):::build
        BGS2("settings.gradle.kts"):::build
    end

    %% Plugin Initialization & Configuration
    subgraph "Plugin Core & Configuration"
        AP("AvroGradlePlugin"):::plugin
        APE("AvroPluginExtension"):::config
    end

    %% Task Registration
    AP -->|"RegistersTask"| GAC("generateAvroClasses"):::task

    %% Build Script feeds configuration
    BGS1 -->|"configures"| APE
    BGS2 -->|"configures"| APE

    %% Task Execution Flow
    subgraph "Task Execution Flow"
        AVSF("Avro Schema Files (src/main/resources/avro)"):::task
        AVP("Avro Processing (using Apache Avro)"):::task
        GJC("Generated Java Classes (build/generated/java)"):::task
    end

    %% Flow within Task Execution
    GAC -->|"reads"| AVSF
    GAC -->|"processes"| AVP
    AVP -->|"outputsTo"| GJC

    %% External Dependencies
    subgraph "External Dependencies"
        JAVA("Java(v21+)"):::external
        GRADLE("Gradle(v8+)"):::external
        AAV("ApacheAvro(1.12.0+)"):::external
    end

    %% External Dependencies linking to Plugin and Processing logic
    GRADLE -->|"drives"| AP
    JAVA -->|"runs"| AP
    AAV -->|"usedBy"| AVP

    %% Unit Testing Block
    subgraph "Unit Testing"
        TEST("PluginUnitTests"):::test
        TESTSCHEMA("AvroSchema(Test)"):::test
    end

    %% Unit Testing interactions
    TEST -->|"validates"| AP
    TESTSCHEMA -->|"usedIn"| TEST

    %% Click Events
    click BGS1 "https://github.com/martinsjavacode/avro-gradle-plugin/blob/main/build.gradle.kts"
    click BGS2 "https://github.com/martinsjavacode/avro-gradle-plugin/blob/main/settings.gradle.kts"
    click AP "https://github.com/martinsjavacode/avro-gradle-plugin/blob/main/src/main/kotlin/io/github/martinsjavacode/avro/AvroGradlePlugin.kt"
    click APE "https://github.com/martinsjavacode/avro-gradle-plugin/blob/main/src/main/kotlin/io/github/martinsjavacode/avro/AvroPluginExtension.kt"
    click GAC "https://github.com/martinsjavacode/avro-gradle-plugin/blob/main/src/main/kotlin/io/github/martinsjavacode/avro/AvroGradlePlugin.kt"
    click TEST "https://github.com/martinsjavacode/avro-gradle-plugin/blob/main/src/test/kotlin/io/github/martinsjavacode/avro/AvroGradlePluginTest.kt"
    click TESTSCHEMA "https://github.com/martinsjavacode/avro-gradle-plugin/blob/main/src/test/resources/avro/user.avsc"

    %% Styles
    classDef build fill:#bbdefb,stroke:#0d47a1,stroke-width:2px
    classDef plugin fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px
    classDef config fill:#fff9c4,stroke:#f57f17,stroke-width:2px
    classDef task fill:#ffe0b2,stroke:#e65100,stroke-width:2px
    classDef external fill:#d1c4e9,stroke:#4a148c,stroke-width:2px
    classDef test fill:#ffccbc,stroke:#bf360c,stroke-width:2px
```
