# eaglerforge/eaglerforgeinjector architecture

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

- Interactive diagram: https://gitdiagram.com/eaglerforge/eaglerforgeinjector
- Repository: https://github.com/eaglerforge/eaglerforgeinjector

## Overview

#### Purpose and Inputs
EaglerForgeInjector transforms compatible EaglercraftX offline builds into runtime-modifiable builds. It pattern-matches unminified, unobfuscated, unsigned client/server JavaScript, injects hooks and a core ModAPI runtime, and can package/minify the result. Primary user entry points are the browser uploader in `index.html`, Node CLI in `cli.js`, and package wrapper in `npx_wrapper.js`.

#### Invocation Surfaces
Browser execution is coordinated by `browser.js`, with `index.html` providing the offline/hosted UI. CLI execution starts in `cli.js`; it is intended for larger builds and transformation/minification workflows that exceed browser memory limits. `backgroundLogger.js` supports progress/logging behavior across these execution contexts.

#### Transformation Pipeline
`core/core.js` is the central injector/orchestrator: it consumes an Eaglercraft build, locates known structural patterns, and applies rewrite stages. `core/patches.js` contains the architecture-critical patch definitions that introduce interception points into target code. `core/minify.js` is the output optimization boundary, used when producing compact transformed artifacts.

#### Runtime Bootstrap and ModAPI
The injected runtime is centered on `core/postinit.js`, which initializes the global `ModAPI` after the target application is available. This separates static source rewriting from runtime extension: the injector adds stable access points, while mods use ModAPI to hook or alter live Eaglercraft behavior.

#### Extension, Hooking, and Reflection
`core/modloader.js` loads mod scripts into the injected environment. `core/core.js` and `core/postinit.js` jointly expose the runtime-facing API needed for monkey patching, method hooks, reflection, and custom classes. Example consumers under `examplemods/` demonstrate the expected mod boundary; they are separate payloads rather than part of the injector core.

#### Dedicated Server and UI Integration
`core/efserver.js` handles dedicated-server-specific modification paths, extending the same injection model beyond the browser client. `core/modgui.js` provides the in-game or injected mod-management UI layer, keeping user-facing mod controls distinct from source transformation and runtime loading.

#### Outputs and External Boundaries
The system operates entirely on user-supplied Eaglercraft download artifacts and local JavaScript modules; no backend service is required for core operation. Browser usage depends on file upload/browser runtime constraints, while CLI/NPX usage depends on Node.js and dependencies declared in `package.json` and locked in `package-lock.json`. Documentation of the exposed API and intended extension contracts lives in `docs/apidoc/` and `docs/architecture.md`.

Main entry points: [`core/core.js`](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/core.js) (Injector orchestrator), [`cli.js`](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/cli.js) (Node CLI), [`browser.js`](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/browser.js) (Browser coordinator), [`core/postinit.js`](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/postinit.js) (ModAPI bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Invocation surfaces"]
  node_browser_ui["Browser uploader UI<br/>web entry<br/>[index.html]"]
  node_browser_runner["Browser coordinator<br/>browser runtime<br/>[browser.js]"]
  node_cli["Node CLI<br/>CLI entry<br/>[cli.js]"]
  node_npx_wrapper["NPX wrapper<br/>package entry<br/>[npx_wrapper.js]"]
  node_logger["Progress logger<br/>shared support"]
end

subgraph group_injector["Injection pipeline"]
  node_core{{"Injector orchestrator<br/>transformation engine<br/>[core.js]"}}
  node_patches["Patch definitions<br/>rewrite rules<br/>[patches.js]"]
  node_server_injector["Server injection path<br/>server transformer<br/>[efserver.js]"]
  node_minifier["Output minifier<br/>optimization stage<br/>[minify.js]"]
end

subgraph group_runtime["Injected runtime"]
  node_bootstrap{{"ModAPI bootstrap<br/>injected runtime<br/>[postinit.js]"}}
  node_modloader["Mod script loader<br/>runtime loader<br/>[modloader.js]"]
  node_modgui["Mod management UI<br/>injected UI<br/>[modgui.js]"]
end

subgraph group_extensions["Extension boundary"]
  node_mods["Example mod payloads<br/>mod scripts"]
  node_api_docs["API documentation<br/>extension contract"]
  node_architecture_docs["Architecture guide<br/>documentation<br/>[architecture.md]"]
end

node_input_build["Eaglercraft build<br/>user artifact"]
node_transformed_build["Transformed artifact<br/>output artifact"]
node_node_deps["Node dependencies<br/>package dependencies<br/>[package.json]"]

node_browser_ui -->|"starts"| node_browser_runner
node_browser_runner -->|"invokes"| node_core
node_cli -->|"invokes"| node_core
node_npx_wrapper -->|"wraps"| node_cli
node_browser_runner -.->|"reports through"| node_logger
node_cli -.->|"reports through"| node_logger
node_input_build -->|"input"| node_core
node_core -->|"uses"| node_patches
node_core -->|"routes server builds"| node_server_injector
node_core -->|"injects"| node_bootstrap
node_core -->|"injects"| node_modloader
node_core -->|"injects"| node_modgui
node_core -->|"optionally optimizes"| node_minifier
node_minifier -->|"emits"| node_transformed_build
node_core -.->|"emits unminified"| node_transformed_build
node_bootstrap -->|"initializes runtime for"| node_modloader
node_modloader -->|"loads"| node_mods
node_mods -->|"uses ModAPI hooks"| node_bootstrap
node_api_docs -.->|"documents contract"| node_mods
node_node_deps -.->|"supports"| node_cli
node_node_deps -.->|"supports"| node_npx_wrapper

click node_browser_ui "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/index.html"
click node_browser_runner "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/browser.js"
click node_cli "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/cli.js"
click node_npx_wrapper "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/npx_wrapper.js"
click node_logger "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/backgroundLogger.js"
click node_core "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/core.js"
click node_patches "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/patches.js"
click node_server_injector "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/efserver.js"
click node_minifier "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/minify.js"
click node_bootstrap "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/postinit.js"
click node_modloader "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/modloader.js"
click node_modgui "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/modgui.js"
click node_architecture_docs "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/docs/architecture.md"
click node_node_deps "https://github.com/eaglerforge/eaglerforgeinjector/blob/main/package.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser_ui,node_browser_runner,node_cli,node_npx_wrapper,node_logger toneBlue
class node_core,node_patches,node_server_injector,node_minifier toneAmber
class node_bootstrap,node_modloader,node_modgui toneMint
class node_mods,node_api_docs,node_architecture_docs toneRose
class node_input_build,node_transformed_build,node_node_deps toneNeutral
```

## Components

### Invocation surfaces

- [Browser uploader UI](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/index.html): web entry · Offline or hosted upload interface. · `index.html`
- [Browser coordinator](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/browser.js): browser runtime · `browser.js`
- [Node CLI](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/cli.js): CLI entry · Handles larger transformation and minification workflows. · `cli.js`
- [NPX wrapper](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/npx_wrapper.js): package entry · `npx_wrapper.js`
- [Progress logger](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/backgroundLogger.js): shared support · `backgroundLogger.js`

### Injection pipeline

- [Injector orchestrator](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/core.js): transformation engine · Finds known structures and applies rewrite stages. · `core/core.js`
- [Patch definitions](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/patches.js): rewrite rules · Defines interception points inserted into target code. · `core/patches.js`
- [Server injection path](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/efserver.js): server transformer · `core/efserver.js`
- [Output minifier](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/minify.js): optimization stage · `core/minify.js`

### Injected runtime

- [ModAPI bootstrap](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/postinit.js): injected runtime · Initializes global ModAPI after the target application is available. · `core/postinit.js`
- [Mod script loader](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/modloader.js): runtime loader · `core/modloader.js`
- [Mod management UI](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/core/modgui.js): injected UI · `core/modgui.js`

### Extension boundary

- **Example mod payloads**: mod scripts · Separate consumers of the injected extension contract.
- **API documentation**: extension contract
- [Architecture guide](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/docs/architecture.md): documentation · `docs/architecture.md`

### Other components

- **Eaglercraft build**: user artifact · Compatible unsigned, unobfuscated client or server JavaScript.
- **Transformed artifact**: output artifact · Runtime-modifiable client or server build.
- [Node dependencies](https://github.com/eaglerforge/eaglerforgeinjector/blob/main/package.json): package dependencies · Required by CLI and NPX execution. · `package.json`

## Connections

- Browser uploader UI → Browser coordinator: starts
- Browser coordinator → Injector orchestrator: invokes
- Node CLI → Injector orchestrator: invokes
- NPX wrapper → Node CLI: wraps
- Browser coordinator → Progress logger: reports through
- Node CLI → Progress logger: reports through
- Eaglercraft build → Injector orchestrator: input
- Injector orchestrator → Patch definitions: uses
- Injector orchestrator → Server injection path: routes server builds
- Injector orchestrator → ModAPI bootstrap: injects
- Injector orchestrator → Mod script loader: injects
- Injector orchestrator → Mod management UI: injects
- Injector orchestrator → Output minifier: optionally optimizes
- Output minifier → Transformed artifact: emits
- Injector orchestrator → Transformed artifact: emits unminified
- ModAPI bootstrap → Mod script loader: initializes runtime for
- Mod script loader → Example mod payloads: loads
- Example mod payloads → ModAPI bootstrap: uses ModAPI hooks
- API documentation → Example mod payloads: documents contract
- Node dependencies → Node CLI: supports
- Node dependencies → NPX wrapper: supports
