# playpro/coreprotect architecture

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

- Interactive diagram: https://gitdiagram.com/playpro/coreprotect
- Repository: https://github.com/playpro/coreprotect

## Overview

##### Main Components

- Plugin Core & Initialization
- Plugin Initialization Service (services/PluginInitializationService.java) and ShutdownService, VersionCheckService, etc.

- API Layer
- Public API classes (e.g., CoreProtectAPI.java) that expose logging and lookup functionalities to server administrators and potentially to other plugins.
- API modules like BlockAPI, QueueLookup, and SessionLookup.

- Command Handling
- That these modules accept player/server commands and route them to the appropriate functionality.

- Listener and Event Subsystem
- Listener packages (net/coreprotect/listener) which cover block, entity, player, and world listeners, plus any auxiliary inspector modules.

- Consumer / Processing System
- Asynchronous/logging processing components that consume events. This includes the consumer package and its various process classes (e.g., BlockBreakProcess, PlayerChatProcess, etc.).
- How events captured by listeners are handed off to the consumer for processing and then logged to the database.

- Database Module
- Database layer which handles persistence. This module (in net/coreprotect/database) contains classes for logging, lookups, rollbacks, and statement preparation.
- Separate subcomponents: Logger (with various logger classes), Lookup, Rollback, and Statement creation. Indicate interactions where processed data is written to, read from, or rolled back from the database.

- Integrations & Adapters
- Adapters for different Minecraft server implementations – groups for Bukkit (net/coreprotect/bukkit), Spigot (net/coreprotect/spigot), and Paper (net/coreprotect/paper).
- Plugin Channel integrations (under listener/channel) and any external communication paths.

- Configuration & Localization
- Configuration management modules (net/coreprotect/config) which load and handle configuration files.
- Language/translation support (the lang/ directory and net/coreprotect/language package) for localization.

- Utility & Common Libraries
- A supporting layer for various utilities (under net/coreprotect/utility) that provide functionalities like string processing, version utilities, database utilities, etc.

##### Relationships and Interactions

- Plugin Core initializes and interacts with API, Command Handlers, and Listener modules.
- Listeners capture events from the Minecraft server environment (via Bukkit/Spigot/Paper) and pass them to the Consumer.
- The Consumer processes these events and uses the Database module to log data.
- The API layer can offer read operations that may invoke lookups in the Database module, and rollback operations where needed.
- Configuration and Localization modules serve as dependencies that supply runtime configuration data and multi-language support to almost all components.

- Asynchronous communication within the Consumer to avoid blocking the main server thread.

##### Important Architectural Patterns & Design Principles

- Layered Architecture: Show clear segregation between presentation (event listeners, command handling), processing (consumer/queue handling), data access (database modules), and cross-cutting concerns (configuration, language, utilities).

- Adapter Pattern: Particularly in the integration with Bukkit, Spigot, and Paper – each adapter abstracts differences in Minecraft server implementations.

- Modular Design: Each package/subsystem (listeners, commands, database, processors) represents a dedicated module, promoting separation of concerns and maintainability.

##### Final Steps

- That every major function—from the reception of player commands or server events, through processing and logging, to data lookup and rollback—is represented.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Plugin Core & Services
    subgraph "Plugin Core & Services"
        PC["Plugin Core (CoreProtect.java)"]:::core
        PI["Plugin Initialization Service"]:::core
        SS["Shutdown Service"]:::core
        VC["Version Check Service"]:::core
    end

    %% API Layer
    subgraph "API Layer"
        API["Core Protect API"]:::api
        BA["Block API"]:::api
        QL["Queue Lookup"]:::api
        SL["Session Lookup"]:::api
    end

    %% Command Handling
    subgraph "Command Handling"
        CH["Command Handler"]:::command
        CC["Command Classes"]:::command
        CP["Command Parsers"]:::command
        LT["Lookup Threads"]:::command
    end

    %% Listener & Event Subsystem
    subgraph "Listener & Event Subsystem"
        LH["Listener Handler"]:::listener
        BL["Block Listeners"]:::listener
        EL["Entity Listeners"]:::listener
        PL["Player Listeners"]:::listener
        WL["World Listeners"]:::listener
        PCL["Plugin Channel Listeners"]:::listener
    end

    %% Consumer / Processing
    subgraph "Consumer / Processing"
        CON["Consumer"]:::consumer
        QM["Queue Management"]:::consumer
        PM["Processing Modules"]:::consumer
    end

    %% Database Module
    subgraph "Database Module"
        DB["Database Core"]:::database
        DL["Lookup Module"]:::database
        LG["Logger Module"]:::database
        RB["Rollback Module"]:::database
        SP["Statement Preparer"]:::database
    end

    %% Integrations & Adapters
    subgraph "Integrations & Adapters"
        BAda["Bukkit Adapter"]:::integration
        SInt["Spigot Integration"]:::integration
        PInt["Paper Integration"]:::integration
    end

    %% Configuration & Localization
    subgraph "Configuration & Localization"
        CM["Configuration Management"]:::config
        LS["Language Support"]:::config
        LR["Language Resources"]:::config
    end

    %% Utility & Common Libraries
    subgraph "Utility & Common Libraries"
        UL["Utility Libraries"]:::utility
    end

    %% Connections Between Core Components
    PC -->|"initializes"| PI
    PC -->|"manages"| SS
    PC -->|"manages"| VC
    PC -->|"exposes"| API
    PC -->|"registers"| CH
    PC -->|"registers"| LH
    PC -->|"loads"| CM

    %% API Layer Interactions
    API -->|"utilizes"| BA
    API -->|"utilizes"| QL
    API -->|"utilizes"| SL
    API -->|"queries"| DL

    %% Command Handling Interactions
    CH -->|"routes"| CC
    CH -->|"parses"| CP
    CH -->|"initiates"| LT

    %% Listener & Event Subsystem Interactions
    LH -->|"captures"| BL
    LH -->|"captures"| EL
    LH -->|"captures"| PL
    LH -->|"captures"| WL
    LH -->|"captures"| PCL
    LH -->|"forwardsEvent"| CON

    %% Consumer / Processing Interactions
    CON -->|"manages"| QM
    CON -->|"processes"| PM
    PM -->|"logsData"| DB

    %% Database Module Interactions
    DB -->|"lookup"| DL
    DB -->|"logs"| LG
    DB -->|"rollbacks"| RB
    DB -->|"prepares"| SP

    %% Integrations & Adapters Interactions
    BAda -->|"adaptsFor"| LH
    SInt -->|"adaptsFor"| LH
    PInt -->|"adaptsFor"| LH

    %% Configuration & Localization Interactions
    LS -->|"supports"| API
    LS -->|"supports"| CH
    LS -->|"supports"| LH
    LR -->|"suppliesLanguages"| LS

    %% Utility & Common Libraries Interaction
    UL -->|"assists"| PC

    %% Class Definitions for Colors
    classDef core fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef api fill:#ADD8E6,stroke:#4682B4,stroke-width:2px;
    classDef command fill:#90EE90,stroke:#228B22,stroke-width:2px;
    classDef listener fill:#F08080,stroke:#CD5C5C,stroke-width:2px;
    classDef consumer fill:#9ACD32,stroke:#556B2F,stroke-width:2px;
    classDef database fill:#E0FFFF,stroke:#20B2AA,stroke-width:2px;
    classDef integration fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef config fill:#D3D3D3,stroke:#A9A9A9,stroke-width:2px;
    classDef utility fill:#FFA07A,stroke:#FF4500,stroke-width:2px;

    %% Click Events
    click PC "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/CoreProtect.java"
    click PI "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/services/PluginInitializationService.java"
    click SS "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/services/ShutdownService.java"
    click VC "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/services/VersionCheckService.java"

    click API "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/CoreProtectAPI.java"
    click BA "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/api/BlockAPI.java"
    click QL "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/api/QueueLookup.java"
    click SL "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/api/SessionLookup.java"

    click CH "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/command/CommandHandler.java"
    click CC "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/command/"
    click CP "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/command/parser/"
    click LT "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/command/lookup/"

    click LH "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/listener/ListenerHandler.java"
    click BL "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/listener/block/"
    click EL "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/listener/entity/"
    click PL "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/listener/player/"
    click WL "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/listener/world/"
    click PCL "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/listener/channel/"

    click CON "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/consumer/Consumer.java"
    click QM "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/consumer/Queue.java"
    click PM "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/consumer/process/"

    click DB "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/database/Database.java"
    click DL "https://github.com/playpro/coreprotect/blob/master/src/main/java/net/coreprotect/database/Lookup.java"
    click LG "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/database/logger/"
    click RB "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/database/rollback/"
    click SP "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/database/statement/"

    click BAda "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/bukkit/"
    click SInt "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/spigot/"
    click PInt "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/paper/"

    click CM "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/config/"
    click LS "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/language/"
    click LR "https://github.com/playpro/coreprotect/tree/master/lang/"

    click UL "https://github.com/playpro/coreprotect/tree/master/src/main/java/net/coreprotect/utility/"
```
