Conversation
Phase 1 - Directory Restructuring:
- cmd/main.go → cmd/sing-helm/main.go (Go standard practice)
- internal/env/ → internal/platform/ (clearer naming)
- internal/runtime/ → internal/model/ (avoid stdlib conflict)
- internal/client/ → internal/clashapi/ (explicit purpose)
Phase 2 - Dependency Injection Foundation:
- Add internal/app/app.go with Application struct (DI container)
- Add platform.Resolve() pure function (no global state)
- Add model.SaveStateTo/LoadStateFrom (path as parameter)
- Wire Application into CLI via context (AppFromContext)
- Add logger.GetInstance() for DI consumers
Phase 3 - Anti-Corruption Layer:
- Merge internal/config/ + internal/service/ → internal/engine/
- Move tools/exporter → internal/engine/exporter.go
- All sing-box imports now isolated to engine/ package
- Future sing-box upgrades only require changes in engine/
Phase 4 - Daemon Slimming:
- Split daemon.go (578 lines) into focused files:
- daemon.go (~200 lines): core struct, Serve, Handle router
- handler_run.go: run/reload logic
- handler_node.go: node management via Clash API
- handler_mode.go: proxy/route mode switching
- handler_status.go: status/health/log/stop/reload
Address secondary review findings: - Delete redundant `controller` package, route TUI IPC calls directly - Consolidate duplicated `asInt` implementations to `ipc.AsInt` - Eliminate `internal/pkg` anti-pattern (move `netutil` to `platform`) - Merge `cli/utils.go` into `dispatcher.go` - Extract 366-line `engine/exporter.go` to independent `internal/export` package - Split 350-line `cli/config.go` by extracting operations to `config_ops.go` - Rename files for better clarity (`lifecycle`->`status`, `type`->`options`, `singbox`->`instance`, etc.)
Create `internal/engine/config` for core building logic (builder, loader, types), and `internal/engine/module` for all `ConfigModule` implementations (tun, route, experimental, outbound, etc.). Move high level exported API to `internal/engine/engine.go` to act as the primary facade, eliminating Go circular imports.
Resolve chaotic top-level "internal/" coupling by introducing strict vertical layering: - `internal/core`: Isolated business definitions (model, version) - `internal/sys`: System abstractions (sys/env, logger, ipc) - `internal/proxy`: Proxy domain boundaries (engine, export, subscription, clashapi) - `internal/app`: Application entrypoints & orchestration (cli, daemon, tui, container)
- Move `internal/sys/env/lock.go` to `internal/sys/lock/lock.go` - Rename `internal/sys/env` to `internal/sys/paths` since it mainly models and resolves the application paths instead of generic environments
- moving daemon background state and file reading into app/daemon/meta.go - migrating cli bootstrap into app/cli/setup.go - keeping sys/paths purely a utility package for static path computations without JSON serialization logic
…ckage and update CLI and daemon for new structure.
…ycles & clean up module design
…sing logic to a dedicated subscription package and consolidating module utilities under `node` and `utils` subdirectories.
…ig/model`, and refactor subscription storage to use JSON files.
… module, enhance node processing with improved deduplication and detour resolution, and add comprehensive test coverage across various modules.
… module, and improve logger output.
…tibility and ensure DNS hijack rules precede private direct rules.
…port, removing generic version compatibility.
- Added refactor.md, serve_log.txt, .gemini/ and gha-creds-*.json to .gitignore - Removed serve_log.txt from the repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a major architectural overhaul to improve maintainability, decouple components, and follow Go best practices (DDD-inspired layering).
Key Changes
internal/intocore,sys,proxy, andapplayers.sing-boxdependencies.sing-boxv1.11.x config export..gitignoreto include refactor notes and temporary logs; removed unnecessary files.Test Plan
make testlocally; all 35 tests passed across focused packages.