Chapter 1 / 51
Volume 1 · Getting Started & Mental Model (opening)

Introduction: what XServer is and how to read this book

Volume 1 builds the three concepts that run through the whole book — generations, leases and reclaim-at-zero. This chapter answers the most fundamental question first: what exactly XServer is, and which step of "writing a server" it changes.

Overview

Positioning: no code in this chapter — only judgment. After reading you can state precisely what a XServer deployment artifact is, how it differs from your current stack, and which volumes of this book matter to you. If you have already run the demo and understand "source code is the deployment", skim 1.1 and 1.3 and jump to chapter 2.

One-sentence definition first:

XServer is a single-file C application server: one executable (compiler and runtime embedded) plus one plain C source directory is a complete, hot-reloadable server-side deployment.

Three keywords in that sentence map to the three story lines of this book: single file (runtime and toolchain fully embedded — volume 2 covers build and delivery), C source directory (the application is the source itself, not a prebuilt artifact — volumes 1 and 3 cover how to write it), and hot reload (edit code with zero downtime — volume 4 dives deep).

1.1 What XServer is

Traditional C server development goes "write code → compile → link → deploy the binary → restart", and every business change walks the whole pipeline. XServer folds that pipeline into the runtime: what you place on the target machine is a source directory as the deployment artifact; xs.exe compiles your C code into native machine code with the embedded TCC compiler at startup and on every hot reload, and runs it in-process.

Deployment artifact comparison
/* Traditional C server */
myapp/  →  build pipeline  →  myapp.exe + dependency list  →  install deps on target  →  restart

/* xs */
myapp/  =  xs.exe (the only binary; compiler/runtime/SDK embedded)
        + main.c + modules/ + wwwroot/ + db/ (source is the deployment)
        →  copy to deploy, edit source to hot reload

This is not a toy "C as scripting" scheme but a deliberate engineering trade: scripts are trusted native code, in-process with the host, calling the host's 3,030 xrt APIs by address — no interpreter overhead, no FFI boundary; a function call is just a function call. The price is no sandbox: XServer targets operator-controlled trusted deployments and does not accept untrusted third-party scripts (this boundary is explored in chapter 44, volume 5).

Underneath sits xrt — a 310k-line in-house runtime (TLS 1.2/1.3, HTTP/1.1, WebSocket, a five-backend event loop, coroutines, memory debugging). This book does not re-teach xrt: where xrt fundamentals matter, the "further reading" box at the chapter end links to the matching chapters of the xrt book.

1.2 Compared with alternatives

StackDeploymentBusiness logicCost of a one-line change
nginx + modulesbinary + heavy configmostly config; C modules need a rebuildconfig reload; modules rebuild all of nginx
Node / Go servicesruntime + source or binaryJS / Go, package ecosystemsprocess restart (PM2/supervisor)
Traditional C serveryour own build pipelineC, built in-house or third-party libscompile + deploy + downtime window
XServerone exe + a source directoryC, calling 3,030 embedded APIs directlysubmit a hot reload; old connections never notice

The difference in one sentence: other stacks manage "the runtime" and "your code" as two separate things; XServer packs them into the same file, the same process, and the same lifecycle.

1.3 Roadmap of the book

The XServer Book (5 volumes, 51 chapters) Vol. 1 Start & mental model Vol. 2 Config & assembly ┌──────────────────┐ ┌──────────────────┐ │ generations·lease│ ───▶ │ xs.json field │ │ minimal app·debug│ │ vhost·certs·roll │ └──────────────────┘ └────────┬─────────┘ │ ┌──────────────────┐ ┌────────▼─────────┐ │ Vol. 5 Projects │ ◀─── │ Vol. 3 Protocols │ │ REST·gw·farms │ │ HTTP·WS·TCP·UDP │ └──────────────────┘ └────────┬─────────┘ ┌────────▼─────────┐ │ Vol. 4 Hot reload│ │ swap·GC·anti-pat │ └──────────────────┘
  • Volume 1 (ch. 01–06): mental model and toolchain. The three essential chapters are 03 (mental model), 04 (minimal app) and 06 (debugging).
  • Volume 2 (ch. 07–13): xs.json is the single assembly surface — every field, constraint and error semantic.
  • Volume 3 (ch. 14–25): development patterns for the four protocol classes; pick yours.
  • Volume 4 (ch. 26–31): hot reload from "can trigger it" to "understand the semantics" — rollback, handover, zero leaks.
  • Volume 5 (ch. 32–43): the extension system, deployment and ops, security boundaries, and three end-to-end projects.

1.4 The chapter template contract

All 51 chapters follow the same eight-part structure. Chapter 1 turns the template into a contract — any later chapter that violates it counts as a chapter defect, not a style choice:

#NamePurpose
1OverviewWhere the chapter sits, learning strategy, whether it can be skimmed
2Intro (N.1)Starts from a real pain point, never from an API list
3Concepts (N.2)Mental models, comparison tables, flow / state diagrams
4Examples (N.3)The five-piece set: file name + provenance + run command + real output + "what just happened"
5Contract (N.4)The hard rules: threading / ownership / lifecycle
6Common mistakesSymptom → cause → wrong-way / right-way side by side
7ExercisesThree levels (basic / advanced / challenge), each with acceptance criteria
8SummaryA cheatsheet reviewing every conclusion of the chapter in one screen

Every chapter ends with two fixed boxes: APIs covered in this chapter (linking to this book's reference pages with entry counts) and xrt further reading (linking to the xrt book). Every code block tagged "verified on a real machine" shows genuinely captured output — including unforgeable details like dynamic ports and real timestamps.

1.5 Reader paths

Who you areSuggested path
Backend developerVol. 1 → Vol. 3 by protocol → Vol. 4 (must) → Vol. 5 projects
Ops / deploymentch. 01–02 → Vol. 2 → ch. 42–39
Evaluatorch. 01–04 + the benchmark + ch. 44 (security boundaries)
ContributorRead cover to cover; fill xrt gaps via the further-reading boxes

Common mistakes

Looking for an admin panel / xsdbg
Symptom
After startup you try an admin endpoint like __xs/status for inspection and get a 404.
Cause
That was a built-in debug app of the historical (vnext-era) line. The current XServer mainline deliberately ships no management plane — the host provides the protocol stack, the script host and stability guarantees; the management plane belongs to the application layer.
✗ Wrong assumption
curl http://127.0.0.1:9080/__xs/status
/* expecting a built-in admin endpoint → 404 */
✓ Right way
/* Write admin routes in your own script:
 * inspection / reload endpoints are ordinary business routes */

Exercises

BasicInventory your migration surface

List the components of one of your live services (routing, static assets, database, scheduled jobs, certificates) and tag each: after migrating to XServer, which xs.json field does it map to, which part of the app directory, or which module you would write yourself.

Acceptance: every item classifies into one of "config / static layer / script module / built-in xrt capability" — nothing left dangling as "not sure".
AdvancedExtend the comparison table

Add the framework you actually use (e.g. Spring / FastAPI / Gin) to the 1.2 table and fill in the three columns: deployment artifact / business logic / cost of a one-line change.

Acceptance: you can point at where "runtime and business code" couple in each stack.

Summary

PointConclusion
DefinitionA single-file C application server: one exe + one source directory = a complete deployment
DeploymentSource is the deployment; the embedded TCC compiles to native code, zero interpreter
Capability surfaceScripts call 3,030 xrt APIs by address; no sandbox — built for trusted operations
Book structure5 volumes, 51 chapters; the eight-part template is a contract
xrt splitFundamentals deep-link into the xrt book; this book covers the XServer layer only
xrt further reading