# RoomDefinition: schema property

> The schema property of a room definition is the room's schema, which declares its state, entities and calls and is shared with its clients.

The **`schema`** property of a [room definition](/docs/room/room-definition) is the room's [`Schema`](/docs/room/schema), made with [`defineSchema()`](/docs/room/defineschema). It declares the room's shared state, private state, entity kinds, calls and input, and the room's clients connect with the same schema.

## Value

A [`Schema`](/docs/room/schema). Without one, the room has no entities, shared or private state, or calls.

## Description

The schema types the room: `room.state`, `room.private()`, the handlers [`calls`](/docs/room/room-definition/calls) must have and the keys [`writes`](/docs/room/room-definition/writes) may have all come from it.

Keep the schema in a module of its own that the room and the client both import. A client sends the schema's hash when it connects, and a client built with a different schema fails to connect with close code 4004. The calls aren't part of the hash.

A room module is one room type, with its own schema. A room never changes type, so a lobby type and a match type each have theirs.

## Examples

### A schema shared with the client

```ts
// shared.ts
import { call, defineCalls, defineSchema, entity } from "@irtio/room";

export const Table = entity("table", { pot: "u32", turn: "string" });
export const Hand = entity("hand", { chips: "u32" });

export const schema = defineSchema({
  state: Table,
  private: Hand,
  calls: defineCalls({ bet: call({ amount: "u32" }) }),
});
```

```ts
// room.ts
import { CallRejected, defineRoom } from "@irtio/room";
import { schema } from "./shared.js";

export default defineRoom({
  schema,
  calls: {
    bet({ amount }, { room, connection }) {
      const hand = room.private(connection);
      if (room.state.turn !== connection.player || amount > hand.chips) throw new CallRejected("you can't bet that");
      hand.chips -= amount;
      room.state.pot += amount;
    },
  },
});
```

## See also

- [`defineSchema()`](/docs/room/defineschema)
- [`Schema`](/docs/room/schema)
- [State sync](/docs/room/guides/state-sync)
