Architecture

Recommended XyPriss Project Architecture

A production-ready structure for both single-server and multi-server deployments, designed for scalability, security, and maintainability.

Quick Bootstrap with xfpm init
The sections below walk through the manual setup to explain how each layer fits together. To scaffold this clean, pre-configured architecture automatically in seconds, run:
bash
xfpm init

Multi-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.

Enterprise Modular XMS Topology
The recommended multi-server setup splits the application into three dedicated nodes resolved from 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
How They Work Together
All three server nodes share the underlying native XHSC engine while remaining isolated at the HTTP and security boundary layer. src/router.ts dispatches requests by both URL prefix and serverId: /api/* to mainServer, /auth/* to authServer, and /cdn/* to cdnServer.

Recommended Project Structure

my-xypriss-app
package.json
tsconfig.json
xypriss.config.jsonc
src
server.ts
router.ts
configs
servers
routes
controller
services
guards
db
schemas
types
const
utils

Initialization Flow

Declare Environment & Server Topology (xypriss.config.jsonc)

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)

typescript
// 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)

typescript
// 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();
Why This Architecture?
Strict Separation of Concerns: Routes, controllers, services, guards, and schemas live in dedicated layers. Zero-Trust by Default: Environment access is whitelisted in 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():

Execution & Boot Lifecycle

XyPriss Runtime Flow (xfpm dev → app.start())

Layered architecture from CLI supervision and libXESS confinement to application bootstrap and the native libSynapx control plane.

Layer 1CLI & Dev Orchestration
xfpm dev
1. User Command

Invokes xfpm dev (alias xfpm run dev) with automatic target & runtime detection (Bun / Node.js).

2. Project Discovery

Resolves project root (package.json, .env, xypriss.config.jsonc) and active execution profile.

3. Hot-Reload Supervisor

Watches source files and orchestrates controlled, zero-orphan restart cycles.

Layer 2Confinement Envelope & Memory Vault
libXESS
4. Isolated Memory Vault

Loads .env secrets exclusively into supervisor memory and scrubs the child runtime environment.

5. File Shield & Canary Decoy

Intercepts direct .env filesystem reads and transparently serves synthetic canary decoys.

6. Confined Runtime Launch

Spawns the supervised child process with anti-inspection bounds and an authenticated session channel.

Layer 3JS/TS Runtime & Bootstrap
import "xypriss"
7. Envelope Verification

Verifies active libXESS confinement on boot (throws XessShieldRequiredError if unconfined).

8. process.env Shield

Enforces system whitelists, audit logging, and scoped package sandboxes ($env.packages).

9. __sys__.__env__ API

Provides caller-scoped secret retrieval via get(), getStrict(), and zeroizable withSecret().

Layer 4Application Construction
createServer, Routes, Guards, Plugins
10. Config & Factory

createServer(configs) resolves &(env).KEY interpolations and Single or Multi-Server (XMS) topology.

11. App Topology

Mounts routers (app.use), middlewares, XyGuard security rules, and sandboxed XStatic routes.

12. Plugin Manager

Registers plugins, isolates execution contexts, and prepares lifecycle hooks.

Layer 5Startup Orchestration
app.start()
13. Mode Dispatch

app.start() evaluates execution mode (Cluster Worker vs. Primary / Single Instance).

14a. Worker Branch

In cluster mode, attaches the worker to the libSynapx IPC pool and maintains the event loop.

14b. Primary / Single Branch

Cleans stale endpoints and delegates native network engine startup to XHSC.

15. Hooks & Readiness

Executes "onServerReady" plugin hooks and invokes the app.start(cb) readiness callback.

Layer 6Native Control Plane & IPC Bus
libSynapx ↔ System Services
Authenticated IPC Bus (libSynapx)

Persistent bidirectional binary transport between JS workers and the native Go core.

Vault Service (env)

Serves authenticated secret reads and ephemeral byte transfers backed by the libXESS vault.

System & Lifecycle Services

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.

Multi-Server Setup

Configure per-instance response control and route isolation with XMS.