TZ/docs/第一版本.md
2026-08-21 18:34:18 +08:00

8.5 KiB
Raw Permalink Blame History

项目组织

使用语言 Go

第一版本需要实现的指令

tz status
tz start
tz stop
tz restart

tz core list
tz core add
tz core remove
tz core use
tz core info

tz profile list
tz profile add
tz profile remove
tz profile use
tz profile update

tz config build
tz config check

tz node list
tz node select
tz node test

tz log

文件树

tz/
├── Cargo.toml
├── Cargo.lock
├── rust-toolchain.toml
├── README.md
├── LICENSE
│
├── src/
│   ├── main.rs
│   ├── lib.rs
│   │
│   ├── cli/
│   │   ├── mod.rs
│   │   ├── args.rs
│   │   ├── output.rs
│   │   └── commands/
│   │       ├── mod.rs
│   │       ├── status.rs
│   │       ├── service.rs
│   │       ├── core.rs
│   │       ├── profile.rs
│   │       ├── group.rs
│   │       ├── node.rs
│   │       ├── mode.rs
│   │       ├── tun.rs
│   │       ├── proxy.rs
│   │       ├── setting.rs
│   │       ├── rule.rs
│   │       ├── connection.rs
│   │       ├── config.rs
│   │       ├── log.rs
│   │       └── diagnose.rs
│   │
│   ├── application/
│   │   ├── mod.rs
│   │   ├── context.rs
│   │   └── usecase/
│   │       ├── mod.rs
│   │       ├── start.rs
│   │       ├── stop.rs
│   │       ├── restart.rs
│   │       ├── reload.rs
│   │       ├── switch_core.rs
│   │       ├── switch_profile.rs
│   │       ├── update_profile.rs
│   │       └── select_node.rs
│   │
│   ├── domain/
│   │   ├── mod.rs
│   │   ├── core.rs
│   │   ├── profile.rs
│   │   ├── settings.rs
│   │   ├── runtime.rs
│   │   ├── capability.rs
│   │   ├── group.rs
│   │   ├── node.rs
│   │   ├── connection.rs
│   │   └── error.rs
│   │
│   ├── adapter/
│   │   ├── mod.rs
│   │   ├── traits.rs
│   │   ├── registry.rs
│   │   │
│   │   ├── mihomo/
│   │   │   ├── mod.rs
│   │   │   ├── adapter.rs
│   │   │   ├── command.rs
│   │   │   ├── config.rs
│   │   │   ├── controller.rs
│   │   │   └── response.rs
│   │   │
│   │   └── sing_box/
│   │       ├── mod.rs
│   │       ├── adapter.rs
│   │       ├── command.rs
│   │       ├── config.rs
│   │       ├── controller.rs
│   │       └── response.rs
│   │
│   ├── core_manager/
│   │   ├── mod.rs
│   │   ├── manager.rs
│   │   ├── registry.rs
│   │   ├── package.rs
│   │   ├── installer.rs
│   │   └── remover.rs
│   │
│   ├── profile/
│   │   ├── mod.rs
│   │   ├── manager.rs
│   │   ├── store.rs
│   │   ├── fetcher.rs
│   │   ├── detector.rs
│   │   └── format/
│   │       ├── mod.rs
│   │       ├── clash.rs
│   │       ├── sing_box.rs
│   │       └── uri_list.rs
│   │
│   ├── config/
│   │   ├── mod.rs
│   │   ├── builder.rs
│   │   ├── overlay.rs
│   │   ├── effective.rs
│   │   ├── bypass.rs
│   │   └── validator.rs
│   │
│   ├── runtime/
│   │   ├── mod.rs
│   │   ├── manager.rs
│   │   ├── process.rs
│   │   ├── pid.rs
│   │   ├── lock.rs
│   │   ├── health.rs
│   │   ├── state.rs
│   │   └── log.rs
│   │
│   ├── platform/
│   │   ├── mod.rs
│   │   ├── paths.rs
│   │   ├── shell.rs
│   │   ├── system_proxy.rs
│   │   ├── service.rs
│   │   └── linux/
│   │       ├── mod.rs
│   │       ├── systemd.rs
│   │       ├── signal.rs
│   │       ├── tun.rs
│   │       └── routes.rs
│   │
│   ├── storage/
│   │   ├── mod.rs
│   │   ├── atomic_file.rs
│   │   ├── core_store.rs
│   │   ├── profile_store.rs
│   │   ├── settings_store.rs
│   │   └── runtime_store.rs
│   │
│   ├── infrastructure/
│   │   ├── mod.rs
│   │   ├── command.rs
│   │   ├── http.rs
│   │   ├── download.rs
│   │   ├── checksum.rs
│   │   └── filesystem.rs
│   │
│   └── diagnose/
│       ├── mod.rs
│       ├── process.rs
│       ├── ports.rs
│       ├── api.rs
│       ├── config.rs
│       └── network.rs
│
├── assets/
│   ├── defaults/
│   │   └── settings.toml
│   ├── templates/
│   │   ├── mihomo.yaml
│   │   └── sing-box.json
│   └── systemd/
│       └── tz.service
│
├── tests/
│   ├── cli.rs
│   ├── start_stop.rs
│   ├── profile.rs
│   └── adapter.rs
│
├── testdata/
│   ├── profiles/
│   │   ├── clash.yaml
│   │   └── sing-box.json
│   ├── api/
│   │   ├── mihomo-proxies.json
│   │   ├── mihomo-connections.json
│   │   └── mihomo-version.json
│   └── bin/
│       └── fake-core
│
├── docs/
│   ├── scope.md
│   ├── domain-model.md
│   ├── workflows.md
│   ├── adapter-contract.md
│   └── filesystem-layout.md
│
├── packaging/
│   ├── systemd/
│   └── completions/
│
└── scripts/
    ├── install.sh
    ├── uninstall.sh
    └── release.sh

运行树

语言            Rust
异步运行时      Tokio
CLI             clap derive
序列化          Serde
HTTP            reqwest
错误类型        thiserror + anyhow
日志            tracing
项目配置        TOML
Clash Profile   YAML
sing-box        JSON
~/.config/tz/
├── settings.toml
├── current.toml
├── bypass.list
├── profiles/
│   ├── home/
│   │   ├── manifest.toml
│   │   └── source.yaml
│   └── company/
│       ├── manifest.toml
│       └── source.json
└── overlays/
    ├── common.toml
    ├── mihomo.yaml
    └── sing-box.json
    
~/.local/share/tz/
└── cores/
    ├── mihomo/
    │   ├── current
    │   └── versions/
    │       └── 1.20.0/
    │           ├── manifest.toml
    │           └── bin/
    │               └── mihomo
    └── sing-box/
        ├── current
        └── versions/
            └── 1.x/
                ├── manifest.toml
                └── bin/
                    └── sing-box
                    
~/.local/state/tz/
├── logs/
│   ├── tz.log
│   └── core.log
├── builds/
│   ├── effective-mihomo.yaml
│   └── effective-sing-box.json
├── history/
└── runtime-history/

~/.cache/tz/
├── downloads/
├── subscriptions/
└── latency/

${XDG_RUNTIME_DIR}/tz/
├── tz.lock
├── core.pid
├── runtime.json
├── effective-config
└── control.sock

rust开发环境

Rust + Tokio + clap
Mihomo
Clash YAML profile
start / stop / status / log
node list / select

现在使用一个 Package包含一个 Library target 和一个 Binary target。 不使用 Workspace也不使用多 Bin。

开发顺序

第一阶段
├── 路径系统
├── SettingsStore
├── CoreRegistry
├── ProfileStore
├── MihomoAdapter
├── RuntimeManager
├── tz start
├── tz stop
├── tz status
└── tz log
第二阶段
├── Mihomo Controller API
├── group list/select
├── node list/select/test
├── mode
├── reload
└── profile update
第三阶段
├── sing-box Adapter
├── Capability 检测
├── sing-box 配置生成
├── TUN
├── system proxy
└── bypass
第四阶段
├── core install/update
├── diagnose
├── connection
├── completion
└── 发布与安装脚本