# skidamek/automodpack architecture

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

- Interactive diagram: https://gitdiagram.com/skidamek/automodpack
- Repository: https://github.com/skidamek/automodpack

## Overview

##### Project type and purpose
- This is a Minecraft “mod” project named AutoModpack with three main parts:
- A **core library** (`core/`) that implements the modpack metadata generator, Netty-based file-transfer server, protocol messages, and direct-download services (Modrinth/CurseForge).
- A **loader library** (`loader/`) that contains a standalone GUI/updater/relauncher and multiple platform adapters (Fabric, Forge, NeoForge) that bootstrap the core on the client.
- The **mod module** (`src/`) which contains the actual Minecraft mod entrypoints for server & client, mixins for injecting into vanilla/Fabric/Forge, the in-game UI screens, and the custom networking hooks.

##### High-level file-structure analysis
- Top-level directories:
- `.github/`, CI workflows (build/test/release)
- `core/` – the pure-Java automodpack core library
- `loader/` – GUI and platform-loader adapters (Fabric/Forge/NeoForge)
- `src/` – the actual Minecraft mod (entrypoints, mixins, UI, networking)
- `versions/` – Gradle property overrides for different Minecraft versions
- Patterns & notable files:
- **Modular Gradle multi-project** using `settings.gradle.kts`
- **Protocol** in `core/src/main/java/.../protocol/netty` (NettyServer, handlers, messages)
- **LoaderManagerService**, `ModpackLoaderService`, `DownloadClient` in core
- **Mixins** under `src/main/java/.../mixin` for injecting handshake logic into Minecraft’s login/network classes.

##### Key insights from the README
- The mod **generates** a server-side metadata file listing all modpack files.
- On client connect, the mod uses **secure Netty channels** and Minecraft’s login hooks to tell the client where to fetch that metadata.
- The client then pulls files **directly** from CurseForge/Modrinth APIs or through the embedded Netty server on the server.
- Supports **automatic background updating** on subsequent boots.

##### Main components
a. **Server-side components**
- Minecraft Server with AutoModpack mod (entrypoint classes in `src/.../init/`)
- Core NettyServer (hosts metadata + file streams)
- Metadata generator (`ModpackContent`, `ModpackExecutor`)
b. **Client-side components**
- Minecraft Client with AutoModpack mod (init + mixins + UI screens in `src/.../client` & `src/.../ui`)
- Loader core (`LoaderManagerService`, `GameCallService`) invoked via Fabric/Forge adapter
- Netty client (`DownloadClient`) to connect back to the server’s NettyServer
- Direct-download managers (`ModrinthAPI`, `CurseForgeAPI`)
- Local file system storage (client’s `.automodpack` folder)
c. **External services**
- Modrinth API
- CurseForge API
d. **Platform adapters**
- Fabric adapter (`loader/fabric/...`)
- Forge adapter (`loader/forge/...`)
- NeoForge adapter (`loader/neoforge/...`)

##### Relationships & data flows
1. **Minecraft login handshake** (client ⇄ server)
- Server mod intercepts login, generates metadata, and sends metadata URL + auth via custom packet.
- Client mixin intercepts that custom packet.
2. **Client fetch phase**
- Client’s `DownloadClient` (Netty) ↔ Server’s `NettyServer` to pull any files not available on CurseForge/Modrinth.
- Concurrently, `ModrinthAPI`/`CurseForgeAPI` direct downloads for known mod IDs.
- Files saved under local automodpack folder.
3. **Game restart or reload**
- Client instructs Minecraft to reload mods (via relaunch or dynamic loading).

##### Architectural patterns & design principles
- **Separation of concerns**: core library is platform-agnostic; loader adapters handle platform bootstrapping; mod module handles in-game integration.
- **Plugin/adapter pattern**: multiple adapter modules for different mod loaders.
- **Protocol abstraction**: custom Netty protocol messages for file requests & responses.
- **Mixin injection**: minimal invasive hooks into Minecraft’s networking stack.
- **Multi-project Gradle**: clean modular build & version management.

##### Elements
- Blue = server components
- Green = client components
- Orange = external services/APIs
- Clouds for external APIs
- Rectangles for modules/services

##### Final advice
- Call out critical security boundary: trust domain between server-hosted files and client.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Server Side
    subgraph "Server Side"
        direction TB
        MS["Minecraft Server<br/>(AutoModpack Mod)"]:::server
        NS["NettyServer"]:::server
        MG["Metadata Generator<br/>(ModpackContent)"]:::server
        ME["Metadata Executor<br/>(ModpackExecutor)"]:::server
        MF["Metadata File"]:::storage

        MS -->|1: handshake trigger| MG
        MG --> ME
        ME --> MF
        MS -->|hosts file streams| NS
    end

    %% Client Side
    subgraph "Client Side"
        direction TB
        MC["Minecraft Client<br/>(AutoModpack Mod)"]:::client
        MK["Mixins & Hooks"]:::client
        UI["Client UI Screens"]:::client
        DL["DownloadClient"]:::client
        LMS["LoaderManagerService"]:::client
        MLS["ModpackLoaderService"]:::client
        GCS["GameCallService"]:::client
        LS["Local Storage<br/>(.automodpack)"]:::storage

        MC -->|1: custom packet| MK
        MK -->|2: start fetch| DL
        MK --> LMS
        LMS --> MLS
        MLS --> DL
        DL -->|fetch missing files| NS
        DL --> LS
        MLS -->|invoke restart| GCS
        GCS --> MC
        MC --> UI
    end

    %% External Services
    subgraph "External Services"
        direction TB
        MR["ModrinthAPI"]:::external
        CF["CurseForgeAPI"]:::external
    end

    DL -->|2: direct download| MR
    DL -->|2: direct download| CF
    MR --> LS
    CF --> LS

    %% Platform Adapters (dashed)
    subgraph "Platform Adapters" 
        direction TB
        FA["Fabric Adapter"] 
        FO["Forge Adapter"] 
        NF["NeoForge Adapter"] 
    end
    FA -.-> LMS
    FO -.-> LMS
    NF -.-> LMS

    %% Click events
    click NS "https://github.com/skidamek/automodpack/blob/main/core/src/main/java/pl/skidam/automodpack_core/protocol/netty/NettyServer.java"
    click DL "https://github.com/skidamek/automodpack/blob/main/core/src/main/java/pl/skidam/automodpack_core/protocol/DownloadClient.java"
    click MG "https://github.com/skidamek/automodpack/blob/main/core/src/main/java/pl/skidam/automodpack_core/modpack/ModpackContent.java"
    click ME "https://github.com/skidamek/automodpack/blob/main/core/src/main/java/pl/skidam/automodpack_core/modpack/ModpackExecutor.java"
    click LMS "https://github.com/skidamek/automodpack/blob/main/core/src/main/java/pl/skidam/automodpack_core/loader/LoaderManagerService.java"
    click MLS "https://github.com/skidamek/automodpack/blob/main/core/src/main/java/pl/skidam/automodpack_core/loader/ModpackLoaderService.java"
    click GCS "https://github.com/skidamek/automodpack/blob/main/core/src/main/java/pl/skidam/automodpack_core/loader/GameCallService.java"
    click FA "https://github.com/skidamek/automodpack/blob/main/loader/fabric/core/src/main/java/pl/skidam/automodpack_loader_core_fabric/loader/LoaderManager.java"
    click FO "https://github.com/skidamek/automodpack/blob/main/loader/forge/fml47/src/main/java/pl/skidam/automodpack_loader_core_forge/loader/LoaderManager.java"
    click NF "https://github.com/skidamek/automodpack/blob/main/loader/neoforge/fml4/src/main/java/pl/skidam/automodpack_loader_core_neoforge/loader/LoaderManager.java"
    click MS "https://github.com/skidamek/automodpack/blob/main/src/main/java/pl/skidam/automodpack/init/FabricInit.java"
    click MS "https://github.com/skidamek/automodpack/blob/main/src/main/java/pl/skidam/automodpack/init/ForgeInit.java"
    click MS "https://github.com/skidamek/automodpack/blob/main/src/main/java/pl/skidam/automodpack/init/NeoForgeInit.java"
    click FA "https://github.com/skidamek/automodpack/blob/main/loader/fabric/core/src/main/resources/fabric.mod.json"
    click FO "https://github.com/skidamek/automodpack/blob/main/loader/forge/fml47/src/main/resources/META-INF/mods.toml"
    click NF "https://github.com/skidamek/automodpack/blob/main/loader/neoforge/fml4/src/main/resources/META-INF/neoforge.mods.toml"

    %% Styles
    classDef server fill:#cce5ff,stroke:#3399ff
    classDef client fill:#d4edda,stroke:#28a745
    classDef external fill:#fff3cd,stroke:#ffcc00
    classDef storage fill:#e2e3e5,stroke:#adb5bd,stroke-dasharray: 5 5
```
