# acceptmediocrity/gzzd architecture

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

- Interactive diagram: https://gitdiagram.com/acceptmediocrity/gzzd
- Repository: https://github.com/acceptmediocrity/gzzd

## Overview

1. **What this repository is**
   - This is a Java-based remote diagnosis platform, adapted into a **single-node/standalone deployment** from the original gzzd project.
   - The system lets an operator open a browser UI, connect to a running Java process via an agent, and perform live operations such as **debugging, thread/CPU inspection, heap histogram, file download, monitoring, and profiling**.

2. **Top-level module boundaries**
   - `common`: shared wire protocol, command DTOs, crypto, and utility code used by both client and server.
   - `clientside`: the agent/runtime installed alongside target JVMs; it executes commands and collects data.
   - `attach`: bytecode instrumentation and attach-time tooling, including Arthas-based shell support and custom agent/instrumentation logic.
   - `serverside`: the operator-facing backend, UI, proxy, persistence, and application registry logic.

3. **Operator-facing entry point**
   - `serverside/serverside-ui` is the main runtime in standalone mode.
   - It contains:
     - Spring MVC controllers for web/API endpoints.
     - A Netty-based proxy layer for long-lived agent/UI communication.
     - Static HTML/JS assets for pages like application view, machine view, monitor, profiler, console, and download.
   - The README indicates this is started as a single jar, accessed on **port 9091** by default.

4. **Proxy layer as the central hub**
   - The most important runtime boundary is `serverside-ui/proxy/communicate`.
   - It manages two sides:
     - **UI connections** from browser sessions.
     - **Agent connections** from deployed client agents.
   - Requests from the UI are translated into command messages, routed through the proxy, sent to the relevant agent, and the response is streamed back to the browser.

5. **Agent-side execution model**
   - `clientside/clientside-agent` is the JVM-side daemon.
   - It maintains:
     - Heartbeats and agent info refresh.
     - Command/task execution.
     - Netty client connectivity back to the server.
   - Task factories under `clientside-agent/task/*` implement concrete operations such as CPU jstack, heap histogram, monitor reporting, profiler file cleanup, and process inspection.

6. **Command protocol and shared message types**
   - `common/remoting` defines the protocol:
     - command codes, request/response envelopes, payload holders, encoders/decoders.
   - `common/remoting/command` contains the logical operations the system supports:
     - thread info, thread count, CPU time, heap histogram, decompiler, download, monitor, machine, profiler, etc.
   - This shared layer is what keeps the browser-facing server, proxy, and agent in sync.

7. **Instrumentation and live debugging subsystem**
   - `attach/instrument` is the bytecode/instrumentation stack.
   - It includes:
     - `instrument-client`: debugger, monitor, profiler, classpath/location discovery, Spring-expression support, and bytecode transformers.
     - `instrument-agent`: bootstrap and classloader support for attaching into target JVMs.
     - `instrument-spy`: async-profiler bridge and spying hooks.
     - `magic-classes` / `magic-loader`: special classloading and shaded helper classes used to make instrumentation work in hostile classloader environments.
   - This subsystem is what enables **live code-level inspection and instrumentation** inside the target JVM.

8. **Arthas integration**
   - `attach/attach-arthas` embeds Arthas shell support and command packs.
   - It adds commands for agent info, config, debug, jar info, monitoring, profiler control, shutdown/stop, and shell server startup.
   - In architecture terms, this is an alternate attach/debug execution path that complements the custom instrument client.

9. **Profiler workflow**
   - Profiling is handled end-to-end across server, agent, and attach layers.
   - Server-side profiler controllers and services issue start/stop/state commands.
   - Agent-side profiler tasks collect and store profiler data.
   - The `clientside-decompiler-fernflower` module provides decompilation support for viewing source-like output from bytecode when needed.

10. **File and artifact handling**
    - `attach/attach-common` and several server/client modules provide file service utilities.
    - These support:
      - jar storage and lookup,
      - downloaded artifacts,
      - snapshot/cache management,
      - profiler output files,
      - and other temporary result payloads.
    - The server also serves static frontend assets and downloadable binaries such as `agent-bin.tgz`.

11. **Application registry / environment management**
    - `serverside/serverside-application` provides an application metadata boundary.
    - It includes:
      - API interfaces for applications and app servers,
      - a Kubernetes-backed implementation (`serverside-application-k8s`),
      - and DAO/service layers for managing application-to-server relationships.
    - In the standalone setup this is auxiliary, but it defines how the platform resolves which target app/server an operator wants to inspect.

12. **Persistence, config, and security**
    - `serverside-common` contains shared server infrastructure:
      - dynamic config loading,
      - encryption utilities,
      - JDBC/H2 helpers,
      - ZK client abstractions,
      - metrics wrappers,
      - and file-store utilities.
    - The server side uses encryption for private tokens and request security, plus local or external config sources depending on deployment mode.
    - The README notes first-time login uses **admin / 123456**.

13. **Standalone deployment shape**
    - The repo is designed to run without the original distributed infrastructure in standalone mode.
    - The README and scripts indicate you deploy the `serverside-ui.jar` plus `start-all-stand-alone.sh`, then start/stop by application name.
    - The documented ports suggest three distinct roles can be co-located on one host:
      - UI access on `9091`,
      - agent/debug communication on `9013`,
      - and an additional gateway/control port on `9014`.

14. **How data moves through the system**
    - Browser requests enter `serverside-ui` controllers.
    - Controllers call services that build command requests.
    - The proxy layer selects the agent connection and forwards the command.
    - The agent executes the task locally against the target JVM or OS process.
    - Results stream back through the same proxy path and are rendered in the UI, sometimes as files, sometimes as structured JSON, and sometimes as live console output.

Main entry points: [`clientside/clientside-command/src/main/java/qunar/tc/bistoury/commands`](https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-command/src/main/java/qunar/tc/bistoury/commands) (Client Commands), [`serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate`](https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate) (Proxy Hub), [`serverside/serverside-ui/src/main/java/qunar/tc/bistoury/ui/controller`](https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/ui/controller) (Web APIs), [`attach/instrument/instrument-client/src/main/java/qunar/tc/bistoury/instrument/client`](https://github.com/acceptmediocrity/gzzd/tree/main/attach/instrument/instrument-client/src/main/java/qunar/tc/bistoury/instrument/client) (Instrument Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_common["Common"]
  node_common_protocol["Remoting<br/>protocol"]
  node_common_core["Core Utils<br/>shared-utils"]
  node_common_profiler["Profiler Core<br/>shared-profiler"]
end

subgraph group_group_clientside["Clientside"]
  node_client_agent(("Agent Runtime<br/>agent-daemon"))
  node_client_tasks["Agent Tasks<br/>task-executors"]
  node_client_common["Agent Common<br/>agent-support"]
  node_client_commands["Client Commands<br/>command-pack"]
  node_client_decompiler["Decompiler<br/>fernflower"]
end

subgraph group_group_attach["Attach"]
  node_attach_bootstrap["Bootstrap<br/>attach-agent"]
  node_attach_client["Instrument Client<br/>instrumentation"]
  node_attach_spy["Spy Bridge<br/>async-profiler-bridge"]
  node_attach_magic["Magic Classes<br/>classloading-aid"]
  node_attach_arthas["Arthas Shell<br/>arthas-integration"]
  node_attach_common["Attach File<br/>file-service"]
end

subgraph group_group_serverside["Serverside"]
  node_server_ui(("Serverside UI<br/>standalone-app"))
  node_server_proxy["Proxy Hub<br/>netty-proxy"]
  node_server_ui_handlers["UI Handlers<br/>ui-command-routing"]
  node_server_agent_handlers["Agent Handlers<br/>agent-message-routing"]
  node_server_profiler["Profiler Service<br/>profiler-workflow"]
  node_server_web["Web APIs<br/>spring-mvc"]
  node_server_persistence["Persistence<br/>db-config-security"]
  node_server_app_registry["App Registry<br/>application-metadata"]
end

node_common_protocol -->|"messages"| node_server_proxy
node_common_protocol -->|"codec"| node_client_common
node_common_core -->|"helpers"| node_server_persistence
node_common_core -->|"utils"| node_server_web
node_common_profiler -->|"data model"| node_server_profiler
node_common_profiler -->|"profile data"| node_client_commands
node_server_ui -->|"hosts"| node_server_web
node_server_ui -->|"embeds"| node_server_proxy
node_server_web -->|"dispatches"| node_server_proxy
node_server_web -->|"resolves apps"| node_server_app_registry
node_server_web -->|"stores users"| node_server_persistence
node_server_proxy -->|"routes ui"| node_server_ui_handlers
node_server_proxy -->|"routes agent"| node_server_agent_handlers
node_server_ui_handlers -->|"issues commands"| node_client_commands
node_server_ui_handlers -->|"profiler control"| node_server_profiler
node_server_agent_handlers -->|"connects to"| node_client_agent
node_client_agent -->|"executes"| node_client_tasks
node_client_tasks -->|"implements"| node_client_commands
node_client_agent -->|"uses"| node_client_common
node_client_commands -->|"alternate path"| node_attach_arthas
node_client_commands -->|"instrumentation"| node_attach_client
node_attach_bootstrap -->|"boots"| node_attach_client
node_attach_client -->|"profiles"| node_attach_spy
node_attach_client -->|"loads"| node_attach_magic
node_attach_common -->|"files"| node_attach_arthas
node_server_profiler -->|"streams"| node_server_proxy
node_client_decompiler -->|"supports"| node_client_commands

click node_common_protocol "https://github.com/acceptmediocrity/gzzd/tree/main/common/src/main/java/qunar/tc/bistoury/remoting"
click node_common_core "https://github.com/acceptmediocrity/gzzd/tree/main/common/src/main/java/qunar/tc/bistoury/common"
click node_common_profiler "https://github.com/acceptmediocrity/gzzd/tree/main/common/src/main/java/qunar/tc/bistoury/common/profiler"
click node_client_agent "https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-agent/src/main/java/qunar/tc/bistoury/agent"
click node_client_tasks "https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-agent/src/main/java/qunar/tc/bistoury/agent/task"
click node_client_common "https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-agent-common/src/main/java/qunar/tc/bistoury/agent/common"
click node_client_commands "https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-command/src/main/java/qunar/tc/bistoury/commands"
click node_client_decompiler "https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-decompiler-fernflower/src/main/java/qunar/tc/decompiler"
click node_attach_bootstrap "https://github.com/acceptmediocrity/gzzd/tree/main/attach/instrument/instrument-agent/src/main/java/qunar/tc/bistoury/instrument/agent"
click node_attach_client "https://github.com/acceptmediocrity/gzzd/tree/main/attach/instrument/instrument-client/src/main/java/qunar/tc/bistoury/instrument/client"
click node_attach_spy "https://github.com/acceptmediocrity/gzzd/tree/main/attach/instrument/instrument-spy/src/main/java/qunar/tc/bistoury/instrument/spy"
click node_attach_magic "https://github.com/acceptmediocrity/gzzd/tree/main/attach/instrument/magic-classes/src/main/java/qunar/tc/bistoury/magic/classes"
click node_attach_arthas "https://github.com/acceptmediocrity/gzzd/tree/main/attach/attach-arthas/src/main/java/qunar/tc/bistoury/attach/arthas"
click node_attach_common "https://github.com/acceptmediocrity/gzzd/tree/main/attach/attach-common/src/main/java/qunar/tc/bistoury/attach"
click node_server_ui "https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury"
click node_server_proxy "https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate"
click node_server_ui_handlers "https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate/ui/handler"
click node_server_agent_handlers "https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate/agent/handler"
click node_server_profiler "https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/service"
click node_server_web "https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/ui/controller"
click node_server_persistence "https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-common/src/main/java/qunar/tc/bistoury/serverside"
click node_server_app_registry "https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-application"

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_common_protocol,node_common_core,node_common_profiler toneBlue
class node_client_agent,node_client_tasks,node_client_common,node_client_commands,node_client_decompiler toneAmber
class node_attach_bootstrap,node_attach_client,node_attach_spy,node_attach_magic,node_attach_arthas,node_attach_common toneMint
class node_server_ui,node_server_proxy,node_server_ui_handlers,node_server_agent_handlers,node_server_profiler,node_server_web,node_server_persistence,node_server_app_registry toneRose
```

## Components

### Common

Shared protocol, utilities, and crypto used across server and agent

- [Remoting](https://github.com/acceptmediocrity/gzzd/tree/main/common/src/main/java/qunar/tc/bistoury/remoting): protocol · Shared command codes, envelopes, codecs, and message types · `common/src/main/java/qunar/tc/bistoury/remoting`
- [Core Utils](https://github.com/acceptmediocrity/gzzd/tree/main/common/src/main/java/qunar/tc/bistoury/common): shared-utils · Shared crypto, file, JSON, and runtime helpers · `common/src/main/java/qunar/tc/bistoury/common`
- [Profiler Core](https://github.com/acceptmediocrity/gzzd/tree/main/common/src/main/java/qunar/tc/bistoury/common/profiler): shared-profiler · Compact profiler data structures and method caches · `common/src/main/java/qunar/tc/bistoury/common/profiler`

### Clientside

Agent runtime, commands, and decompiler support deployed near target JVMs

- [Agent Runtime](https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-agent/src/main/java/qunar/tc/bistoury/agent): agent-daemon · Standalone client agent entrypoint, heartbeat, and Netty connectivity · `clientside/clientside-agent/src/main/java/qunar/tc/bistoury/agent`
- [Agent Tasks](https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-agent/src/main/java/qunar/tc/bistoury/agent/task): task-executors · Concrete JVM and OS-side task factories for inspection and collection · `clientside/clientside-agent/src/main/java/qunar/tc/bistoury/agent/task`
- [Agent Common](https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-agent-common/src/main/java/qunar/tc/bistoury/agent/common): agent-support · Process discovery, response jobs, remoting task store, and KV helpers · `clientside/clientside-agent-common/src/main/java/qunar/tc/bistoury/agent/common`
- [Client Commands](https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-command/src/main/java/qunar/tc/bistoury/commands): command-pack · Command implementations for CPU, heap, download, monitor, host, and profiler flows · `clientside/clientside-command/src/main/java/qunar/tc/bistoury/commands`
- [Decompiler](https://github.com/acceptmediocrity/gzzd/tree/main/clientside/clientside-decompiler-fernflower/src/main/java/qunar/tc/decompiler): fernflower · Embedded Fernflower decompiler used for source-like rendering · `clientside/clientside-decompiler-fernflower/src/main/java/qunar/tc/decompiler`

### Attach

Instrumentation, attach-time tooling, and Arthas integration

- [Bootstrap](https://github.com/acceptmediocrity/gzzd/tree/main/attach/instrument/instrument-agent/src/main/java/qunar/tc/bistoury/instrument/agent): attach-agent · Attach-time bootstrap and classloader support for target JVM instrumentation · `attach/instrument/instrument-agent/src/main/java/qunar/tc/bistoury/instrument/agent`
- [Instrument Client](https://github.com/acceptmediocrity/gzzd/tree/main/attach/instrument/instrument-client/src/main/java/qunar/tc/bistoury/instrument/client): instrumentation · Debugger, monitor, profiler, and source location instrumentation logic · `attach/instrument/instrument-client/src/main/java/qunar/tc/bistoury/instrument/client`
- [Spy Bridge](https://github.com/acceptmediocrity/gzzd/tree/main/attach/instrument/instrument-spy/src/main/java/qunar/tc/bistoury/instrument/spy): async-profiler-bridge · Async-profiler bridge and spying hooks used by instrumentation · `attach/instrument/instrument-spy/src/main/java/qunar/tc/bistoury/instrument/spy`
- [Magic Classes](https://github.com/acceptmediocrity/gzzd/tree/main/attach/instrument/magic-classes/src/main/java/qunar/tc/bistoury/magic/classes): classloading-aid · Special classloading and shaded helper classes for hostile environments · `attach/instrument/magic-classes/src/main/java/qunar/tc/bistoury/magic/classes`
- [Arthas Shell](https://github.com/acceptmediocrity/gzzd/tree/main/attach/attach-arthas/src/main/java/qunar/tc/bistoury/attach/arthas): arthas-integration · Embedded Arthas command pack and shell server integration · `attach/attach-arthas/src/main/java/qunar/tc/bistoury/attach/arthas`
- [Attach File](https://github.com/acceptmediocrity/gzzd/tree/main/attach/attach-common/src/main/java/qunar/tc/bistoury/attach): file-service · Shared attach-side file service utilities and jar storage helpers · `attach/attach-common/src/main/java/qunar/tc/bistoury/attach`

### Serverside

Standalone backend, proxy, UI, persistence, and application registry

- [Serverside UI](https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury): standalone-app · Spring MVC frontend runtime, static assets, and the standalone jar entrypoint · `serverside/serverside-ui/src/main/java/qunar/tc/bistoury`
- [Proxy Hub](https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate): netty-proxy · Central browser-to-agent communication hub with UI and agent sessions · `serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate`
- [UI Handlers](https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate/ui/handler): ui-command-routing · Browser request decoding and command processors for inspection, download, and profiler actions · `serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate/ui/handler`
- [Agent Handlers](https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate/agent/handler): agent-message-routing · Agent-side connection handlers, heartbeats, and profiler file delivery · `serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/communicate/agent/handler`
- [Profiler Service](https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/service): profiler-workflow · Profiler coordination, storage, locking, and analysis pipeline · `serverside/serverside-ui/src/main/java/qunar/tc/bistoury/proxy/service`
- [Web APIs](https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-ui/src/main/java/qunar/tc/bistoury/ui/controller): spring-mvc · HTTP controllers for login, application views, config, profiler, and agent endpoints · `serverside/serverside-ui/src/main/java/qunar/tc/bistoury/ui/controller`
- [Persistence](https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-common/src/main/java/qunar/tc/bistoury/serverside): db-config-security · Dynamic config, database access, encryption, and user/token storage support · `serverside/serverside-common/src/main/java/qunar/tc/bistoury/serverside`
- [App Registry](https://github.com/acceptmediocrity/gzzd/tree/main/serverside/serverside-application): application-metadata · Application and app-server resolution with k8s-backed implementations · `serverside/serverside-application`

## Connections

- Remoting → Proxy Hub: messages · Shared request/response datagrams and command codes define the proxy contract
- Remoting → Agent Common: codec · Agent-side remoting uses the same envelopes and serializers
- Core Utils → Persistence: helpers · Shared utilities support encryption, files, and runtime helpers
- Core Utils → Web APIs: utils · Frontend and API flows reuse common JSON, crypto, and file helpers
- Profiler Core → Profiler Service: data model · Profiler structures are shared with server-side analysis and storage
- Profiler Core → Client Commands: profile data · Profiler summaries and caches are consumed by client command execution
- Serverside UI → Web APIs: hosts · Standalone application exposes Spring MVC controllers and static assets
- Serverside UI → Proxy Hub: embeds · The standalone runtime embeds the proxy communication hub
- Web APIs → Proxy Hub: dispatches · HTTP handlers translate browser actions into proxy commands and sessions
- Web APIs → App Registry: resolves apps · Controllers consult application metadata to locate target servers
- Web APIs → Persistence: stores users · Login, token, and configuration flows use persistence services
- Proxy Hub → UI Handlers: routes ui · Browser-originated requests are decoded into command processors
- Proxy Hub → Agent Handlers: routes agent · Agent sessions receive heartbeat, info, response, and profiler file messages
- UI Handlers → Client Commands: issues commands · UI command processors build logical operations executed by the agent
- UI Handlers → Profiler Service: profiler control · Profiler start/stop/state flows coordinate with profiler services
- Agent Handlers → Agent Runtime: connects to · Proxy-side agent connections terminate in the running JVM agent
- Agent Runtime → Agent Tasks: executes · Agent runtime schedules concrete task factories and background jobs
- Agent Tasks → Client Commands: implements · Agent-side task factories realize command semantics such as heap, CPU, monitor, and profiler
- Agent Runtime → Agent Common: uses · Agent runtime relies on shared process, response, and remoting helpers
- Client Commands → Arthas Shell: alternate path · Arthas command packs provide a parallel debug and shell execution path
- Client Commands → Instrument Client: instrumentation · Commands for debugging, monitoring, and profiling rely on instrumented runtime support
- Bootstrap → Instrument Client: boots · Attach bootstrap loads instrumentation client into target JVMs
- Instrument Client → Spy Bridge: profiles · Instrumentation client delegates profiler hooks to the spy bridge
- Instrument Client → Magic Classes: loads · Special classloading helpers keep instrumentation working across classloader boundaries
- Attach File → Arthas Shell: files · Attach-side file service supports jars, snapshots, and temporary outputs
- Profiler Service → Proxy Hub: streams · Profiler data and state are transferred through the proxy hub
- Decompiler → Client Commands: supports · Decompiler output backs source-view and decompile-related commands
