How zamibd/zpanel works
1. Overall shape
ZPanel is a Go-based control plane for Sing-Box with a separate Vue 3 + Vite frontend. The backend exposes an admin API, serves the web panel, and also exposes a customer-facing subscription service. The system is organized around configuration management, runtime control of Sing-Box, persistence, and traffic/statistics tracking.
2. Main runtime entry points
The top-level main.go and app/ / core/ packages form the server bootstrap path. config/ holds application configuration and version/name metadata. cmd/ contains CLI-oriented operations, including settings and migrations, suggesting the binary can initialize or upgrade stored state outside the normal web runtime.
3. Backend request surfaces
There are three major HTTP-facing areas:
- web/ for serving the panel assets,
- api/ for the admin API,
- sub/ for subscription endpoints that produce link/json output for customers.
The README’s default panel path and customer path map directly to these surfaces.
4. Frontend subsystem
frontend/ is a standalone SPA built with Vue, TypeScript, and Vuetify. It is organized by domain views such as Inbounds, Outbounds, Rules, Tls, Services, and Settings, plus modal editors for each object type. The UI talks to the backend through frontend/src/plugins/api.ts, so the frontend is a thin consumer of the backend API rather than a separate domain service.
5. Domain/service layer
The service/ package is the main application logic layer. It appears to group operations by domain object: clients, config, endpoints, inbounds, outbounds, services, settings, TLS, users, warp, and panel/server orchestration. This is the layer the API handlers likely call after auth/validation, keeping HTTP concerns separate from business rules.
6. Sing-Box integration and core control
The core/ package is the bridge to the underlying proxy engine. Files like register.go, register_gvisor.go, and register_nogvisor.go suggest pluggable runtime registration depending on whether gVisor support is available. core/endpoint.go, core/box.go, core/main.go, and tracker files indicate this layer manages the Sing-Box process/runtime, endpoints, and live connection/statistics reporting.
7. Persistence and models
The database/ package contains DB access plus structured models for endpoints, inbounds, outbounds, and services. This is the system-of-record for panel state. database/backup.go indicates built-in backup/restore support, and cmd/migration/ shows schema or data migrations are first-class parts of the architecture.
8. Traffic and usage observability
Traffic tracking is split across core/tracker_conn.go, core/tracker_stats.go, service/stats.go, and cronjob/. The panel is not just a configuration UI; it continuously observes live clients/inbounds/outbounds and aggregates usage into visible stats. The frontend has dedicated tiles and history components for these metrics.
9. Background maintenance
cronjob/ contains scheduled jobs such as core checking, stats collection, stats deletion, and quota depletion. This indicates a periodic maintenance loop running alongside the API server, responsible for keeping counts accurate and enforcing time/traffic limits on clients.
10. Subscription generation subsystem
The sub/ package generates customer subscription artifacts in multiple formats: link-based, JSON-based, Clash-oriented, and subscription service handlers. util/ includes helpers such as link encoding, base64, and JSON conversion that support this export pipeline. This is a key boundary: internal panel configuration is transformed into externally consumable subscription outputs.
11. Networking and TLS handling
network/auto_https_* and middleware/domainValidator.go suggest the backend can manage HTTPS/TLS concerns for the panel/subscription endpoints and validate host/domain usage. This aligns with the README’s support for self-provided domain + SSL certificate and secure access to both admin and customer endpoints.
12. API/auth/session boundary
The api/ package includes handlers, API service code, session handling, and versioned endpoints (apiV2Handler.go). This suggests request authentication/session state is centralized before delegating to services. The presence of middleware implies cross-cutting validation is applied at the HTTP boundary rather than inside domain services.
13. Deployment and packaging
The repo includes Dockerfile, docker-compose.yml, install.sh, build.sh, and systemd service files (ZPanel.service, ZPanel.sh). This is designed for self-hosted deployment, with the backend and frontend packaged together into a panel service, and Sing-Box integrated as an external/runtime dependency controlled by the panel.
14. Diagramming guidance
For an architecture diagram, the most important flows are:
- Browser/UI → web/ static assets → api/ / sub/
- api/ → service/ → database/ and core/
- cronjob/ → service/ / core/ / database/
- sub/ → util/ transformation helpers → subscription outputs
- core/ → Sing-Box runtime / trackers / connection stats
The cleanest boundaries are: presentation, API/auth, domain services, Sing-Box runtime control, persistence, subscription export, and background jobs.
Main entry points: apiHandler.go Admin API · sub.go Sub export · db.go Database · app.go App bootstrap
Components 31
Backend entrypoints
Process bootstrap, CLI, and config setup
- Main · Top-level process start for the panel binary
main.go - App bootstrap · Initial application setup and server assembly
app/app.go - Config · App naming, versioning, and runtime configuration
config/config.go - CLI entry · Command-line operations for setup and maintenance
cmd/cmd.go - Migrations · Versioned database or state migration entrypoint
cmd/migration/main.go
HTTP surfaces
Admin API, web hosting, and customer subscription endpoints
- Web host · Serves the built panel assets
web/web.go - Admin API · Primary authenticated admin request handlers
api/apiHandler.go - API v2 · Versioned admin endpoints
api/apiV2Handler.go - Session · Session and login state management
api/session.go - Sub handler · Customer-facing subscription request handling
sub/subHandler.go
Domain services
Application logic organized by panel domain
- Panel svc · High-level panel coordination and lifecycle logic
service/panel.go - Config svc · Configuration assembly and transformation services
service/config.go - Inbounds · Inbound object operations and validation
service/inbounds.go - Outbounds · Outbound object operations and validation
service/outbounds.go - Endpoints · Endpoint lifecycle and panel exposure logic
service/endpoints.go - Stats svc · Usage aggregation and statistics queries
service/stats.go - Users · User and admin account operations
service/user.go
Runtime and data
Sing-Box control, persistence, and telemetry
- Database · Storage access and system-of-record management
database/db.go - Backup · Backup and restore support for stored state
database/backup.go - Core runtime · Bridge to the underlying Sing-Box process/runtime
core/main.go - Box · Sing-Box lifecycle and process control
core/box.go - Tracker stats · Live connection and usage statistics collection
core/tracker_stats.go - Sub export · Transforms panel data into external subscription artifacts
sub/sub.go - Link export · Builds subscription links
sub/linkService.go - JSON export · Builds JSON subscription output
sub/jsonService.go - Clash export · Builds Clash-oriented subscription output
sub/clashService.go
Background jobs
Periodic maintenance and enforcement tasks
Frontend
Vue single-page panel UI
- Panel UI · Single-page administration interface
frontend/src/App.vue - API client · Frontend API access layer
frontend/src/plugins/api.ts - Views · Main panel screens for admins and configuration
frontend/src/views/Home.vue
Connections 36
- Main → App bootstrap: bootstraps · Process start wires the application
- Main → Config: loads · Reads app configuration and version metadata
- Main → CLI entry: invokes CLI · Supports administrative command-line entrypoints
- CLI entry → Migrations: runs · CLI can trigger migrations and setup tasks
- App bootstrap → Web host: serves UI · Hosts the static web panel
- App bootstrap → Admin API: mounts · Registers admin API handlers
- App bootstrap → Sub handler: mounts · Registers subscription endpoints
- Admin API → Session: authenticates · API requests rely on session state
- Admin API → API v2: routes · Dispatches versioned endpoint handlers
- Admin API → Panel svc: calls · Delegates business operations to services
- Admin API → Inbounds: calls · Manages inbound objects through service layer
- Admin API → Outbounds: calls · Manages outbound objects through service layer
- Admin API → Endpoints: calls · Manages endpoints through service layer
- Admin API → Users: calls · Admin/user operations flow through services
- Panel svc → Core runtime: controls runtime · Panel orchestration reaches Sing-Box control
- Config svc → Database: reads/writes · Configuration state is persisted
- Inbounds → Database: reads/writes · Inbound definitions are stored in the database
- Outbounds → Database: reads/writes · Outbound definitions are stored in the database
- Endpoints → Database: reads/writes · Endpoint state is persisted
- Stats svc → Tracker stats: collects · Stats service consumes live runtime telemetry
- Core runtime → Box: runs · Core layer manages the Sing-Box process
- Core runtime → Database: loads state · Runtime uses persisted configuration and models
- Core runtime → Tracker stats: emits stats · Runtime exposes live traffic and connection tracking
- Cron jobs → Stats job: schedules · Scheduler triggers periodic stats jobs
- Stats job → Stats svc: updates · Background jobs refresh aggregated statistics
- Stats job → Database: maintains · Periodic maintenance updates stored counters and quotas
- Sub handler → Sub export: delegates · Subscription HTTP layer uses export pipeline
- Sub export → Link export: formats · Generates link-based subscription output
- Sub export → JSON export: formats · Generates JSON subscription output
- Sub export → Clash export: formats · Generates Clash-compatible output
- Sub export → Config svc: reads config · Subscription output is derived from panel configuration
- Sub export → Database: reads state · Subscription exports depend on persisted objects
- Panel UI → API client: calls · UI uses the frontend API client
- API client → Admin API: requests · Frontend talks to the admin API
- Views → API client: consumes · Views load and mutate data through the API layer
- Views → Panel UI: renders in · Screens compose the main application shell