How ieooo/clash works
Clash is a rule-based Go tunnel: configuration initializes inbound listeners, traffic enters as connection or packet contexts, routing selects a rule and proxy, and the selected outbound carries traffic onward. The architecture also includes DNS/fake-IP resolution, proxy groups and remote providers, transparent proxy modes, and a REST API for live control. The README documents several capabilities whose specific implementations are not sampled; those branches are included at subsystem level. Dashed edges mark documented but unverified runtime wiring.
Main entry points: tunnel.go Traffic tunnel · outbound Outbound protocols · server.go REST controller · executor.go Config executor
Components 20
Runtime control
- Process lifecycle
main.go - Hub orchestration
hub/hub.go - Config executor
hub/executor/executor.go
Traffic ingress
- Listener manager
listener/listener.go - HTTP / SOCKS / TUN
listener - Inbound adapters
adapter/inbound
Routing and DNS
- Traffic tunnel
tunnel/tunnel.go - Rule matching
rule - Resolver / fake IP
component/resolver - DNS service
dns/server.go - Upstream DNS
dns/client.go
Proxy egress
- Proxy construction
adapter/parser.go - Outbound protocols
adapter/outbound - Proxy groups
adapter/outboundgroup/parser.go - Remote providers
adapter/provider - Protocol transports
transport
Management API
- REST controller
hub/route/server.go - Live config / proxy routes
hub/route - Traffic statistics
tunnel/statistic/manager.go
Other components
- Operator / client
Connections 22
- Operator / client → Process lifecycle: starts process
main.go - Process lifecycle → Hub orchestration: loads config
main.go - Hub orchestration → Config executor: parses config
hub/hub.go - Config executor → Listener manager: configures listeners
hub/executor/executor.go - Listener manager → HTTP / SOCKS / TUN: creates listeners
listener/listener.go - HTTP / SOCKS / TUN → Inbound adapters: adapts connections
listener/listener.go - Inbound adapters → Traffic tunnel: submits traffic
tunnel/tunnel.go - Traffic tunnel → Rule matching: matches metadata
tunnel/tunnel.go - Traffic tunnel → Resolver / fake IP: resolves metadata
tunnel/tunnel.go - DNS service → Resolver / fake IP: uses resolver
dns/server.go - Upstream DNS → Resolver / fake IP: looks up host
dns/client.go - Traffic tunnel → Outbound protocols: dials selected proxy
- Proxy construction → Outbound protocols: constructs protocol
adapter/parser.go - Proxy groups → Outbound protocols: groups proxies
adapter/outboundgroup/parser.go - Proxy groups → Remote providers: uses providers
adapter/outboundgroup/parser.go - Outbound protocols → Protocol transports: uses transport
adapter/outbound/vmess.go - Operator / client → Listener manager: connects inbound
- Operator / client → DNS service: queries DNS
- Operator / client → REST controller: controls runtime
- REST controller → Live config / proxy routes: routes requests
hub/route/server.go - Live config / proxy routes → Config executor: updates config
- REST controller → Traffic statistics: reads traffic
hub/route/server.go