# allphaaa77/3x-ui architecture

> Architecture diagram of the GitHub repository allphaaa77/3x-ui, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/allphaaa77/3x-ui
- Repository: https://github.com/allphaaa77/3x-ui

## Overview

3X-UI is a web control panel for configuring and operating Xray proxy servers, from one VPS or across multiple nodes. The main workflow runs from panel users through the frontend and REST API to management services, which persist configuration and apply it to Xray runtimes; clients then receive share links or subscriptions. The graph also preserves monitoring, Telegram, and MTProto capabilities. Relationships among sampled modules use source-index references or excerpts; broader product links are documented in the README, and unsampled implementation details are not inferred.

Main entry points: [`internal/sub/controller.go`](https://github.com/allphaaa77/3x-ui/blob/main/internal/sub/controller.go) (Subscription routes), [`frontend/src/api/http-init.ts`](https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/api/http-init.ts) (API client), [`internal/database/db.go`](https://github.com/allphaaa77/3x-ui/blob/main/internal/database/db.go) (Database), [`internal/web/job/check_client_ip_job.go`](https://github.com/allphaaa77/3x-ui/blob/main/internal/web/job/check_client_ip_job.go) (Traffic and IP limits)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_panel["Web panel"]
  node_frontend["Management UI<br/>[IndexPage.tsx]"]
  node_api["API client<br/>[http-init.ts]"]
  node_web["Web server<br/>[server.go]"]
  node_controllers["API controllers<br/>[client.go]"]
end

subgraph group_management["Management services"]
  node_clientmgmt["Client management<br/>[client_bulk.go]"]
  node_backend["Panel services<br/>[server.go]"]
  node_database[("Database<br/>[db.go]")]
  node_monitor["Traffic and IP limits"]
  node_xrayconfig["Proxy configuration"]
  node_inbounds["Inbound configuration"]
  node_nodes["Multi-node management<br/>[NodesPage.tsx]"]
  node_telegram["Telegram management<br/>[tgbot_router.go]"]
end

subgraph group_runtime["Proxy runtime"]
  node_runtime_mgr["Node runtime dispatch<br/>[manager.go]"]
  node_xray["Xray integration<br/>[api.go]"]
  node_mtproto["MTProto manager<br/>[manager.go]"]
end

subgraph group_delivery["Client delivery"]
  node_subscriptions["Subscription routes<br/>[controller.go]"]
  node_subservice["Subscription generation<br/>[service.go]"]
  node_jsonsub["JSON subscriptions<br/>[json_service.go]"]
  node_clashsub["Clash subscriptions<br/>[clash_service.go]"]
end

node_operator(("Panel user"))
node_fail2ban["Fail2ban"]
node_clients(("Proxy clients"))

node_operator -->|"manages servers"| node_frontend
node_frontend -.->|"requests data"| node_api
node_api -.->|"calls REST API"| node_web
node_web -->|"routes requests"| node_controllers
node_controllers -->|"delegates operations"| node_backend
node_backend -->|"reads and writes"| node_database
node_backend -->|"controls Xray"| node_xray
node_clientmgmt -->|"updates client records"| node_database
node_clientmgmt -->|"applies client changes"| node_xray
node_inbounds -.->|"configures inbounds"| node_api
node_xrayconfig -.->|"configures routing"| node_api
node_nodes -.->|"selects node runtime"| node_runtime_mgr
node_runtime_mgr -->|"loads node records"| node_database
node_monitor -->|"checks client limits"| node_database
node_monitor -->|"checks IP usage"| node_xray
node_web -->|"serves subscription routes"| node_subscriptions
node_subscriptions -->|"builds subscription data"| node_subservice
node_subscriptions -->|"serves JSON format"| node_jsonsub
node_subscriptions -->|"serves Clash format"| node_clashsub
node_subservice -->|"generates share links"| node_clients
node_telegram -->|"supports remote management"| node_operator
node_monitor -->|"enforces IP limits"| node_fail2ban
node_mtproto -.->|"supports MTProto inbounds"| node_xrayconfig

click node_frontend "https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/pages/index/IndexPage.tsx"
click node_api "https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/api/http-init.ts"
click node_web "https://github.com/allphaaa77/3x-ui/blob/main/internal/web/controller/server.go"
click node_controllers "https://github.com/allphaaa77/3x-ui/blob/main/internal/web/controller/client.go"
click node_clientmgmt "https://github.com/allphaaa77/3x-ui/blob/main/internal/web/service/client_bulk.go"
click node_backend "https://github.com/allphaaa77/3x-ui/blob/main/internal/web/service/server.go"
click node_database "https://github.com/allphaaa77/3x-ui/blob/main/internal/database/db.go"
click node_runtime_mgr "https://github.com/allphaaa77/3x-ui/blob/main/internal/web/runtime/manager.go"
click node_xray "https://github.com/allphaaa77/3x-ui/blob/main/internal/xray/api.go"
click node_mtproto "https://github.com/allphaaa77/3x-ui/blob/main/internal/mtproto/manager.go"
click node_monitor "https://github.com/allphaaa77/3x-ui/blob/main/internal/web/job/check_client_ip_job.go"
click node_xrayconfig "https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/pages/xray/routing/useRoutingColumns.tsx"
click node_inbounds "https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/pages/inbounds/form/InboundFormModal.tsx"
click node_nodes "https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/pages/nodes/NodesPage.tsx"
click node_subscriptions "https://github.com/allphaaa77/3x-ui/blob/main/internal/sub/controller.go"
click node_subservice "https://github.com/allphaaa77/3x-ui/blob/main/internal/sub/service.go"
click node_jsonsub "https://github.com/allphaaa77/3x-ui/blob/main/internal/sub/json_service.go"
click node_clashsub "https://github.com/allphaaa77/3x-ui/blob/main/internal/sub/clash_service.go"
click node_telegram "https://github.com/allphaaa77/3x-ui/blob/main/internal/web/service/tgbot/tgbot_router.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend,node_api,node_web,node_controllers,node_operator,node_clients toneBlue
class node_clientmgmt,node_backend,node_database,node_monitor,node_xrayconfig,node_inbounds,node_nodes,node_telegram toneAmber
class node_runtime_mgr,node_xray,node_mtproto toneMint
class node_subscriptions,node_subservice,node_jsonsub,node_clashsub toneRose
class node_fail2ban toneIndigo
```

## Components

### Web panel

- [Management UI](https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/pages/index/IndexPage.tsx): `frontend/src/pages/index/IndexPage.tsx`
- [API client](https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/api/http-init.ts): `frontend/src/api/http-init.ts`
- [Web server](https://github.com/allphaaa77/3x-ui/blob/main/internal/web/controller/server.go): `internal/web/controller/server.go`
- [API controllers](https://github.com/allphaaa77/3x-ui/blob/main/internal/web/controller/client.go): `internal/web/controller/client.go`

### Management services

- [Client management](https://github.com/allphaaa77/3x-ui/blob/main/internal/web/service/client_bulk.go): `internal/web/service/client_bulk.go`
- [Panel services](https://github.com/allphaaa77/3x-ui/blob/main/internal/web/service/server.go): `internal/web/service/server.go`
- [Database](https://github.com/allphaaa77/3x-ui/blob/main/internal/database/db.go): `internal/database/db.go`
- [Traffic and IP limits](https://github.com/allphaaa77/3x-ui/blob/main/internal/web/job/check_client_ip_job.go): `internal/web/job/check_client_ip_job.go`
- [Proxy configuration](https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/pages/xray/routing/useRoutingColumns.tsx): `frontend/src/pages/xray/routing/useRoutingColumns.tsx`
- [Inbound configuration](https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/pages/inbounds/form/InboundFormModal.tsx): `frontend/src/pages/inbounds/form/InboundFormModal.tsx`
- [Multi-node management](https://github.com/allphaaa77/3x-ui/blob/main/frontend/src/pages/nodes/NodesPage.tsx): `frontend/src/pages/nodes/NodesPage.tsx`
- [Telegram management](https://github.com/allphaaa77/3x-ui/blob/main/internal/web/service/tgbot/tgbot_router.go): `internal/web/service/tgbot/tgbot_router.go`

### Proxy runtime

- [Node runtime dispatch](https://github.com/allphaaa77/3x-ui/blob/main/internal/web/runtime/manager.go): `internal/web/runtime/manager.go`
- [Xray integration](https://github.com/allphaaa77/3x-ui/blob/main/internal/xray/api.go): `internal/xray/api.go`
- [MTProto manager](https://github.com/allphaaa77/3x-ui/blob/main/internal/mtproto/manager.go): `internal/mtproto/manager.go`

### Client delivery

- [Subscription routes](https://github.com/allphaaa77/3x-ui/blob/main/internal/sub/controller.go): `internal/sub/controller.go`
- [Subscription generation](https://github.com/allphaaa77/3x-ui/blob/main/internal/sub/service.go): `internal/sub/service.go`
- [JSON subscriptions](https://github.com/allphaaa77/3x-ui/blob/main/internal/sub/json_service.go): `internal/sub/json_service.go`
- [Clash subscriptions](https://github.com/allphaaa77/3x-ui/blob/main/internal/sub/clash_service.go): `internal/sub/clash_service.go`

### Other components

- **Panel user**
- **Fail2ban**
- **Proxy clients**

## Connections

- Panel user → Management UI: manages servers (evidence: `README.md`)
- Management UI → API client: requests data
- API client → Web server: calls REST API
- Web server → API controllers: routes requests (evidence: `internal/web/controller/server.go`)
- API controllers → Panel services: delegates operations
- Panel services → Database: reads and writes (evidence: `internal/web/service/server.go`)
- Panel services → Xray integration: controls Xray (evidence: `internal/web/service/server.go`)
- Client management → Database: updates client records (evidence: `internal/web/service/client_bulk.go`)
- Client management → Xray integration: applies client changes (evidence: `internal/web/service/client_bulk.go`)
- Inbound configuration → API client: configures inbounds
- Proxy configuration → API client: configures routing
- Multi-node management → Node runtime dispatch: selects node runtime
- Node runtime dispatch → Database: loads node records (evidence: `internal/web/runtime/manager.go`)
- Traffic and IP limits → Database: checks client limits (evidence: `internal/web/job/check_client_ip_job.go`)
- Traffic and IP limits → Xray integration: checks IP usage (evidence: `internal/web/job/check_client_ip_job.go`)
- Web server → Subscription routes: serves subscription routes (evidence: `README.md`)
- Subscription routes → Subscription generation: builds subscription data (evidence: `internal/sub/controller.go`)
- Subscription routes → JSON subscriptions: serves JSON format (evidence: `internal/sub/controller.go`)
- Subscription routes → Clash subscriptions: serves Clash format (evidence: `internal/sub/controller.go`)
- Subscription generation → Proxy clients: generates share links (evidence: `README.md`)
- Telegram management → Panel user: supports remote management (evidence: `README.md`)
- Traffic and IP limits → Fail2ban: enforces IP limits (evidence: `README.md`)
- MTProto manager → Proxy configuration: supports MTProto inbounds
