> ## Documentation Index
> Fetch the complete documentation index at: https://vlyai-1c28d863.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Multiplayer apps

> Prompts for real-time multiplayer — lobbies, state sync, leaderboards.

Multiplayer apps push Convex's real-time sync hardest. Foundation prompt:

```text theme={null}
**Goal**: A real-time multiplayer {game/tool} where players join a session and see each other's actions live.

**User**: Authenticated players. Each player joins a session via short code.

**Data**:
- `sessions`: { code, hostId, maxPlayers, status: 'waiting' | 'playing' | 'ended' }
- `sessionPlayers`: { sessionId, userId, joinedAt, score, state: any }
- `actions`: { sessionId, userId, type, payload, timestamp }

**Behavior**:
- Lobby: enter session code or create new; see who's joined
- Game: real-time state visible to all players; actions submit instantly
- Leaderboard: ranked by score in real-time
- End: results screen, "Play again" returns to lobby

**Constraints**:
- Sub-100ms perceived latency (use Convex reactive queries; optimistic local updates)
- Idle players auto-removed after 5 min
- Cleanup ended sessions older than 24h via scheduled function
```

## Variations

<Tabs>
  <Tab title="Turn-based">
    Add: a `currentTurn` field; UI disables input when it's not your turn.
  </Tab>

  <Tab title="Spectators">
    Add: read-only viewers who don't take actions but see state.
  </Tab>

  <Tab title="Matchmaking">
    Add: skill-based matching (queue players by ELO, pair when ready).
  </Tab>
</Tabs>

## Related

<CardGroup cols={3}>
  <Card title="Multiplayer recipe" icon="gamepad-2" href="/recipes/multiplayer-game">
    Full build walkthrough.
  </Card>

  <Card title="Real-time sync patterns" icon="zap" href="/architecture/realtime-sync-patterns">
    Architectural patterns.
  </Card>

  <Card title="Optimistic updates" icon="zap" href="/architecture/optimistic-updates">
    Sub-100ms feel.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.