[PR #5167] [MERGED] refactor: focused service files, leaf subpackages, and an internal/ layout #5800

Closed
opened 2026-11-02 04:04:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5167
Author: @MHSanaei
Created: 6/10/2026
Status: ✅ Merged
Merged: 6/10/2026
Merged by: @MHSanaei

Base: main ← Head: refactor/client-service-split


📝 Commits (10+)

  • c4c1f6f refactor(service): split client.go into focused files
  • b98e4f6 refactor(service): split inbound.go into focused files
  • 4883503 refactor(service): split tgbot.go into focused files
  • 72d94f3 refactor(client): dedupe single-field by-email setters
  • a96b089 refactor(service): extract panel/ subpackage
  • 93cfe95 refactor(service): extract integration/ subpackage
  • b3edf10 refactor(service): extract tgbot/ subpackage
  • a04ba49 refactor(service): extract outbound/ subpackage
  • e109457 refactor(util): move wireguard into its own subpackage
  • 2a0a6bf refactor(sub): drop redundant sub prefix from filenames

📊 Changes

254 files changed (+13074 additions, -12836 deletions)

View changed files

📝 .dockerignore (+2 -1)
📝 .github/workflows/ci.yml (+4 -4)
📝 .github/workflows/claude-issue-bot.yml (+19 -19)
📝 .github/workflows/release.yml (+2 -2)
📝 .gitignore (+4 -7)
📝 CONTRIBUTING.md (+9 -9)
📝 Dockerfile (+3 -3)
📝 README.md (+1 -1)
📝 docs/custom-subscription-templates.md (+1 -1)
📝 frontend/README.md (+5 -5)
📝 frontend/eslint.config.js (+1 -1)
📝 frontend/eslint.deprecated.config.js (+1 -1)
📝 frontend/src/generated/types.ts (+0 -1)
📝 frontend/src/generated/zod.ts (+0 -3)
📝 frontend/src/i18n/react.ts (+4 -4)
📝 frontend/src/test/setup.components.ts (+1 -1)
📝 frontend/tsconfig.json (+1 -1)
📝 frontend/vite.config.js (+1 -1)
📝 internal/config/config.go (+7 -0)
📝 internal/config/name (+0 -0)

...and 80 more files

📄 Description

What & why

A structural reorganization of the Go backend so it's easier to navigate and follows an idiomatic, professional Go application layout. No runtime behavior change — the file splits are verbatim moves and the package moves are import-path-only. Best reviewed commit-by-commit (17 self-contained commits, each builds and tests green on its own).

Highlights

1. Split the three oversized service files (verbatim; identical declaration set verified before/after):

File Before After
client.go 4455 lines 10 focused client_*.go
inbound.go 4100 lines 10 focused inbound_*.go
tgbot.go 3738 lines (incl. a 1246-line method) 6 focused tgbot_*.go

2. Extract leaf service subpackages — services the core doesn't depend on (so no import cycles): web/service/{panel,integration,outbound,tgbot}/. The mutually-coupled core (client ↔ inbound ↔ node ↔ setting) necessarily stays flat.

3. Adopt an internal/ layout — moved config, database, logger, mtproto, sub, util, web, xray under internal/ (149 import rewrites). main.go and tools/ stay at the root; the module path is unchanged. Includes the non-Go couplings the compiler can't see: Vite outDir, the frontend's web/translation imports, Dockerfile COPYs, .gitignore/CI embed stubs, the openapigen package paths, and a repo-root-relative test path.

4. Smaller cleanups & fixes

  • dedupe 3 near-identical "set one field by email" setters into a single helper
  • util/wireguard.go → util/wireguard/ (it was the lone file of the root util package)
  • drop the redundant sub prefix from sub/ filenames; controller/xui.go → spa.go
  • move the orphan sub_templates/README.md → docs/custom-subscription-templates.md
  • remove the long-obsolete /xui → /panel redirect middleware
  • fix: tests no longer scatter log/ directories through the source tree (GetLogFolder() now honors testing.Testing())
  • fix: dev-mode disk-serving paths (os.DirFS("web/dist/...")) the internal/ move missed — production was unaffected (embedded FS); only go run with a live frontend build silently fell back to embed
  • .dockerignore: corrected path and excluded the local x-ui/ runtime dir from the build context

Verification

  • go build ./..., go vet ./..., go test ./... — all green
  • frontend: typecheck, lint, vitest (478 tests), build — all green
  • full docker build — image builds; embedded + disk layout verified inside the container

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5167 **Author:** [@MHSanaei](https://github.com/MHSanaei) **Created:** 6/10/2026 **Status:** ✅ Merged **Merged:** 6/10/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `refactor/client-service-split` --- ### 📝 Commits (10+) - [`c4c1f6f`](https://github.com/MHSanaei/3x-ui/commit/c4c1f6fd5583fc943cf9f60799a619b209fe774a) refactor(service): split client.go into focused files - [`b98e4f6`](https://github.com/MHSanaei/3x-ui/commit/b98e4f67985fe9595459537cc6f8d787dd72e12e) refactor(service): split inbound.go into focused files - [`4883503`](https://github.com/MHSanaei/3x-ui/commit/48835038fa209b9586b5f9ff6675b09719765333) refactor(service): split tgbot.go into focused files - [`72d94f3`](https://github.com/MHSanaei/3x-ui/commit/72d94f37b88c21ea84c05b6ab0820de12f0f8e99) refactor(client): dedupe single-field by-email setters - [`a96b089`](https://github.com/MHSanaei/3x-ui/commit/a96b0896fe2215f40eccc9deeecb1e3a9a94c759) refactor(service): extract panel/ subpackage - [`93cfe95`](https://github.com/MHSanaei/3x-ui/commit/93cfe95363dd7c2cdc62a517c6219f349a9c2d70) refactor(service): extract integration/ subpackage - [`b3edf10`](https://github.com/MHSanaei/3x-ui/commit/b3edf10a58fae607c6660139cee25c0e611f7c28) refactor(service): extract tgbot/ subpackage - [`a04ba49`](https://github.com/MHSanaei/3x-ui/commit/a04ba4928113b198444d6d7ce2b6ee7474638c49) refactor(service): extract outbound/ subpackage - [`e109457`](https://github.com/MHSanaei/3x-ui/commit/e10945728e822e1177553fd31f2f9400cf821b52) refactor(util): move wireguard into its own subpackage - [`2a0a6bf`](https://github.com/MHSanaei/3x-ui/commit/2a0a6bfee5e029dc042f849f53ea812b4fad34b5) refactor(sub): drop redundant sub prefix from filenames ### 📊 Changes **254 files changed** (+13074 additions, -12836 deletions) <details> <summary>View changed files</summary> 📝 `.dockerignore` (+2 -1) 📝 `.github/workflows/ci.yml` (+4 -4) 📝 `.github/workflows/claude-issue-bot.yml` (+19 -19) 📝 `.github/workflows/release.yml` (+2 -2) 📝 `.gitignore` (+4 -7) 📝 `CONTRIBUTING.md` (+9 -9) 📝 `Dockerfile` (+3 -3) 📝 `README.md` (+1 -1) 📝 `docs/custom-subscription-templates.md` (+1 -1) 📝 `frontend/README.md` (+5 -5) 📝 `frontend/eslint.config.js` (+1 -1) 📝 `frontend/eslint.deprecated.config.js` (+1 -1) 📝 `frontend/src/generated/types.ts` (+0 -1) 📝 `frontend/src/generated/zod.ts` (+0 -3) 📝 `frontend/src/i18n/react.ts` (+4 -4) 📝 `frontend/src/test/setup.components.ts` (+1 -1) 📝 `frontend/tsconfig.json` (+1 -1) 📝 `frontend/vite.config.js` (+1 -1) 📝 `internal/config/config.go` (+7 -0) 📝 `internal/config/name` (+0 -0) _...and 80 more files_ </details> ### 📄 Description ## What & why A structural reorganization of the Go backend so it's easier to navigate and follows an idiomatic, professional Go application layout. **No runtime behavior change** — the file splits are verbatim moves and the package moves are import-path-only. Best reviewed commit-by-commit (17 self-contained commits, each builds and tests green on its own). ## Highlights **1. Split the three oversized service files** (verbatim; identical declaration set verified before/after): | File | Before | After | |---|---|---| | `client.go` | 4455 lines | 10 focused `client_*.go` | | `inbound.go` | 4100 lines | 10 focused `inbound_*.go` | | `tgbot.go` | 3738 lines (incl. a 1246-line method) | 6 focused `tgbot_*.go` | **2. Extract leaf service subpackages** — services the core doesn't depend on (so no import cycles): `web/service/{panel,integration,outbound,tgbot}/`. The mutually-coupled core (client ↔ inbound ↔ node ↔ setting) necessarily stays flat. **3. Adopt an `internal/` layout** — moved `config, database, logger, mtproto, sub, util, web, xray` under `internal/` (149 import rewrites). `main.go` and `tools/` stay at the root; the module path is unchanged. Includes the non-Go couplings the compiler can't see: Vite `outDir`, the frontend's `web/translation` imports, Dockerfile COPYs, `.gitignore`/CI embed stubs, the openapigen package paths, and a repo-root-relative test path. **4. Smaller cleanups & fixes** - dedupe 3 near-identical "set one field by email" setters into a single helper - `util/wireguard.go` → `util/wireguard/` (it was the lone file of the root `util` package) - drop the redundant `sub` prefix from `sub/` filenames; `controller/xui.go` → `spa.go` - move the orphan `sub_templates/README.md` → `docs/custom-subscription-templates.md` - remove the long-obsolete `/xui → /panel` redirect middleware - **fix:** tests no longer scatter `log/` directories through the source tree (`GetLogFolder()` now honors `testing.Testing()`) - **fix:** dev-mode disk-serving paths (`os.DirFS("web/dist/...")`) the `internal/` move missed — production was unaffected (embedded FS); only `go run` with a live frontend build silently fell back to embed - `.dockerignore`: corrected path and excluded the local `x-ui/` runtime dir from the build context ## Verification - `go build ./...`, `go vet ./...`, `go test ./...` — all green - frontend: `typecheck`, `lint`, `vitest` (478 tests), `build` — all green - full `docker build` — image builds; embedded + disk layout verified inside the container --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:09 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5800
No description provided.