# Game components

> A Minekube game is an Effect UI component tree - rules that turn messages into a new Model and Commands, a server half that connects them to Paper, a scope per revision that cleans up after it, and child components as failure boundaries.

A Minekube game is an [Effect UI](https://github.com/Effect-TS/effect/tree/main/packages/ui) component, mounted in Paper by the Minekube plugin. Its state changes only through messages, and everything it wants to happen in the world is data, a Command, until the server half carries it out. The same shape runs a proxy bundle on Velocity and a bot in a client.

## The parts

| Part | What it is |
| --- | --- |
| **Model** | The game's state, with a Schema. |
| **Messages** | What happened, as a tagged union with Schemas: a player clicked a sign, a round ended, a Command answered. |
| **`update`** | One handler per message. It returns the next Model and the Commands to run, and never calls Paper or waits. |
| **Commands** | What should happen, such as launching a player. Declared in the rules, implemented in the server half with Paper calls. |
| **Subscriptions** | Where messages come from: Paper events with `Paper.event`, and server commands with `Paper.command`. |
| **Children** | Other components the game renders, each with its own Model, such as one per arena or per player. |

A game is therefore a tree of components: the game at the root, and children for the parts that have their own state and their own lifetime.

## Rules and the server half

A game has two halves, in two files.

- **The rules** are the Model, the messages, `update` and the Command declarations. They import no Java, so they run in Bun.
- **The server half** turns Paper events into messages, implements each Command with Paper's real API, and mounts the component with `Paper.mount`.

Because the rules decide without touching the server, the same message always gives the same Model and the same Commands. That is what makes a recorded session replayable months later, and what lets Stories test the rules in milliseconds. See [Session recordings](https://minekube.com/games/concepts/recording).

## Commands and server commands

Two different things share the word.

- **A Command** is an effect the rules ask for. A silent Command acts on the world. A Command with a `success` answers with a message, and one with an `error` declares a failure the rules can react to. A Command runs as long as its Effect, so a particle trail that repeats for a second is one Command.
- **A server command,** such as `/browse`, is something a player types. `Paper.command` makes it one of the server's own commands while the game runs, with suggestions as players type, and turns each use into a message.

## A scope per revision

Everything a loaded bundle starts, it starts inside its scope: listeners, timers, fibers, running Commands and its server commands. When the runtime replaces or uninstalls the bundle, the scope closes and all of it ends. There is no disable hook to forget, and nothing of the previous code keeps running, which is what makes [live swap](https://minekube.com/games/concepts/runtime) safe.

The world is not in the scope. Blocks and entities belong to the server, so a game creates them in a way that tolerates finding them already there, and pairs anything it must remove with its removal.

## Children are failure boundaries

A bug in a running game, such as a Java exception in a Command, fails the component it happened in.

- **A failed child shows its fallback,** its parent hears of it, and the rest of the game keeps running. Give each arena or player its own child, so that one player's bug does not restart everyone's round.
- **The game itself is a child too.** The runtime mounts it under its own small component, the Supervisor, which starts a failed game over from its first Model and reports the failure. A game that keeps failing stays off until its next revision, so a crash at start cannot loop on the server thread. [Limits](https://minekube.com/games/platform/limits#games) gives the threshold.

## Why components

Minecraft games are full of state that changes on events, and plugins usually scatter that state across listeners. A component gathers it in one Model, with one place where it changes. The result is code that a person or a coding agent can read in one file, test without a server, and replay from a real session.

## What a game is not

- **Not a Paper plugin.** It has no plugin class, no `onEnable` and no jar of its own. It is a [bundle](https://minekube.com/games/concepts/bundle) that the Minekube plugin runs.
- **Not a wrapper over Paper.** The server half calls Paper's own classes, typed from the server's jars.
- **Not required to be a component.** `Paper.make` runs any Effect program as a game, but only components are recorded and replayable.

## Related

- [Games as Effect components](https://minekube.com/games/write/effect-model): the programming model in depth.
- [Game structure](https://minekube.com/games/write/game-structure): the rules and the server half in code, with events, lifetime and failures.
- [Proxy bundles](https://minekube.com/games/write/proxy-bundles): the same model on Velocity.
