# Leaderboard

> The Leaderboard interface of the Room API is a collection with leaderboard settings, holding one score per player per period.

The **`Leaderboard`** interface of the [Room API](/docs/room) is a collection declared with leaderboard settings in `irt.config.ts`, holding one score per player for each period it keeps. `room.leaderboard(name)` returns one.

## Instance properties

`Leaderboard.name`
: The leaderboard's name. Read only.

## Instance methods

[`Leaderboard.submit()`](/docs/room/leaderboard/submit)
: Applies a player's score to every period the board keeps.

[`Leaderboard.top()`](/docs/room/leaderboard/top)
: Resolves with a page of the best entries of a period.

[`Leaderboard.around()`](/docs/room/leaderboard/around)
: Resolves with a player's rank and the entries either side.

[`Leaderboard.refresh()`](/docs/room/leaderboard/refresh)
: Does nothing, since leaderboard reads aren't cached.

## Description

- **Periods.** A board keeps any of `"all"`, `"day"`, `"week"` and `"month"`, as its `periods` setting declares, in UTC; weeks are ISO weeks from Monday. A `period` argument is one of those for the current period, or a full name such as `"day:2026-11-06"`, `"week:2026-W45"` or `"month:2026-11"` for one of the three before it.
- **Ranks** go by score in the board's `order`, then by the earliest `updated`.
- **Nothing is cached**: every `top()` and `around()` is a call.
- **Errors.** Calls reject with a [`DataError`](/docs/room/data-error).

## Examples

### Scoring a finished run

```ts
// time-trial.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  async onMessage(room, connection, message) {
    const m = message as { type?: string; ms?: number };
    if (m.type !== "finished" || typeof m.ms !== "number") return;
    await room.leaderboard("laps").submit(connection.player, m.ms, { meta: { track: "canyon" } });
    const best = await room.leaderboard("laps").top({ period: "week", limit: 5 });
    room.broadcast({ type: "standings", entries: best.entries });
  },
});
```

## See also

- [Player data, collections and leaderboards](/docs/room/guides/player-data), the guide
- [`Collection`](/docs/room/collection)
