# benhengeveld/nbt-recipes architecture

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

- Interactive diagram: https://gitdiagram.com/benhengeveld/nbt-recipes
- Repository: https://github.com/benhengeveld/nbt-recipes

## Overview

Based on our analysis of the file tree and README, the project is a Minecraft mod named “NBT Recipes” designed to extend the standard JSON recipe system. Its purpose is to allow modders to add detailed NBT (Named Binary Tag) data to recipe outputs and to support additional features (like setting counts for smelting, stonecutting, and smithing recipes). The mod leverages mixin injections to modify behavior in the vanilla Minecraft code, and it is organized into distinct client and core (or “main”) components.

##### Main Components
- Core Mod Component (located in src/main):
- Contains the core classes NbtRecipes.java and NbtRecipesDataGenerator.java.
- Includes mixin modifications that target vanilla functionality in crafting, smelting, stonecutting, and smithing. For example, classes like MixinItemStack, MixinShapedRecipe, MixinAbstractFurnaceBlockEntity, etc.
- Holds the Fabric mod configuration (fabric.mod.json) and mixin configuration (nbt-recipes.mixins.json).

- Client Component (located in src/client):
- Contains client-specific modifications in NbtRecipesClient.java.
- Includes its own set of mixins (e.g., ExampleClientMixin.java) and corresponding mixin configuration (nbt-recipes.client.mixins.json in resources).

- Build and Configuration Infrastructure:
- Gradle build scripts (build.gradle, gradlew, gradlew.bat, settings.gradle) for compiling and building the mod.
- GitHub workflows (.github/workflows/build.yml) for CI/CD.
- Other configuration files (gradle.properties, .gitignore, LICENSE).

##### Relationships and Interactions
- The mod hooks into the Minecraft runtime via Fabric’s mod loader. The Fabric environment calls the mod’s entry points (e.g., NbtRecipes.java).
- When Minecraft loads its recipes, the mixins (applied to classes like ItemStack or various recipe serializers) intercept recipe parsing logic to allow additional NBT data and custom count values. Some mixins are in the main package while others are client-specific.
- There is a clear separation:
- The core component handles the backend mod logic and data generation.
- The client component deals with any client-rendered modifications or display specifics.
- The build and configuration infrastructure integrates with CI/CD tools and Gradle to manage dependencies and deployments.

##### Architectural Patterns and Design Principles
- Use of Mixin:
- A common pattern in Minecraft modding that allows the mod to modify or extend the behavior of existing classes without direct source modification.
- Separation of Concerns:
- The project clearly divides client-side versus core functionality.
- Data generation for recipes (NbtRecipesDataGenerator) is separated from the recipe logic.
- Extendable JSON-based Recipe System:
- It follows the design principle of modifying existing JSON definitions (crafting, smelting, etc.) to incorporate additional data.

##### Specific Elements
- Clear labels for each modular component (Core, Client, Mixins, Build/Config).
- Initialization flow from the Fabric Mod Loader → NbtRecipes.java.
- Data flow from JSON definitions to processed recipes.
- Dependency/injection lines from mixin classes to the vanilla Minecraft classes they modify.
- For example, use rectangles for core modules, rounded rectangles for mixins, and ellipses for external systems like the Minecraft runtime.
- Annotations that note where configuration files (like fabric.mod.json and mixins JSON files) fit into the overall setup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    subgraph "External Systems"
        FabricLoader("Fabric Mod Loader"):::external
        VanillaItemStack("Vanilla ItemStack"):::external
        VanillaCrafting("Vanilla Crafting"):::external
        VanillaSmelting("Vanilla Smelting"):::external
        VanillaStonecutting("Vanilla Stonecutting"):::external
        VanillaRendering("Vanilla Rendering"):::external
    end

    %% Core Mod Component
    subgraph "Core Mod Component"
        NbtRecipes["NbtRecipes.java"]:::core
        NbtRecipesDataGen["NbtRecipesDataGenerator.java"]:::core
        subgraph "Core Mixins"
            MixinItemStack["MixinItemStack.java"]:::mixin
            MixinShapedRecipe["MixinShapedRecipe.java"]:::mixin
            MixinAbstractFurnace["MixinAbstractFurnaceBlockEntity.java"]:::mixin
            MixinCookingRecipe["MixinCookingRecipeSerializer.java"]:::mixin
            MixinCuttingRecipe["MixinCuttingRecipeSerializer.java"]:::mixin
        end
        FabricConfig["fabric.mod.json"]:::config
        MixinConfigCore["nbt-recipes.mixins.json"]:::config
    end

    %% Client Component
    subgraph "Client Component"
        NbtRecipesClient["NbtRecipesClient.java"]:::client
        ExampleClientMixin["ExampleClientMixin.java"]:::mixin
        ClientMixinConfig["nbt-recipes.client.mixins.json"]:::config
    end

    %% Build & Deployment
    subgraph "Build & Deployment"
        GradleScripts["Gradle Build Scripts"]:::build
        GitHubActions["GitHub Actions(build.yml)"]:::build
        AdditionalConfig["Additional Config Files"]:::build
    end

    %% Relationships and Data Flows
    FabricLoader -->|"initializes"| NbtRecipes
    FabricLoader -->|"initializes"| NbtRecipesClient

    NbtRecipesDataGen -->|"processes"| VanillaCrafting
    NbtRecipesDataGen -->|"processes"| VanillaSmelting
    NbtRecipesDataGen -->|"processes"| VanillaStonecutting

    MixinItemStack -->|"modifies"| VanillaItemStack
    MixinShapedRecipe -->|"modifies"| VanillaCrafting
    MixinAbstractFurnace -->|"modifies"| VanillaSmelting
    MixinCookingRecipe -->|"modifies"| VanillaSmelting
    MixinCuttingRecipe -->|"modifies"| VanillaStonecutting
    ExampleClientMixin -->|"modifies"| VanillaRendering

    GradleScripts -->|"builds"| NbtRecipes
    GradleScripts -->|"builds"| NbtRecipesClient
    GitHubActions -->|"triggers"| GradleScripts
    AdditionalConfig -->|"supports"| GradleScripts

    %% Styles
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef mixin fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef client fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef config fill:#FAD7A0,stroke:#9A7D0A,stroke-width:2px;
    classDef build fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#922B21,stroke-width:2px;

click NbtRecipes "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/main/java/ca/sync/nbtrecipes/NbtRecipes.java"
click NbtRecipesDataGen "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/main/java/ca/sync/nbtrecipes/NbtRecipesDataGenerator.java"
click MixinItemStack "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/main/java/ca/sync/nbtrecipes/mixin/MixinItemStack.java"
click MixinShapedRecipe "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/main/java/ca/sync/nbtrecipes/mixin/crafting/MixinShapedRecipe.java"
click MixinAbstractFurnace "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/main/java/ca/sync/nbtrecipes/mixin/smelting/MixinAbstractFurnaceBlockEntity.java"
click MixinCookingRecipe "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/main/java/ca/sync/nbtrecipes/mixin/smelting/MixinCookingRecipeSerializer.java"
click MixinCuttingRecipe "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/main/java/ca/sync/nbtrecipes/mixin/stonecutting/MixinCuttingRecipeSerializer.java"
click FabricConfig "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/main/resources/fabric.mod.json"
click MixinConfigCore "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/main/resources/nbt-recipes.mixins.json"
click NbtRecipesClient "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/client/java/ca/sync/nbtrecipes/NbtRecipesClient.java"
click ExampleClientMixin "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/client/java/ca/sync/nbtrecipes/mixin/client/ExampleClientMixin.java"
click ClientMixinConfig "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/src/client/resources/nbt-recipes.client.mixins.json"
click GradleScripts "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/build.gradle"
click GitHubActions "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/.github/workflows/build.yml"
click AdditionalConfig "https://github.com/benhengeveld/nbt-recipes/blob/1.20.1/gradle.properties"
```
