# hcloudlab/hrules architecture

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

- Interactive diagram: https://gitdiagram.com/hcloudlab/hrules
- Repository: https://github.com/hcloudlab/hrules

## Overview

Hrules is a client-side traffic-routing ruleset, not a proxy-node provider. Users add its rules to an existing subscription or import a client configuration; the client matches traffic to service scenes and applies the user-selected egress, with a catch-all for unmatched traffic. Mihomo has Standard and Fine-grained editions, DNS profiles, and a 3X-UI import path; Shadowrocket has a separate configuration. Edges reflect README contracts and sampled Mihomo adapter behavior; unsampled configuration internals are represented only at the documented integration level.

Main entry points: [`mihomo/adapters/clash-verge-rev/hrules-global.js`](https://github.com/hcloudlab/hrules/blob/main/mihomo/adapters/clash-verge-rev/hrules-global.js) (Clash adapter), [`mihomo/editions`](https://github.com/hcloudlab/hrules/tree/main/mihomo/editions) (Edition scripts), [`mihomo/editions/hrules-strict.js`](https://github.com/hcloudlab/hrules/blob/main/mihomo/editions/hrules-strict.js) (Scene and egress groups), [`mihomo/hosts/3x-ui`](https://github.com/hcloudlab/hrules/tree/main/mihomo/hosts/3x-ui) (3X-UI routing profiles)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mihomo["Mihomo routing"]
  node_mihomo_editions["Edition scripts"]
  node_clash_adapter["Clash adapter<br/>[hrules-global.js]"]
  node_mihomo_dns["Mihomo DNS profiles"]
  node_three_x_rules["3X-UI routing profiles"]
  node_scene_groups["Scene and egress groups<br/>[hrules-strict.js]"]
  node_routing_rules["Ordered routing rules<br/>[hrules-strict.js]"]
  node_dns_rules["DNS configuration<br/>[hrules-strict.js]"]
end

subgraph group_rules["Routing assets"]
  node_scene_rules["Scene rule sets"]
end

subgraph group_shadowrocket["Shadowrocket"]
  node_shadow_config["Shadowrocket profile<br/>[hrules.conf]"]
end

subgraph group_external["External runtime"]
  node_clash["Clash Verge Rev"]
  node_mihomo_engine["Mihomo client"]
  node_three_x_ui["3X-UI"]
  node_shadow_app["Shadowrocket app"]
end

node_user(("User"))
node_traffic(("Network traffic"))
node_node_sources(("Node subscriptions"))

node_user -->|"installs script"| node_clash
node_user -->|"imports rules"| node_three_x_ui
node_user -->|"imports profile"| node_shadow_app
node_node_sources -->|"provides subscription"| node_clash
node_clash -->|"runs extension"| node_clash_adapter
node_mihomo_editions -->|"defines groups"| node_scene_groups
node_mihomo_editions -->|"defines ordering"| node_routing_rules
node_mihomo_editions -->|"sets DNS"| node_dns_rules
node_clash_adapter -->|"builds groups"| node_scene_groups
node_clash_adapter -->|"builds rules"| node_routing_rules
node_clash_adapter -->|"sets DNS"| node_dns_rules
node_clash_adapter -->|"references providers"| node_scene_rules
node_three_x_ui -->|"imports profiles"| node_three_x_rules
node_three_x_rules -->|"configures routing"| node_mihomo_engine
node_mihomo_dns -->|"configures DNS"| node_mihomo_engine
node_clash -->|"runs profile"| node_mihomo_engine
node_scene_groups -->|"offers egress choices"| node_mihomo_engine
node_routing_rules -->|"matches traffic"| node_mihomo_engine
node_dns_rules -->|"resolves domains"| node_mihomo_engine
node_traffic -->|"enters routing"| node_mihomo_engine
node_mihomo_engine -->|"uses selected node"| node_node_sources
node_user -->|"downloads profile"| node_shadow_config
node_shadow_config -->|"configures routing"| node_shadow_app
node_traffic -->|"enters routing"| node_shadow_app
node_shadow_app -->|"uses proxy egress"| node_node_sources

click node_mihomo_editions "https://github.com/hcloudlab/hrules/tree/main/mihomo/editions"
click node_clash_adapter "https://github.com/hcloudlab/hrules/blob/main/mihomo/adapters/clash-verge-rev/hrules-global.js"
click node_scene_rules "https://github.com/hcloudlab/hrules/tree/main/mihomo/scenes"
click node_mihomo_dns "https://github.com/hcloudlab/hrules/tree/main/mihomo/dns"
click node_three_x_rules "https://github.com/hcloudlab/hrules/tree/main/mihomo/hosts/3x-ui"
click node_shadow_config "https://github.com/hcloudlab/hrules/blob/main/shadowrocket/hrules.conf"
click node_scene_groups "https://github.com/hcloudlab/hrules/blob/main/mihomo/editions/hrules-strict.js"
click node_routing_rules "https://github.com/hcloudlab/hrules/blob/main/mihomo/editions/hrules-strict.js"
click node_dns_rules "https://github.com/hcloudlab/hrules/blob/main/mihomo/editions/hrules-strict.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_mihomo_editions,node_clash_adapter,node_mihomo_dns,node_three_x_rules,node_scene_groups,node_routing_rules,node_dns_rules,node_user toneBlue
class node_scene_rules toneAmber
class node_shadow_config toneMint
class node_clash,node_mihomo_engine,node_three_x_ui,node_shadow_app toneRose
class node_traffic,node_node_sources toneIndigo
```

## Components

### Mihomo routing

- [Edition scripts](https://github.com/hcloudlab/hrules/tree/main/mihomo/editions): `mihomo/editions`
- [Clash adapter](https://github.com/hcloudlab/hrules/blob/main/mihomo/adapters/clash-verge-rev/hrules-global.js): `mihomo/adapters/clash-verge-rev/hrules-global.js`
- [Mihomo DNS profiles](https://github.com/hcloudlab/hrules/tree/main/mihomo/dns): `mihomo/dns`
- [3X-UI routing profiles](https://github.com/hcloudlab/hrules/tree/main/mihomo/hosts/3x-ui): `mihomo/hosts/3x-ui`
- [Scene and egress groups](https://github.com/hcloudlab/hrules/blob/main/mihomo/editions/hrules-strict.js): `mihomo/editions/hrules-strict.js`
- [Ordered routing rules](https://github.com/hcloudlab/hrules/blob/main/mihomo/editions/hrules-strict.js): `mihomo/editions/hrules-strict.js`
- [DNS configuration](https://github.com/hcloudlab/hrules/blob/main/mihomo/editions/hrules-strict.js): `mihomo/editions/hrules-strict.js`

### Routing assets

- [Scene rule sets](https://github.com/hcloudlab/hrules/tree/main/mihomo/scenes): `mihomo/scenes`

### Shadowrocket

- [Shadowrocket profile](https://github.com/hcloudlab/hrules/blob/main/shadowrocket/hrules.conf): `shadowrocket/hrules.conf`

### External runtime

- **Clash Verge Rev**
- **Mihomo client**
- **3X-UI**
- **Shadowrocket app**

### Other components

- **User**
- **Network traffic**
- **Node subscriptions**

## Connections

- User → Clash Verge Rev: installs script
- User → 3X-UI: imports rules
- User → Shadowrocket app: imports profile
- Node subscriptions → Clash Verge Rev: provides subscription
- Clash Verge Rev → Clash adapter: runs extension
- Edition scripts → Scene and egress groups: defines groups
- Edition scripts → Ordered routing rules: defines ordering
- Edition scripts → DNS configuration: sets DNS
- Clash adapter → Scene and egress groups: builds groups
- Clash adapter → Ordered routing rules: builds rules
- Clash adapter → DNS configuration: sets DNS
- Clash adapter → Scene rule sets: references providers
- 3X-UI → 3X-UI routing profiles: imports profiles
- 3X-UI routing profiles → Mihomo client: configures routing
- Mihomo DNS profiles → Mihomo client: configures DNS
- Clash Verge Rev → Mihomo client: runs profile
- Scene and egress groups → Mihomo client: offers egress choices
- Ordered routing rules → Mihomo client: matches traffic
- DNS configuration → Mihomo client: resolves domains
- Network traffic → Mihomo client: enters routing
- Mihomo client → Node subscriptions: uses selected node
- User → Shadowrocket profile: downloads profile
- Shadowrocket profile → Shadowrocket app: configures routing
- Network traffic → Shadowrocket app: enters routing
- Shadowrocket app → Node subscriptions: uses proxy egress
