# retrooper/packetevents architecture

> Architecture diagram of the GitHub repository retrooper/packetevents, 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/retrooper/packetevents
- Repository: https://github.com/retrooper/packetevents

## Overview

##### Main Components and Modules
- Core API Module ("api"): At the heart of the project, this module contains the base interfaces, event classes, packet event management (like PacketEvents, EventManager, and various event types), protocol definitions, and utilities that support packet manipulation.
- Platform-Specific Wrappers: There are several modules that provide platform-specific integrations. For instance:
- bungeecord (for BungeeCord servers)
- fabric (for Fabric-based servers/clients)
- spigot (for Spigot/Bukkit)
- sponge (for Sponge)
- velocity (for Velocity)
These modules include specialized injectors (channel initializers, pipeline injectors), factory builders, handlers/decoders/encoders, and manager implementations tailored for each platform.
- Netty-Common Module ("netty-common"): This module wraps lower-level networking functionality based on Netty. It contains implementations for buffer operations, channel management, and integration with the high-performance networking layer.
- Build and Utility Modules:
- buildSrc contains custom Gradle plugins and tasks for versioning, mapping compression strategies, and build conventions.
- Patch tools and mappings files (under “patch” and “mappings”) support Minecraft protocol compatibility and registry integrations.

##### Relationships and Interactions
- At the center, the Core API (api module) provides the interfaces and abstract event types that are used and extended by platform-specific modules.
- Each platform-specific module (bungeecord, fabric, spigot, sponge, velocity) acts as an adapter. They rely on the API to capture events and then call into their own implementations (injectors, wrappers, manager classes) to integrate with the respective platform’s network and event frameworks.
- The Netty-common module offers the underlying networking layer that these platform modules may call to perform tasks like channel injection, byte buffer management, and packet encoding/decoding.
- BuildSrc and mapping/patche modules serve as supportive infrastructure. They are used during the build and packaging phase and sometimes for runtime mapping or protocol translation.

##### Architectural Patterns and Design Principles
- Modularity: The separation into distinct modules (API, platform wrappers, common Netty utilities) ensures that common functionality is shared while platform specifics are encapsulated.
- Abstraction and Adaptation: The API defines generic packet and event interfaces; each platform-specific module implements these abstractions to hook into the corresponding environment.
- Event-Driven Architecture: The design is based largely on dispatching events (such as packet receive/send events, login events, etc.). Components communicate through well-defined interfaces.
- Dependency Injection and Inversion of Control: The wrapper classes and injector components are designed to plug into a server’s networking pipeline, often reusing a common provider (via factories or builder patterns).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Source
    MSC("Minecraft Server/Client"):::external

    %% Platform-Specific Wrappers
    subgraph "Platform-Specific Wrappers"
        Bungee("BungeeCord Module"):::adapter
        Fabric("Fabric Module"):::adapter
        Spigot("Spigot Module"):::adapter
        Sponge("Sponge Module"):::adapter
        Velocity("Velocity Module"):::adapter
    end

    %% Core Modules
    subgraph "Core Modules"
        API("Core API Module"):::core
        NCommon("Netty-Common Module"):::core
    end

    %% Build & Mapping Infrastructure
    subgraph "Build & Mapping Infrastructure"
        BuildSrc("buildSrc"):::infrastructure
        PatchTools("Patch Tools"):::infrastructure
        Mappings("Mappings"):::infrastructure
    end

    %% Interactions from External to Platform Wrappers
    MSC -->|"triggers"| Bungee
    MSC -->|"triggers"| Fabric
    MSC -->|"triggers"| Spigot
    MSC -->|"triggers"| Sponge
    MSC -->|"triggers"| Velocity

    %% Platform Wrappers interactions with Core Modules
    Bungee -->|"implements"| API
    Fabric -->|"implements"| API
    Spigot -->|"implements"| API
    Sponge -->|"implements"| API
    Velocity -->|"implements"| API

    Bungee -->|"network"| NCommon
    Fabric -->|"network"| NCommon
    Spigot -->|"network"| NCommon
    Sponge -->|"network"| NCommon
    Velocity -->|"network"| NCommon

    %% Core API dependency on Netty-Common
    API -->|"relies_on"| NCommon

    %% Build & Infrastructure support to Core API
    BuildSrc ---|"build_support"| API
    PatchTools ---|"mapping_support"| API
    Mappings ---|"protocol_mapping"| API

    %% Click Events
    click API "https://github.com/retrooper/packetevents/tree/2.0/api"
    click Bungee "https://github.com/retrooper/packetevents/tree/2.0/bungeecord"
    click Fabric "https://github.com/retrooper/packetevents/tree/2.0/fabric"
    click Spigot "https://github.com/retrooper/packetevents/tree/2.0/spigot"
    click Sponge "https://github.com/retrooper/packetevents/tree/2.0/sponge"
    click Velocity "https://github.com/retrooper/packetevents/tree/2.0/velocity"
    click NCommon "https://github.com/retrooper/packetevents/tree/2.0/netty-common"
    click BuildSrc "https://github.com/retrooper/packetevents/tree/2.0/buildSrc"
    click PatchTools "https://github.com/retrooper/packetevents/tree/2.0/patch"
    click Mappings "https://github.com/retrooper/packetevents/tree/2.0/mappings"

    %% Class Definitions for styling
    classDef core fill:#81C784,stroke:#388E3C,stroke-width:2px;
    classDef adapter fill:#64B5F6,stroke:#1976D2,stroke-width:2px;
    classDef infrastructure fill:#E0E0E0,stroke:#9E9E9E,stroke-width:2px;
    classDef external fill:#FFCC80,stroke:#FB8C00,stroke-width:2px;
```
