[GH-ISSUE #5694] [Feature]: Unified Subscription Link for Groups (Reusing existing aggregation engine) #3959

Open
opened 2026-10-31 20:36:10 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @De-naber on GitHub (Jun 30, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5694

First of all, thank you for the incredible work! The software is absolutely top-notch, and the recent improvements to the "Groups" functionality in the latest releases are perfect.

However, there is a missing piece for a very common real-world scenario. Currently, if I want to provide access to a "Family" (which has multiple users and multiple devices), I have to generate and send a separate subscription link for each client/device. This is quite tedious for the end-user.

It would be much more logical and user-friendly to share just one single subscription link for the entire Group. The user's app (v2rayNG, Karing, etc.) would then fetch this group link and automatically get all the inbounds/configs assigned to the clients within that group.

Describe the solution you'd like

Implement a Group Subscription Link.

I took a look at the SQLite database structure and the current backend logic, and it seems almost zero new logic needs to be written. The engine already knows how to do this!

Currently, the backend engine is already capable of aggregating clients that share the same sub_id into a single subscription link (even if the UI normally prevents duplicate sub IDs, the underlying mechanism still works perfectly). We can just reuse this exact mechanism for Groups.

Proposed Technical Implementation (Backend):

  1. In the database, we just need a new column for group_sub_id (varchar). This can be added either to the client_groups table OR directly to the clients table — whichever is easier to code and requires fewer DB queries.
  2. Point the existing subscription aggregation engine to group clients by this new group_sub_id instead of (or alongside) the individual client's sub_id. Since the clients table already contains the group_name mapping, linking them is straightforward.

Proposed Implementation (Frontend/UI):
We can reuse the existing UI components.
Currently, when you click on a client, the "Client Information" modal pops up, displaying all their inbounds and subscription links. We can reuse this exact modal/logic for Groups. When clicking on a Group, it should open a similar window displaying the new group_sub_id and the aggregated subscription link.

Additional Context:
By reusing the existing aggregation engine and the existing "Client Information" UI modal, this feature can be implemented with minimal code changes while providing a massive quality-of-life improvement for panel admins.

Alternatives you've considered

The only current workaround is to create a single "Client" and share its subscription link across all family devices. But this completely ruins the ability to track traffic statistics per user/device and breaks the whole purpose of the panel's detailed stats.

Concrete use case

No response

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

No response

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @De-naber on GitHub (Jun 30, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5694 ### Is your feature request related to a problem? First of all, thank you for the incredible work! The software is absolutely top-notch, and the recent improvements to the "Groups" functionality in the latest releases are perfect. However, there is a missing piece for a very common real-world scenario. Currently, if I want to provide access to a "Family" (which has multiple users and multiple devices), I have to generate and send a separate subscription link for each client/device. This is quite tedious for the end-user. It would be much more logical and user-friendly to share just one single subscription link for the entire Group. The user's app (v2rayNG, Karing, etc.) would then fetch this group link and automatically get all the inbounds/configs assigned to the clients within that group. ### Describe the solution you'd like Implement a Group Subscription Link. I took a look at the SQLite database structure and the current backend logic, and it seems almost zero new logic needs to be written. The engine already knows how to do this! Currently, the backend engine is already capable of aggregating clients that share the same sub_id into a single subscription link (even if the UI normally prevents duplicate sub IDs, the underlying mechanism still works perfectly). We can just reuse this exact mechanism for Groups. **Proposed Technical Implementation (Backend):** 1. In the database, we just need a new column for group_sub_id (varchar). This can be added either to the client_groups table OR directly to the clients table — whichever is easier to code and requires fewer DB queries. 2. Point the existing subscription aggregation engine to group clients by this new group_sub_id instead of (or alongside) the individual client's sub_id. Since the clients table already contains the group_name mapping, linking them is straightforward. **Proposed Implementation (Frontend/UI):** We can reuse the existing UI components. Currently, when you click on a client, the "Client Information" modal pops up, displaying all their inbounds and subscription links. We can reuse this exact modal/logic for Groups. When clicking on a Group, it should open a similar window displaying the new group_sub_id and the aggregated subscription link. **Additional Context:** By reusing the existing aggregation engine and the existing "Client Information" UI modal, this feature can be implemented with minimal code changes while providing a massive quality-of-life improvement for panel admins. ### Alternatives you've considered The only current workaround is to create a single "Client" and share its subscription link across all family devices. But this completely ruins the ability to track traffic statistics per user/device and breaks the whole purpose of the panel's detailed stats. ### Concrete use case _No response_ ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? _No response_ ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [ ] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 30, 2026):

The technical analysis in this request is broadly accurate, but the implementation scope is somewhat larger than "almost zero new logic." Here is what the code actually shows and what a PR would need to touch.

What already exists

  • ClientGroup struct (internal/database/model/model.go:649-658) has Id, Name, ResetUp, ResetDown, CreatedAt, UpdatedAt. There is no subscription-related field on this table today.
  • Clients carry a Group string field (column group_name) that links them to a group. There is no per-group sub_id equivalent.
  • The subscription engine in internal/sub/service.go aggregates across multiple clients and inbounds via getInboundsBySubId(), which queries WHERE clients.sub_id = ?. The aggregation machinery — including AggregateTrafficByEmails() for unified traffic totals — works and is reusable.
  • Current subscription routes (/sub/{subId}, /json/{subId}, /clash/{subId}) in internal/sub/controller.go are all keyed on a per-client sub_id. There is no group-keyed path.

What a PR would actually need to add

  1. DB schema + migration (internal/database/model/model.go and internal/database/db.go): add a group_sub_id column (unique, nullable) to client_groups, with a corresponding AutoMigrate migration. Without a dedicated token the group name itself cannot safely serve as the URL segment because names are mutable.

  2. New DB query (internal/sub/service.go): a getInboundsByGroupSubId() function parallel to getInboundsBySubId() that joins via clients.group_name = (SELECT name FROM client_groups WHERE group_sub_id = ?) instead of clients.sub_id = ?. The existing AggregateTrafficByEmails() call in getSubs() can then be reused as-is.

  3. New subscription routes (internal/sub/controller.go): route handlers for the group-keyed URL variants, dispatching to the new query. The format (e.g. /sub/g/{groupSubId} or a prefix flag) needs to be decided so it cannot collide with existing per-client sub IDs.

  4. Group API endpoints (internal/web/controller/group.go and frontend/src/pages/api-docs/endpoints.ts): endpoints to generate, display, and revoke a group's sub ID. Per the project rules, every new g.POST/g.GET requires a matching entry in endpoints.ts, followed by make gen.

  5. Frontend UI (frontend/src/): a group-info modal or panel showing the group subscription URL and QR code, analogous to the existing client info modal. Reusing the client info component is a reasonable starting point.

  6. i18n (internal/web/translation/): any new string keys must be added to all 13 locale JSON files.

What the workaround described in the issue breaks

The issuer correctly identifies the core problem: sharing one client across devices collapses per-device traffic tracking. The group subscription approach preserves separate ClientRecord rows and therefore separate client_traffics rows, which is the right design.

Precedent in nearby issues

Issues #4776 (closed) and #5664 (closed) approached related aggregation problems from different angles (shared sub IDs for routing, and a "shell client" container). Neither was implemented; neither is a duplicate of this request.

A PR implementing the above would be a welcome contribution. The complexity is moderate — the aggregation and traffic logic are genuinely reusable — but the schema migration, new routes, endpoints.ts registration, and frontend modal are all required for a complete and mergeable change.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4845184935 --> @github-actions[bot] commented on GitHub (Jun 30, 2026): The technical analysis in this request is broadly accurate, but the implementation scope is somewhat larger than "almost zero new logic." Here is what the code actually shows and what a PR would need to touch. **What already exists** - `ClientGroup` struct (`internal/database/model/model.go:649-658`) has `Id`, `Name`, `ResetUp`, `ResetDown`, `CreatedAt`, `UpdatedAt`. There is no subscription-related field on this table today. - Clients carry a `Group` string field (column `group_name`) that links them to a group. There is no per-group `sub_id` equivalent. - The subscription engine in `internal/sub/service.go` aggregates across multiple clients and inbounds via `getInboundsBySubId()`, which queries `WHERE clients.sub_id = ?`. The aggregation machinery — including `AggregateTrafficByEmails()` for unified traffic totals — works and is reusable. - Current subscription routes (`/sub/{subId}`, `/json/{subId}`, `/clash/{subId}`) in `internal/sub/controller.go` are all keyed on a per-client `sub_id`. There is no group-keyed path. **What a PR would actually need to add** 1. **DB schema + migration** (`internal/database/model/model.go` and `internal/database/db.go`): add a `group_sub_id` column (unique, nullable) to `client_groups`, with a corresponding `AutoMigrate` migration. Without a dedicated token the group name itself cannot safely serve as the URL segment because names are mutable. 2. **New DB query** (`internal/sub/service.go`): a `getInboundsByGroupSubId()` function parallel to `getInboundsBySubId()` that joins via `clients.group_name = (SELECT name FROM client_groups WHERE group_sub_id = ?)` instead of `clients.sub_id = ?`. The existing `AggregateTrafficByEmails()` call in `getSubs()` can then be reused as-is. 3. **New subscription routes** (`internal/sub/controller.go`): route handlers for the group-keyed URL variants, dispatching to the new query. The format (e.g. `/sub/g/{groupSubId}` or a prefix flag) needs to be decided so it cannot collide with existing per-client sub IDs. 4. **Group API endpoints** (`internal/web/controller/group.go` and `frontend/src/pages/api-docs/endpoints.ts`): endpoints to generate, display, and revoke a group's sub ID. Per the project rules, every new `g.POST`/`g.GET` requires a matching entry in `endpoints.ts`, followed by `make gen`. 5. **Frontend UI** (`frontend/src/`): a group-info modal or panel showing the group subscription URL and QR code, analogous to the existing client info modal. Reusing the client info component is a reasonable starting point. 6. **i18n** (`internal/web/translation/`): any new string keys must be added to all 13 locale JSON files. **What the workaround described in the issue breaks** The issuer correctly identifies the core problem: sharing one client across devices collapses per-device traffic tracking. The group subscription approach preserves separate `ClientRecord` rows and therefore separate `client_traffics` rows, which is the right design. **Precedent in nearby issues** Issues #4776 (closed) and #5664 (closed) approached related aggregation problems from different angles (shared sub IDs for routing, and a "shell client" container). Neither was implemented; neither is a duplicate of this request. A PR implementing the above would be a welcome contribution. The complexity is moderate — the aggregation and traffic logic are genuinely reusable — but the schema migration, new routes, `endpoints.ts` registration, and frontend modal are all required for a complete and mergeable change. *This reply was generated automatically; a maintainer may follow up.*
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#3959
No description provided.