# unitech/pm2 architecture

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

- Interactive diagram: https://gitdiagram.com/unitech/pm2
- Repository: https://github.com/unitech/pm2

## Overview

PM2 is a production process manager: a user starts or manages applications through the CLI, which uses the API and client to communicate with a daemon; the daemon coordinates process supervision and returns status or logs. The map also preserves documented clustering, reloads, container runtime, startup scripts, terminal monitoring, and PM2+ monitoring. Relationships use README statements or source-index references; unsampled implementations are represented only where the tree and documentation establish the capability.

Main entry points: [`lib/API.js`](https://github.com/unitech/pm2/blob/master/lib/API.js) (Management API), [`lib/binaries/CLI.js`](https://github.com/unitech/pm2/blob/master/lib/binaries/CLI.js) (PM2 CLI), [`lib/God/ActionMethods.js`](https://github.com/unitech/pm2/blob/master/lib/God/ActionMethods.js) (Process actions), [`lib/Client.js`](https://github.com/unitech/pm2/blob/master/lib/Client.js) (RPC client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User interface"]
  node_cli["PM2 CLI<br/>[CLI.js]"]
end

subgraph group_control["Control plane"]
  node_api["Management API<br/>[API.js]"]
  node_client["RPC client<br/>[Client.js]"]
  node_daemon["PM2 daemon<br/>[Daemon.js]"]
  node_config["App configuration<br/>[Configuration.js]"]
  node_common["Config preparation<br/>[Common.js]"]
end

subgraph group_runtime["Process runtime"]
  node_god["Process supervisor<br/>[God.js]"]
  node_actions["Process actions<br/>[ActionMethods.js]"]
  node_cluster["Cluster mode<br/>[ClusterMode.js]"]
  node_fork["Fork mode<br/>[ForkMode.js]"]
  node_container["App container"]
end

subgraph group_operations["Operations"]
  node_logs["Log management<br/>[LogManagement.js]"]
  node_monitor["Terminal monitor<br/>[Monit.js]"]
  node_startup["Startup scripts<br/>[Startup.js]"]
  node_runtimecli["Container runtime<br/>[Runtime4Docker.js]"]
  node_deploy["Deployment<br/>[Deploy.js]"]
  node_modules["Module management<br/>[Modularizer.js]"]
end

subgraph group_monitoring["Monitoring"]
  node_pm2io["PM2+ integration<br/>[PM2IO.js]"]
  node_agent["Metrics agent"]
  node_features["APM features<br/>[featureManager.js]"]
end

node_operator(("Operator"))
node_dashboard(("PM2+ service"))

node_operator -->|"runs commands"| node_cli
node_cli -->|"dispatches"| node_api
node_api -->|"calls"| node_client
node_client -->|"RPC calls"| node_daemon
node_daemon -->|"initializes"| node_god
node_god -->|"delegates"| node_actions
node_actions -.->|"supports clustering"| node_cluster
node_actions -.->|"supports fork mode"| node_fork
node_cluster -.->|"runs app"| node_container
node_fork -.->|"runs app"| node_container
node_api -->|"uses configuration"| node_config
node_config -->|"prepares app settings"| node_common
node_operator -->|"requests logs"| node_logs
node_operator -->|"opens monitor"| node_monitor
node_operator -->|"configures startup"| node_startup
node_operator -->|"runs container command"| node_runtimecli
node_operator -.->|"requests deployment"| node_deploy
node_api -->|"manages modules"| node_modules
node_cli -->|"invokes integration"| node_pm2io
node_pm2io -->|"starts agent"| node_agent
node_agent -.->|"sends monitoring data"| node_dashboard
node_features -.->|"provides APM capabilities"| node_dashboard

click node_cli "https://github.com/unitech/pm2/blob/master/lib/binaries/CLI.js"
click node_api "https://github.com/unitech/pm2/blob/master/lib/API.js"
click node_client "https://github.com/unitech/pm2/blob/master/lib/Client.js"
click node_daemon "https://github.com/unitech/pm2/blob/master/lib/Daemon.js"
click node_god "https://github.com/unitech/pm2/blob/master/lib/God.js"
click node_actions "https://github.com/unitech/pm2/blob/master/lib/God/ActionMethods.js"
click node_cluster "https://github.com/unitech/pm2/blob/master/lib/God/ClusterMode.js"
click node_fork "https://github.com/unitech/pm2/blob/master/lib/God/ForkMode.js"
click node_container "https://github.com/unitech/pm2/blob/master/lib/ProcessContainer.js"
click node_config "https://github.com/unitech/pm2/blob/master/lib/Configuration.js"
click node_common "https://github.com/unitech/pm2/blob/master/lib/Common.js"
click node_logs "https://github.com/unitech/pm2/blob/master/lib/API/LogManagement.js"
click node_monitor "https://github.com/unitech/pm2/blob/master/lib/API/Monit.js"
click node_startup "https://github.com/unitech/pm2/blob/master/lib/API/Startup.js"
click node_runtimecli "https://github.com/unitech/pm2/blob/master/lib/binaries/Runtime4Docker.js"
click node_deploy "https://github.com/unitech/pm2/blob/master/lib/API/Deploy.js"
click node_modules "https://github.com/unitech/pm2/blob/master/lib/API/Modules/Modularizer.js"
click node_pm2io "https://github.com/unitech/pm2/blob/master/lib/API/pm2-plus/PM2IO.js"
click node_agent "https://github.com/unitech/pm2/blob/master/modules/pm2-io-agent/src/InteractorClient.js"
click node_features "https://github.com/unitech/pm2/blob/master/modules/pm2-io-bpm/featureManager.js"

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_cli toneBlue
class node_api,node_client,node_daemon,node_config,node_common toneAmber
class node_god,node_actions,node_cluster,node_fork,node_container toneMint
class node_logs,node_monitor,node_startup,node_runtimecli,node_deploy,node_modules toneRose
class node_pm2io,node_agent,node_features,node_operator,node_dashboard toneIndigo
```

## Components

### User interface

- [PM2 CLI](https://github.com/unitech/pm2/blob/master/lib/binaries/CLI.js): `lib/binaries/CLI.js`

### Control plane

- [Management API](https://github.com/unitech/pm2/blob/master/lib/API.js): `lib/API.js`
- [RPC client](https://github.com/unitech/pm2/blob/master/lib/Client.js): `lib/Client.js`
- [PM2 daemon](https://github.com/unitech/pm2/blob/master/lib/Daemon.js): `lib/Daemon.js`
- [App configuration](https://github.com/unitech/pm2/blob/master/lib/Configuration.js): `lib/Configuration.js`
- [Config preparation](https://github.com/unitech/pm2/blob/master/lib/Common.js): `lib/Common.js`

### Process runtime

- [Process supervisor](https://github.com/unitech/pm2/blob/master/lib/God.js): `lib/God.js`
- [Process actions](https://github.com/unitech/pm2/blob/master/lib/God/ActionMethods.js): `lib/God/ActionMethods.js`
- [Cluster mode](https://github.com/unitech/pm2/blob/master/lib/God/ClusterMode.js): `lib/God/ClusterMode.js`
- [Fork mode](https://github.com/unitech/pm2/blob/master/lib/God/ForkMode.js): `lib/God/ForkMode.js`
- [App container](https://github.com/unitech/pm2/blob/master/lib/ProcessContainer.js): `lib/ProcessContainer.js`

### Operations

- [Log management](https://github.com/unitech/pm2/blob/master/lib/API/LogManagement.js): `lib/API/LogManagement.js`
- [Terminal monitor](https://github.com/unitech/pm2/blob/master/lib/API/Monit.js): `lib/API/Monit.js`
- [Startup scripts](https://github.com/unitech/pm2/blob/master/lib/API/Startup.js): `lib/API/Startup.js`
- [Container runtime](https://github.com/unitech/pm2/blob/master/lib/binaries/Runtime4Docker.js): `lib/binaries/Runtime4Docker.js`
- [Deployment](https://github.com/unitech/pm2/blob/master/lib/API/Deploy.js): `lib/API/Deploy.js`
- [Module management](https://github.com/unitech/pm2/blob/master/lib/API/Modules/Modularizer.js): `lib/API/Modules/Modularizer.js`

### Monitoring

- [PM2+ integration](https://github.com/unitech/pm2/blob/master/lib/API/pm2-plus/PM2IO.js): `lib/API/pm2-plus/PM2IO.js`
- [Metrics agent](https://github.com/unitech/pm2/blob/master/modules/pm2-io-agent/src/InteractorClient.js): `modules/pm2-io-agent/src/InteractorClient.js`
- [APM features](https://github.com/unitech/pm2/blob/master/modules/pm2-io-bpm/featureManager.js): `modules/pm2-io-bpm/featureManager.js`

### Other components

- **Operator**
- **PM2+ service**

## Connections

- Operator → PM2 CLI: runs commands (evidence: `README.md`)
- PM2 CLI → Management API: dispatches (evidence: `lib/binaries/CLI.js`)
- Management API → RPC client: calls (evidence: `lib/API.js`)
- RPC client → PM2 daemon: RPC calls (evidence: `lib/Client.js`)
- PM2 daemon → Process supervisor: initializes (evidence: `lib/Daemon.js`)
- Process supervisor → Process actions: delegates (evidence: `lib/God/ActionMethods.js`)
- Process actions → Cluster mode: supports clustering (evidence: `README.md`)
- Process actions → Fork mode: supports fork mode (evidence: `lib/God/ActionMethods.js`)
- Cluster mode → App container: runs app
- Fork mode → App container: runs app
- Management API → App configuration: uses configuration (evidence: `lib/API.js`)
- App configuration → Config preparation: prepares app settings (evidence: `lib/Configuration.js`)
- Operator → Log management: requests logs (evidence: `README.md`)
- Operator → Terminal monitor: opens monitor (evidence: `README.md`)
- Operator → Startup scripts: configures startup (evidence: `README.md`)
- Operator → Container runtime: runs container command (evidence: `README.md`)
- Operator → Deployment: requests deployment
- Management API → Module management: manages modules (evidence: `lib/API.js`)
- PM2 CLI → PM2+ integration: invokes integration (evidence: `lib/binaries/CLI.js`)
- PM2+ integration → Metrics agent: starts agent (evidence: `lib/API/pm2-plus/PM2IO.js`)
- Metrics agent → PM2+ service: sends monitoring data (evidence: `README.md`)
- APM features → PM2+ service: provides APM capabilities
