Recommended XyPriss Project Architecture
A production-ready structure for both single-server and multi-server deployments, designed for scalability, security, and maintainability.
xfpm initMulti-Server Architecture
XyPriss Multi-Server (XMS) allows you to run multiple isolated server instances within a single Node.js process. Each instance has its own port, security policy, plugin set, and route scope. This is the recommended architecture for production workloads that require separation between public access, authentication, and administrative surfaces.
xypriss.config.jsonc: api (primary REST API), auth (authentication & identity), and cdn (media & sandboxed static assets).api.server.ts
- Node:
servers.main - Prefix:
/api,/ - Scope: Core REST API & business services
auth.server.ts
- Node:
servers.auth - Prefix:
/auth,/api - Scope: Login, registration, RBAC & tokens
cdn.server.ts
- Node:
servers.cdn - Prefix:
/cdn - Scope: XStatic sandboxed uploads & media
src/router.ts dispatches requests by both URL prefix and serverId: /api/* to mainServer, /auth/* to authServer, and /cdn/* to cdnServer.Recommended Project Structure
Initialization Flow
Declare Environment & Server Topology (xypriss.config.jsonc)
// xypriss.config.jsonc
{
"$env": {
"whitelist": ["NODE_ENV", "PORT"]
},
"$vars": {
"servers": {
"auth": { "port": "&(env).AUTH_SERVER_PORT || 9182", "id": "&(env).AUTH_DOMAIN || rest.auth.domain.com" },
"main": { "port": "&(env).MAIN_SERVER_PORT || 1822", "id": "&(env).MAIN_DOMAIN || rest.api.domain.com" },
"cdn": { "port": "&(env).CDN_SERVER_PORT || 5829", "id": "&(env).CDN_DOMAIN || rest.cdn.domain.com" }
}
}
}Bind Multi-Server Router (src/router.ts)
// src/router.ts
import { Router } from "xypriss";
import { apiRouter } from "./routes/api.route";
import { authRouter } from "./routes/auth.route";
import { cdnRouter } from "./routes/cdn.route";
import { mainServer } from "./servers/api.server";
import { authServer } from "./servers/auth.server";
import { cdnServer } from "./servers/cdn.server";
const r = Router();
r.group({ prefix: ["/api", "/"], serverId: mainServer.id }, (api) => {
api.use("/", apiRouter);
});
r.group({ prefix: ["/auth", "/api"], serverId: authServer.id }, (auth) => {
auth.use("/", authRouter);
});
r.group({ prefix: "/cdn", serverId: cdnServer.id }, (cdn) => {
cdn.use("/", cdnRouter);
});
export { r as router };Bootstrap Guards, Router, XStatic & Start (src/server.ts)
// src/server.ts
import { createServer, XStatic } from "xypriss";
import { serverConfigs } from "./configs/xypriss.config";
import { router } from "./router";
import { guardsRunner } from "./guards/index.guard";
import { permanentCdnPath, publicCdnPath, publicCdnTmpPath } from "./const/cdnPaths";
const app = createServer(serverConfigs);
// 1. Register global XyGuard rules
guardsRunner();
// 2. Mount central multi-server routing topology
app.use("/", router);
// 3. Sandboxed static asset & temp upload delivery via XStatic
const xs = new XStatic(app, __sys__);
xs.define(publicCdnTmpPath, __sys__.path.tmpUserDir, {
allowOutsideRoot: true,
allowOutsideDir: false,
});
xs.define(publicCdnPath, permanentCdnPath, {
allowOutsideRoot: false,
allowOutsideDir: false,
});
// 4. Start all configured XMS server nodes
app.start();xypriss.config.jsonc, guards are registered globally via XyGuard, and temporary storage is sandboxed inside __sys__.path.tmpUserDir with XStatic.Execution & Boot Lifecycle
Whether running in Single-Server or Multi-Server (XMS) mode, every XyPriss application follows the same deterministic, Zero-Trust boot sequence from xfpm dev supervision through app.start():
XyPriss Runtime Flow (xfpm dev → app.start())
Layered architecture from CLI supervision and libXESS confinement to application bootstrap and the native libSynapx control plane.
xfpm devInvokes xfpm dev (alias xfpm run dev) with automatic target & runtime detection (Bun / Node.js).
Resolves project root (package.json, .env, xypriss.config.jsonc) and active execution profile.
Watches source files and orchestrates controlled, zero-orphan restart cycles.
libXESSLoads .env secrets exclusively into supervisor memory and scrubs the child runtime environment.
Intercepts direct .env filesystem reads and transparently serves synthetic canary decoys.
Spawns the supervised child process with anti-inspection bounds and an authenticated session channel.
import "xypriss"Verifies active libXESS confinement on boot (throws XessShieldRequiredError if unconfined).
Enforces system whitelists, audit logging, and scoped package sandboxes ($env.packages).
Provides caller-scoped secret retrieval via get(), getStrict(), and zeroizable withSecret().
createServer, Routes, Guards, PluginscreateServer(configs) resolves &(env).KEY interpolations and Single or Multi-Server (XMS) topology.
Mounts routers (app.use), middlewares, XyGuard security rules, and sandboxed XStatic routes.
Registers plugins, isolates execution contexts, and prepares lifecycle hooks.
app.start()app.start() evaluates execution mode (Cluster Worker vs. Primary / Single Instance).
In cluster mode, attaches the worker to the libSynapx IPC pool and maintains the event loop.
Cleans stale endpoints and delegates native network engine startup to XHSC.
Executes "onServerReady" plugin hooks and invokes the app.start(cb) readiness callback.
libSynapx ↔ System ServicesPersistent bidirectional binary transport between JS workers and the native Go core.
Serves authenticated secret reads and ephemeral byte transfers backed by the libXESS vault.
Manages process supervision, __sys__.fs, telemetry, and XHSC engine lifecycle.
Note: Low-level XHSC HTTP transport details (TLS, socket listeners, wire transcoding) and private confinement internals are abstracted from this lifecycle overview.
Configure per-instance response control and route isolation with XMS.
