# spongepowered/mixin architecture

> Architecture diagram of the GitHub repository spongepowered/mixin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/spongepowered/mixin
- Repository: https://github.com/spongepowered/mixin

## Overview

##### Main Components

a) Core Components:
- Mixin Transformer System
- ASM Integration Layer
- Service Provider Interface (SPI)
- Annotation Processing System
- Bytecode Manipulation Layer

b) Supporting Components:
- Launch Platform Integration
- Logging System
- Configuration Management
- Obfuscation Support

##### Architectural Layers (from top to bottom)

Layer 1: Entry Points
- MixinBootstrap
- Platform-specific Launchers (ModLauncher, LegacyLauncher)
- Annotation Processor

Layer 2: Core Services
- MixinService
- Configuration Management
- Class Loading & Transformation

Layer 3: Processing Pipeline
- Mixin Processing
- Injection Handling
- Transformation Chain

Layer 4: Bytecode Manipulation
- ASM Integration
- Class Generation
- Method Manipulation

##### Key Relationships

a) Service Flow:
- How MixinBootstrap initializes the system
- Service discovery and initialization
- Demonstrate transformation pipeline flow

b) Data Flow:
- Configuration loading and parsing
- Class transformation process
- Annotation processing pipeline

##### Integration Points

a) External Systems:
- ModLauncher Integration
- Development Tools (IDE plugins)
- Build System Integration

b) Internal Bridges:
- Service Provider Interface implementations
- Platform-specific adapters
- Remapping support

##### Design Elements

Use the following visual elements:
- Rectangles: Core components
- Rounded rectangles: Services
- Hexagons: Entry points

- Blue: Core systems
- Green: Processing components
- Orange: Integration points
- Gray: Supporting systems

- Solid: Direct dependencies
- Double-headed: Bidirectional communication

##### Specific Implementation Details

a) Core Services (org.spongepowered.asm.service):
- IMixinService
- IClassProvider
- IClassBytecodeProvider
- ITransformerProvider

b) Mixin Processing (org.spongepowered.asm.mixin):
- MixinEnvironment
- MixinConfig
- MixinInfo

c) Transformation (org.spongepowered.asm.mixin.transformer):
- MixinTransformer
- MixinProcessor
- ClassInfo

## Diagram (Mermaid)

```mermaid
graph TB
    %% Core Components
    subgraph Core
        Bootstrap["MixinBootstrap<br>---<br>+ init()<br>+ getPlatform()"]:::core
        Environment["MixinEnvironment<br>---<br>+ getCurrentPhase()<br>+ getDefaultPhase()"]:::core
        Service["MixinService<br>---<br>+ getService()<br>+ init()"]:::core
        Transformer["MixinTransformer<br>---<br>+ transformClass()<br>+ applyMixins()"]:::core
    end

    %% Service Layer
    subgraph Services
        IMixinService["IMixinService<br>---<br>+ getName()<br>+ getPhaseProviders()"]:::service
        ModLauncher["ModLauncherService<br>---<br>+ getName()<br>+ initialize()"]:::service
        ServiceAbstract["MixinServiceAbstract<br>---<br>+ getName()<br>+ getClassProvider()"]:::service
    end

    %% Transformation Pipeline
    subgraph Pipeline
        Processor["MixinProcessor<br>---<br>+ select()<br>+ prepare()<br>+ apply()"]:::processor
        Config["MixinConfig<br>---<br>+ load()<br>+ validate()"]:::processor
        Info["MixinInfo<br>---<br>+ getClassName()<br>+ getTargets()"]:::processor
        TargetContext["MixinTargetContext<br>---<br>+ getTarget()<br>+ applyMixins()"]:::processor
        AppStandard["MixinApplicatorStandard<br>---<br>+ apply()<br>+ applyMixin()"]:::processor
        AppInterface["MixinApplicatorInterface<br>---<br>+ apply()<br>+ handleInjections()"]:::processor
    end

    %% Injection System
    subgraph Injections
        InjPoint["InjectionPoint<br>---<br>+ find()<br>+ parse()"]:::injection
        BeforeInv["BeforeInvoke<br>---<br>+ find()"]:::injection
        AfterInv["AfterInvoke<br>---<br>+ find()"]:::injection
        BeforeField["BeforeFieldAccess<br>---<br>+ find()"]:::injection
        BeforeRet["BeforeReturn<br>---<br>+ find()"]:::injection
        ModConst["ModifyConstant<br>---<br>+ modify()"]:::injection
    end

    %% Relationships
    Bootstrap --> Environment
    Bootstrap --> Service
    Service --> Transformer
    Service --> IMixinService
    IMixinService --> ModLauncher
    IMixinService --> ServiceAbstract
    Transformer --> Processor
    Processor --> Config
    Processor --> Info
    Processor --> TargetContext
    TargetContext --> AppStandard
    TargetContext --> AppInterface
    AppStandard --> InjPoint
    AppInterface --> InjPoint
    InjPoint --> BeforeInv
    InjPoint --> AfterInv
    InjPoint --> BeforeField
    InjPoint --> BeforeRet
    InjPoint --> ModConst

    %% Click Events
    click Bootstrap "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java"
    click Environment "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java"
    click Service "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/service/MixinService.java"
    click Transformer "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java"
    click Processor "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/transformer/MixinProcessor.java"
    click Config "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/transformer/Config.java"
    click Info "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java"
    click TargetContext "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java"
    click AppStandard "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java"
    click AppInterface "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorInterface.java"
    click IMixinService "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/service/IMixinService.java"
    click ModLauncher "https://github.com/SpongePowered/Mixin/blob/master/src/modlauncher/java/org/spongepowered/asm/service/modlauncher/MixinServiceModLauncher.java"
    click ServiceAbstract "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/service/MixinServiceAbstract.java"
    click InjPoint "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java"
    click BeforeInv "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeInvoke.java"
    click AfterInv "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/injection/points/AfterInvoke.java"
    click BeforeField "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeFieldAccess.java"
    click BeforeRet "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeReturn.java"
    click ModConst "https://github.com/SpongePowered/Mixin/blob/master/src/main/java/org/spongepowered/asm/mixin/injection/ModifyConstant.java"

    %% Styles
    classDef core fill:#a8d1f0,stroke:#333,stroke-width:2px;
    classDef service fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef processor fill:#FFB347,stroke:#333,stroke-width:2px;
    classDef injection fill:#DDA0DD,stroke:#333,stroke-width:2px;

    %% Legend
    subgraph Legend
        CoreLegend["Core Component"]:::core
        ServiceLegend["Service"]:::service
        ProcessorLegend["Processor"]:::processor
        InjectionLegend["Injection"]:::injection
    end
```
