# growthease/gamesentry architecture

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

## Overview

##### Project type and purpose
- GameSentry is an open-source, Node.js-based security-testing tool for mobile games.
- It provides a CLI entrypoint (index.js), a modular plugin system under lib/cli, a native “agent” injected into the target game process (lib/component), and a browser-based UI (res/templates + res/static).
- Core use cases: automatic Hooking, protocol extraction (e.g., Protobuf), Lua dumping/decompiling, function tracing, and hot-patching.

##### File structure
- Top-level:
- index.js – CLI server startup
- lib/cli/… – plugin modules (hook, log, protocol, dump, hotfix, etc.) + utils/constants/helper
- lib/component/… – Frida-agent code (agent API, filtering, tracer, structs definitions)
- lib/cocos/… – engine-specific adapters (cocos-js, cocos-lua)
- res/templates + res/static – HTML/CSS/JS for browser UI
- tools/lua/unluac.jar – external decompiler for Lua bytecode
- Patterns:
- Plugin architecture for extendability (each module under lib/cli/module)
- Client-server IPC between Node.js and in-process Frida agent
- MVC-style separation for UI (templates vs. static assets)

##### README for additional insights
- Describes supported game engines (unity il2cpp, cocos-js/lua), requirements (rooted device, no APK obfuscation).
- Points to detailed features (doc/Features.md) and usage instructions (doc/InstructionsForUse.md).
- Emphasizes extensibility and attacker-style analysis.

##### Summary of essential architectural elements
- Don’t over-fragment: group related modules under logical subsystems (Modules, Agent, UI).
- Communication flows (Frida IPC, HTTP).
- Engine adapters (lib/cocos) and extensibility points (module folder).
- Technology labels (Node.js, Frida, Lua, HTTP).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host machine boundary
    subgraph "Host Machine" 
        direction TB
        CLI_Core["CLI Core<br/>(index.js)"]:::host
        CLI_Core -->|loads modules| Module_Loader
        subgraph "CLI Modules"
            direction TB
            Module_base["Base Module"]:::host
            HookFunction["hook-function.js"]:::host
            HookLog["hook-log.js"]:::host
            StalkerTrace["stalker-trace.js"]:::host
            TraceModule["trace.js"]:::host
            ProtocolProto["protocol-protobuf.js"]:::host
            LuaDump["lua-dump.js"]:::host
            LuaHotfix["lua-hotfix.js"]:::host
            HotFixYiDun["HotFixYiDun.lua"]:::host
            FieldModule["field.js"]:::host
            Customize["customize.js"]:::host
            Show["show.js"]:::host
        end
        CLI_Core -->|uses utils| CLI_Utils
        subgraph "CLI Utilities"
            direction TB
            Constants["constants.js"]:::host
            Helper["helper.js"]:::host
            UtilsCLI["utils.js"]:::host
        end
        LuaDump -->|invokes| ExternalTool
        subgraph "External Tools"
            ExternalTool["unluac.jar"]:::ext
        end
        CLI_Core -->|serves UI| HTTPServer["HTTP Server"]:::host
        subgraph "Browser UI"
            direction TB
            Templates["Templates<br/>(HTML views)"]:::ui
            StaticJS["Static Assets<br/>(res/static/js)"]:::ui
        end
        HTTPServer -->|serves| Templates
        HTTPServer -->|serves| StaticJS
    end

    %% Mobile device boundary
    subgraph "Mobile Device" 
        direction TB
        subgraph "Frida Agent" 
            direction TB
            AgentIndex["agent/index.js"]:::agent
            AgentAPI["api.js"]:::agent
            AgentBase["base.js"]:::agent
            AgentRuntime["runtime.js"]:::agent
            AgentFiltering["filtering.js"]:::agent
            AgentTracer["tracer.js"]:::agent
            subgraph "Struct Definitions"
                Structs["structs/*"]:::agent
            end
            subgraph "Agent Utilities"
                AgentConsole["console.js"]:::agent
                AgentNativeStruct["native-struct.js"]:::agent
                AgentUtils["utils.js"]:::agent
            end
        end
        CocosAdapters["Cocos Adapters<br/>(cocos-js.js, cocos-lua.js)"]:::agent
        TargetProcess["Game Process"]:::device
        CLI_Core -->|injects via Frida| AgentIndex
        AgentIndex -->|runs in| TargetProcess
        AgentIndex -->|Frida RPC| CLI_Core
    end

    HTTPServer -->|HTTP| Browser["User Browser"]:::ui
    Browser -->|requests| HTTPServer

    %% Click events
    click CLI_Core "https://github.com/growthease/gamesentry/blob/main/index.js"
    click Module_base "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/base.js"
    click HookFunction "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/hook-function.js"
    click HookLog "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/hook-log.js"
    click StalkerTrace "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/stalker-trace.js"
    click TraceModule "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/trace.js"
    click ProtocolProto "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/protocol-protobuf.js"
    click LuaDump "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/lua-dump.js"
    click LuaHotfix "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/lua-hotfix.js"
    click HotFixYiDun "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/HotFixYiDun.lua"
    click FieldModule "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/field.js"
    click Customize "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/customize.js"
    click Show "https://github.com/growthease/gamesentry/blob/main/lib/cli/module/show.js"
    click Constants "https://github.com/growthease/gamesentry/blob/main/lib/cli/utils/constants.js"
    click Helper "https://github.com/growthease/gamesentry/blob/main/lib/cli/utils/helper.js"
    click UtilsCLI "https://github.com/growthease/gamesentry/blob/main/lib/cli/utils/utils.js"
    click ExternalTool "https://github.com/growthease/gamesentry/blob/main/tools/lua/unluac.jar"
    click Templates "https://github.com/growthease/gamesentry/blob/main/res/templates/main.html"
    click StaticJS "https://github.com/growthease/gamesentry/tree/main/res/static/js"
    click AgentIndex "https://github.com/growthease/gamesentry/blob/main/lib/component/agent/index.js"
    click AgentAPI "https://github.com/growthease/gamesentry/blob/main/lib/component/agent/api.js"
    click AgentBase "https://github.com/growthease/gamesentry/blob/main/lib/component/agent/base.js"
    click AgentRuntime "https://github.com/growthease/gamesentry/blob/main/lib/component/agent/runtime.js"
    click AgentFiltering "https://github.com/growthease/gamesentry/blob/main/lib/component/agent/filtering.js"
    click AgentTracer "https://github.com/growthease/gamesentry/blob/main/lib/component/agent/tracer.js"
    click Structs "https://github.com/growthease/gamesentry/tree/main/lib/component/agent/structs"
    click AgentConsole "https://github.com/growthease/gamesentry/blob/main/lib/component/utils/console.js"
    click AgentNativeStruct "https://github.com/growthease/gamesentry/blob/main/lib/component/utils/native-struct.js"
    click AgentUtils "https://github.com/growthease/gamesentry/blob/main/lib/component/utils/utils.js"
    click CocosAdapters "https://github.com/growthease/gamesentry/blob/main/lib/cocos/cocos-js.js"
    %% Styles
    classDef host fill:#D0E8FF,stroke:#1B4F72;
    classDef agent fill:#DFF2E1,stroke:#196F3D;
    classDef ext fill:#FDEBD0,stroke:#B9770E;
    classDef ui fill:#F3E5F5,stroke:#6C3483;
    classDef device fill:#E8DAEF,stroke:#62306D;
```
