P-Node is a lightweight Xray node managed by P-Manager written in Go. It runs Xray binary, exposes a small HTTP API for stats/config updates, and persists settings in a JSON file store.
cmd: Cobra commandsconfigs: Configuration filesinternal/app: App lifecycle orchestrationinternal/config: Configuration loader, constants, and pathsinternal/coordinator: Periodic sync between current state, local Xray process, and P-Managerinternal/data: database schema, models and default valuesinternal/http: Echo HTTP server, routes, and API handlerspkg/database: Simple generic file-backed JSON storepkg/http/client: HTTP clientpkg/http/middleware: Shared middleware used in this project and P-Managerpkg/http/validator: Echo validator implementation based ongo-playground/validatorpkg/logger: A logging wrapper aroundzaploggerpkg/util: Generic utilspkg/worker: Simple worker implementation for periodic taskspkg/xray: Xray wrapper (Xray process lifecycle, config model, gRPC stats)scripts: Scripts for project and server setupstorage: Application data storage directorythird_party: Third-party binaries and libraries
main.go→cmd/root.go(Cobra) →cmd/serve.go.internal/app.New(): Builds config, logger, database, xray, http server, http client, coordinator, and other modules.App.Run(): Initializes and runs long-running modules like database, xray, coordinator, and http server, etc.- Signals handled in
internal/app/app.goto stop gracefully.
- Database is simple file-backed JSON store
- Database driver is
pkg/database - Database schema is defined in
internal/data/data.go - Database directory path is defined in
internal/config/config.goasDatabaseDirectory - Database file path is
$DatabaseDirectory/data.json
- All handlers are located in
internal/http/handlers - Requests and responses are in JSON format
- Authentication is token-based, token is stored in database (
http_tokenininternal/data/settings.go) - Header
Authorization: Bearer <token>is checked for authenticated routes
github.com/xtls/xray-core: Interaction with running Xray processgithub.com/labstack/echo: HTTP server and routergithub.com/spf13/cobra: CLI frameworkgithub.com/go-playground/validator: Validating config modelsgithub.com/cockroachdb/errors: Errors and stacktracego.uber.org/zap: Logging
pkg/http/clientskips TLS verification (intentionally).settings.http_tokenis generated randomly on first run (seeinternal/data/settings.go).make updateis destructive (git reset --hard+git clean -fd).- Use Java-style camelCase for namings (
UserIdinstead ofuserID,clientIdisclientID, etc.)
Xray is a proxy platform which can be used to run proxy servers. with different protocols like Shadowsocks, VMess, VLess, Socks, etc. It supports chain of proxies. The high level flow is:
[ Client ] -> [ Xray on Server 1 ] -> [ Xray on Server 2 ] -> Internet
Each xray node receives traffic on its inbound port and forwards it to the next node in the chain. Based on the routing rules and balancers it forwards traffic to the appropriate outbound.
Xray provides a reverse proxy feature that allows a connection to be initiated from the next node back to the previous node. This is particularly useful when the previous node is behind a firewall (such as the GFW) that restricts outbound connections to the network where the next node resides.
- Keep it simple stupid.
- Prefer small, inline improvements; keep architecture intact.