Skip to content

Package lifecycle

A Matrix package passes through seven stages between the day a package author runs mx init and the day a runtime backed by that package is shut down. Each stage corresponds to a specific CLI command and a specific section of this site.

The seven stages

#StageCommand(s)What happens
1Authormx init, mx actor, mx element, mx webapp, mx cqrs, mx actor-elementScaffold a package on disk; create matrix.json, src/, tests/.
2Buildpnpm build (per package) or node build.mjsCompile TypeScript and bundle browser assets into dist/.
3Testpnpm test (per package)Run package-local tests against built artifacts.
4Publishmx pack, mx publishPack the package into a tarball; push it to a registry.
5Installmx install <pkg>, hivecast installCopy the published artifact (or local source) into a Host's package store.
6Runmx run, mx up, hivecast up, matrix upStart a runtime that loads the package and mounts its actors.
7Operatehivecast status, hivecast runtimes, mx info, mx outdated, mx update-fork, hivecast down, mx uninstallInspect, update, supervise, and remove.

Each stage has its own section in this site:

StageSection
1 AuthorAuthoring
2-3 Build & TestLocal Development
4 PublishPublishing
5 InstallInstalling
6 RunRunning
7 OperateRunning (logs, health, update, rollback)

Stage diagram

mermaid
flowchart LR
    A[mx init] --> B[pnpm build]
    B --> C[pnpm test]
    C --> D[mx pack]
    D --> E[mx publish]
    E --> F[mx install / hivecast install]
    F --> G[hivecast up / matrix up]
    G --> H[Operate: status, logs, update]
    H -->|new version| C
    H -->|stop| I[hivecast down]
    I -->|remove| J[mx uninstall]

Stage gating

The lifecycle is not strictly serial. Some stages can be skipped for specific shapes:

  • A library package has no Run stage on its own — its install and build are real, but it executes only when imported by another package's runtime.
  • A web app package without a service factory still has a Build and Run stage; mx run . --env <name> --serve mounts the asset endpoint without starting a service factory.
  • Local development can skip Publish entirely: see Deployless lifecycle.

What enforces correctness at each gate

GateEnforced by
Authormx init writes a manifest that validateManifestForMxCli accepts
BuildThe package's own pnpm build script
TestThe package's own pnpm test script (CLAUDE.md Rule 10)
Publishmx publish runs ensurePublishPreflight (packages/mx-cli/src/commands/publish.ts:49-86) which re-validates the manifest, checks the runtime entry exists, and confirms the package declares at least one of: root actor, component, webapp, or matrix.service.json factory
Installmx install runs the install lifecycle hooks (validate, migrate, seed, verify) declared in matrix.json:install
RunHost Service supervises the runtime; the runtime's matrix.service.json factory must exist, export the named function, and survive its --check invocation

See also

Source: Each stage's commands are in projects/matrix-3/packages/mx-cli/src/commands/ and projects/matrix-3/packages/host-service/src/cli.ts.