# misted91/clash_royal architecture

> Architecture diagram of the GitHub repository misted91/clash_royal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/misted91/clash_royal
- Repository: https://github.com/misted91/clash_royal

## Overview

Web Royale is a real-time 1v1 strategy game with solo play against a simple AI and online matches. The player selects a card and deploys it on the arena; the shared game engine simulates the match, while the client renders state and updates the HUD. Online, the server pairs players, runs the authoritative simulation, and broadcasts snapshots. The README documents both modes; edges below are limited to relationships shown in excerpts, the SOURCE INDEX, or README.

Main entry points: [`src/client/main.ts`](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/client/main.ts) (Client orchestration), [`src/engine/engine.ts`](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/engine.ts) (Match simulation), [`src/client/renderer.ts`](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/client/renderer.ts) (Arena renderer), [`src/engine/ai.ts`](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/ai.ts) (Solo AI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Game client"]
  node_app["Client orchestration<br/>[main.ts]"]
  node_hud["Card HUD<br/>[hud.ts]"]
  node_renderer["Arena renderer<br/>[renderer.ts]"]
end

subgraph group_rules["Game rules"]
  node_engine["Match simulation<br/>[engine.ts]"]
  node_ai["Solo AI<br/>[ai.ts]"]
  node_arena["Arena rules<br/>[arena.ts]"]
  node_cards["Card catalogue<br/>[cards.ts]"]
  node_types["Game state types<br/>[types.ts]"]
end

subgraph group_network["Online play"]
  node_netclient["WebSocket client<br/>[client.ts]"]
  node_protocol["Message protocol<br/>[protocol.ts]"]
  node_matchmaking["Player matchmaking<br/>[index.ts]"]
  node_match["Authoritative match<br/>[index.ts]"]
end

node_player(("Player"))
node_opponent(("Online opponent"))

node_player -->|"starts game"| node_app
node_player -->|"selects card"| node_hud
node_app -->|"creates and updates"| node_hud
node_app -->|"renders state"| node_renderer
node_app -->|"steps and reads state"| node_engine
node_app -->|"updates in solo"| node_ai
node_app -->|"connects and sends deploys"| node_netclient
node_hud -->|"displays catalogue"| node_cards
node_renderer -->|"draws units"| node_cards
node_renderer -->|"draws arena"| node_arena
node_renderer -->|"renders game state"| node_types
node_engine -->|"uses arena rules"| node_arena
node_engine -->|"uses card definitions"| node_cards
node_engine -->|"uses game types"| node_types
node_ai -->|"deploys cards"| node_engine
node_ai -->|"reads arena bounds"| node_arena
node_ai -->|"chooses affordable cards"| node_cards
node_netclient -->|"encodes messages"| node_protocol
node_matchmaking -->|"pairs players"| node_match
node_match -->|"simulates match"| node_engine
node_match -->|"sends match messages"| node_protocol
node_opponent -->|"joins queue"| node_matchmaking
node_netclient -->|"opens WebSocket"| node_matchmaking
node_match -->|"broadcasts snapshots"| node_netclient

click node_app "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/client/main.ts"
click node_hud "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/client/hud.ts"
click node_renderer "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/client/renderer.ts"
click node_engine "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/engine.ts"
click node_ai "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/ai.ts"
click node_arena "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/arena.ts"
click node_cards "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/cards.ts"
click node_types "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/types.ts"
click node_netclient "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/net/client.ts"
click node_protocol "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/net/protocol.ts"
click node_matchmaking "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/server/index.ts"
click node_match "https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/server/index.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_hud,node_renderer toneBlue
class node_engine,node_ai,node_arena,node_cards,node_types toneAmber
class node_netclient,node_protocol,node_matchmaking,node_match toneMint
class node_player,node_opponent toneIndigo
```

## Components

### Game client

- [Client orchestration](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/client/main.ts): `src/client/main.ts`
- [Card HUD](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/client/hud.ts): `src/client/hud.ts`
- [Arena renderer](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/client/renderer.ts): `src/client/renderer.ts`

### Game rules

- [Match simulation](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/engine.ts): `src/engine/engine.ts`
- [Solo AI](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/ai.ts): `src/engine/ai.ts`
- [Arena rules](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/arena.ts): `src/engine/arena.ts`
- [Card catalogue](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/cards.ts): `src/engine/cards.ts`
- [Game state types](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/engine/types.ts): `src/engine/types.ts`

### Online play

- [WebSocket client](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/net/client.ts): `src/net/client.ts`
- [Message protocol](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/src/net/protocol.ts): `src/net/protocol.ts`
- [Player matchmaking](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/server/index.ts): `server/index.ts`
- [Authoritative match](https://github.com/misted91/clash_royal/blob/claude/intelligent-volta-0fy61q/server/index.ts): `server/index.ts`

### Other components

- **Player**
- **Online opponent**

## Connections

- Player → Client orchestration: starts game (evidence: `README.md`)
- Player → Card HUD: selects card (evidence: `README.md`)
- Client orchestration → Card HUD: creates and updates (evidence: `src/client/main.ts`)
- Client orchestration → Arena renderer: renders state (evidence: `src/client/main.ts`)
- Client orchestration → Match simulation: steps and reads state (evidence: `src/client/main.ts`)
- Client orchestration → Solo AI: updates in solo (evidence: `src/client/main.ts`)
- Client orchestration → WebSocket client: connects and sends deploys (evidence: `src/client/main.ts`)
- Card HUD → Card catalogue: displays catalogue (evidence: `src/client/hud.ts`)
- Arena renderer → Card catalogue: draws units (evidence: `src/client/renderer.ts`)
- Arena renderer → Arena rules: draws arena (evidence: `src/client/renderer.ts`)
- Arena renderer → Game state types: renders game state (evidence: `src/client/renderer.ts`)
- Match simulation → Arena rules: uses arena rules (evidence: `src/engine/engine.ts`)
- Match simulation → Card catalogue: uses card definitions (evidence: `src/engine/engine.ts`)
- Match simulation → Game state types: uses game types (evidence: `src/engine/engine.ts`)
- Solo AI → Match simulation: deploys cards (evidence: `src/engine/ai.ts`)
- Solo AI → Arena rules: reads arena bounds (evidence: `src/engine/ai.ts`)
- Solo AI → Card catalogue: chooses affordable cards (evidence: `src/engine/ai.ts`)
- WebSocket client → Message protocol: encodes messages (evidence: `src/net/client.ts`)
- Player matchmaking → Authoritative match: pairs players (evidence: `server/index.ts`)
- Authoritative match → Match simulation: simulates match (evidence: `server/index.ts`)
- Authoritative match → Message protocol: sends match messages (evidence: `server/index.ts`)
- Online opponent → Player matchmaking: joins queue (evidence: `server/index.ts`)
- WebSocket client → Player matchmaking: opens WebSocket (evidence: `README.md`)
- Authoritative match → WebSocket client: broadcasts snapshots (evidence: `server/index.ts`)
