How vaxilu/x-ui works
Project type and purpose
• From the README and file structure, x-ui is a full-stack web panel (monolithic Go application) to manage the Xray proxy engine.
• Frontend: static Vue/Ant-Design/Element-UI assets under web/assets.
• Backend: Go HTTP server, MVC-style controllers/services, data access (SQLite via database/db.go), job schedulers, and Xray process management.
• It also bundles the Xray binaries (bin/xray-*), supports SSL cert issuance (via Cloudflare DNS API), and can run as a systemd service or in Docker.
File structure
• Top-level:
• main.go: application entrypoint
• config/: configuration loading
• database/: DB connection + model definitions
• util/: common helpers (error handling, JSON, reflection, syscalls)
• logger/: logging
• web/: MVC implementation –
– web/controller/: HTTP handlers
– web/service/: business logic
– web/entity/ & web/global/: shared types/globals
– web/html/: HTML templates
– web/assets/: frontend dependencies and JS models
– web/job/: background jobs for stats, health checks
– web/session/: session management
– web/network/: TLS listener wrapper
• xray/: wrappers to start/stop Xray engine, traffic capture
• v2ui/: migration helpers from v2-ui
• Deployment: Dockerfile, install.sh, x-ui.service
Key points from README
• Multi-protocol support, multi-user, traffic monitoring, SSL automation.
• Installation via script, manual instructions or Docker.
• Uses Let’s Encrypt + Cloudflare DNS for certs.
• Data stored locally (likely SQLite under /etc/x-ui/db/).
a. Main components
1. User’s Browser (HTTPS)
2. Frontend Static Server (built-in Go HTTP serving web/assets + templates)
3. Go Backend
– HTTP Router → Controllers → Services
– DB Layer (SQLite or file-based DB)
– Job Scheduler (periodic jobs)
– Xray Manager (spawns Xray processes, reads/writes bin/xray-*)
– SSL Manager (invokes ACME via Cloudflare API)
4. Data Store (SQLite file)
5. Xray Engine processes (child processes)
6. External Services
– Cloudflare DNS API (for certs)
– Let’s Encrypt CA
– (Optional) Telegram Bot API
b. Relationships & data flows
• Browser → HTTPS → Go HTTP Server
• HTTP Server → Controller → Service → DB (read/write configs, users, traffic stats)
• Control commands → Xray Manager → spawn/kill Xray process
• Periodic jobs → gather Xray traffic logs → write stats to DB
• SSL Manager → Cloudflare DNS API ↔ Let’s Encrypt → certificates saved to filesystem
• Backend serves updated certs to frontend or rebinds HTTPS listener
• (Optional) Jobs push notifications via Telegram API
c. Architectural patterns
• Monolithic layered architecture
• MVC (Controllers → Services → Data Access)
• Embedded static assets
• Process-wrapper pattern for managing external Xray engine
• Job scheduling for background tasks
d. Key technologies/frameworks
• Language: Go
• Frontend: Vue.js, Ant-Design-Vue, Element-UI
• DataStore: SQLite (via Go’s database/sql)
• SSL: ACME (Let’s Encrypt) + Cloudflare DNS API
• Process control: Go os/exec for Xray
• Deployment: systemd, Docker
Detail
• Subcomponent (Controllers, Services, Jobs) if clarity is needed.
• Filesystem mounts for Docker or path locations for configs/db.
• Service lifecycle: install.sh → systemd → x-ui binary → loads config → serves UI & manages Xray.
• Don’t overload—focus on logical separation of UI, API, data, engine management, and external integrations.