# weraf/virusantivirus-game architecture

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

- Interactive diagram: https://gitdiagram.com/weraf/virusantivirus-game
- Repository: https://github.com/weraf/virusantivirus-game

## Overview

Virus VS Antivirus is a browser-based, real-time network-board game. Players enter matchmaking, play as virus or antivirus against another player or AI, or spectate matches; the server creates a map-backed game, validates and broadcasts turns, and ends play on a win or timeout. The client renders the shared board, handles input and game UI, and supports translated screens and audio. The README documents random map selection, bugs, AI play and spectating, and multilingual UI. Relationships shown are limited to explicit README claims and sampled imports/calls; some client-server event wiring is only partially excerpted.

Main entry points: [`client/shared/board.js`](https://github.com/weraf/virusantivirus-game/blob/main/client/shared/board.js) (Board model), [`client/game.js`](https://github.com/weraf/virusantivirus-game/blob/main/client/game.js) (Game scene), [`server/gameserver.js`](https://github.com/weraf/virusantivirus-game/blob/main/server/gameserver.js) (Game server), [`server/lobbyhandler.js`](https://github.com/weraf/virusantivirus-game/blob/main/server/lobbyhandler.js) (Match lobby)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Match services"]
  node_webserver["Web server<br/>[webserver.js]"]
  node_socket["Socket service<br/>[server.js]"]
  node_user["Socket user<br/>[user.js]"]
  node_lobby["Match lobby<br/>[lobbyhandler.js]"]
  node_players["Player wrappers<br/>[player.js]"]
  node_gameserver["Game server<br/>[gameserver.js]"]
  node_aiplayer["AI player<br/>[aiplayer.js]"]
end

subgraph group_rules["Game domain"]
  node_ai["Move search<br/>[ai.js]"]
  node_gamestate["Turn and win state<br/>[gamestate.js]"]
  node_boardcreator["Map builder<br/>[boardCreator.js]"]
  node_board["Board model<br/>[board.js]"]
  node_node["Network nodes<br/>[node.js]"]
  node_virus["Virus piece<br/>[virus.js]"]
  node_antivirus["Antivirus pieces<br/>[antivirus.js]"]
  node_bugs["Map bugs<br/>[bugs.js]"]
  node_enums["Shared events<br/>[enums.js]"]
  node_maps["Map data"]
end

subgraph group_client["Player client"]
  node_game["Game scene<br/>[game.js]"]
  node_input["Move input<br/>[inputhandler.js]"]
  node_drawer["Board renderer<br/>[gameDrawer.js]"]
end

subgraph group_interface["UI and media"]
  node_gameui["Game interface<br/>[game_ui.js]"]
  node_html["HTML manager<br/>[htmlmanager.js]"]
  node_translator["Translations<br/>[translator.js]"]
  node_sound["Audio manager<br/>[soundManager.js]"]
end

node_browser(("Browser player"))

node_browser -->|"opens game"| node_webserver
node_webserver -->|"starts socket"| node_socket
node_socket -->|"wraps connection"| node_user
node_socket -->|"routes actions"| node_lobby
node_lobby -->|"creates players"| node_players
node_lobby -->|"creates AI"| node_aiplayer
node_lobby -->|"creates games"| node_gameserver
node_aiplayer -->|"uses search"| node_ai
node_gameserver -->|"builds board"| node_boardcreator
node_gameserver -->|"selects map"| node_maps
node_gameserver -->|"creates board"| node_board
node_gameserver -->|"tracks turns"| node_gamestate
node_boardcreator -.->|"populates nodes"| node_board
node_board -->|"creates nodes"| node_node
node_board -->|"owns piece"| node_virus
node_board -->|"owns pieces"| node_antivirus
node_board -->|"owns bugs"| node_bugs
node_browser -->|"plays or watches"| node_game
node_game -->|"creates board"| node_board
node_game -->|"starts state"| node_gamestate
node_game -->|"creates renderer"| node_drawer
node_game -->|"handles input"| node_input
node_game -->|"creates interface"| node_gameui
node_game -->|"starts audio"| node_sound
node_input -->|"reads nodes"| node_board
node_drawer -->|"renders board"| node_board
node_drawer -->|"renders bugs"| node_bugs
node_drawer -->|"renders virus"| node_virus
node_gameui -->|"loads components"| node_html
node_gameui -->|"connects translations"| node_translator
node_translator -->|"updates components"| node_html
node_gameui -->|"displays state"| node_gamestate
node_game -.->|"exchanges events"| node_socket

click node_webserver "https://github.com/weraf/virusantivirus-game/blob/main/webserver.js"
click node_socket "https://github.com/weraf/virusantivirus-game/blob/main/server/server.js"
click node_user "https://github.com/weraf/virusantivirus-game/blob/main/server/user.js"
click node_lobby "https://github.com/weraf/virusantivirus-game/blob/main/server/lobbyhandler.js"
click node_players "https://github.com/weraf/virusantivirus-game/blob/main/server/player.js"
click node_gameserver "https://github.com/weraf/virusantivirus-game/blob/main/server/gameserver.js"
click node_aiplayer "https://github.com/weraf/virusantivirus-game/blob/main/server/aiplayer.js"
click node_ai "https://github.com/weraf/virusantivirus-game/blob/main/client/shared/ai.js"
click node_gamestate "https://github.com/weraf/virusantivirus-game/blob/main/client/shared/gamestate.js"
click node_boardcreator "https://github.com/weraf/virusantivirus-game/blob/main/client/shared/boardCreator.js"
click node_board "https://github.com/weraf/virusantivirus-game/blob/main/client/shared/board.js"
click node_node "https://github.com/weraf/virusantivirus-game/blob/main/client/shared/node.js"
click node_virus "https://github.com/weraf/virusantivirus-game/blob/main/client/shared/virus.js"
click node_antivirus "https://github.com/weraf/virusantivirus-game/blob/main/client/shared/antivirus.js"
click node_bugs "https://github.com/weraf/virusantivirus-game/blob/main/client/shared/bugs.js"
click node_enums "https://github.com/weraf/virusantivirus-game/blob/main/client/shared/enums.js"
click node_game "https://github.com/weraf/virusantivirus-game/blob/main/client/game.js"
click node_input "https://github.com/weraf/virusantivirus-game/blob/main/client/inputhandler.js"
click node_drawer "https://github.com/weraf/virusantivirus-game/blob/main/client/gameDrawer.js"
click node_gameui "https://github.com/weraf/virusantivirus-game/blob/main/client/ui/game_ui.js"
click node_html "https://github.com/weraf/virusantivirus-game/blob/main/client/ui/htmlmanager/htmlmanager.js"
click node_translator "https://github.com/weraf/virusantivirus-game/blob/main/client/ui/translator.js"
click node_sound "https://github.com/weraf/virusantivirus-game/blob/main/client/soundManager.js"
click node_maps "https://github.com/weraf/virusantivirus-game/tree/main/client/assets"

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_webserver,node_socket,node_user,node_lobby,node_players,node_gameserver,node_aiplayer,node_browser toneBlue
class node_ai,node_gamestate,node_boardcreator,node_board,node_node,node_virus,node_antivirus,node_bugs,node_enums,node_maps toneAmber
class node_game,node_input,node_drawer toneMint
class node_gameui,node_html,node_translator,node_sound toneRose
```

## Components

### Match services

- [Web server](https://github.com/weraf/virusantivirus-game/blob/main/webserver.js): `webserver.js`
- [Socket service](https://github.com/weraf/virusantivirus-game/blob/main/server/server.js): `server/server.js`
- [Socket user](https://github.com/weraf/virusantivirus-game/blob/main/server/user.js): `server/user.js`
- [Match lobby](https://github.com/weraf/virusantivirus-game/blob/main/server/lobbyhandler.js): `server/lobbyhandler.js`
- [Player wrappers](https://github.com/weraf/virusantivirus-game/blob/main/server/player.js): `server/player.js`
- [Game server](https://github.com/weraf/virusantivirus-game/blob/main/server/gameserver.js): `server/gameserver.js`
- [AI player](https://github.com/weraf/virusantivirus-game/blob/main/server/aiplayer.js): `server/aiplayer.js`

### Game domain

- [Move search](https://github.com/weraf/virusantivirus-game/blob/main/client/shared/ai.js): `client/shared/ai.js`
- [Turn and win state](https://github.com/weraf/virusantivirus-game/blob/main/client/shared/gamestate.js): `client/shared/gamestate.js`
- [Map builder](https://github.com/weraf/virusantivirus-game/blob/main/client/shared/boardCreator.js): `client/shared/boardCreator.js`
- [Board model](https://github.com/weraf/virusantivirus-game/blob/main/client/shared/board.js): `client/shared/board.js`
- [Network nodes](https://github.com/weraf/virusantivirus-game/blob/main/client/shared/node.js): `client/shared/node.js`
- [Virus piece](https://github.com/weraf/virusantivirus-game/blob/main/client/shared/virus.js): `client/shared/virus.js`
- [Antivirus pieces](https://github.com/weraf/virusantivirus-game/blob/main/client/shared/antivirus.js): `client/shared/antivirus.js`
- [Map bugs](https://github.com/weraf/virusantivirus-game/blob/main/client/shared/bugs.js): `client/shared/bugs.js`
- [Shared events](https://github.com/weraf/virusantivirus-game/blob/main/client/shared/enums.js): `client/shared/enums.js`
- [Map data](https://github.com/weraf/virusantivirus-game/tree/main/client/assets): `client/assets`

### Player client

- [Game scene](https://github.com/weraf/virusantivirus-game/blob/main/client/game.js): `client/game.js`
- [Move input](https://github.com/weraf/virusantivirus-game/blob/main/client/inputhandler.js): `client/inputhandler.js`
- [Board renderer](https://github.com/weraf/virusantivirus-game/blob/main/client/gameDrawer.js): `client/gameDrawer.js`

### UI and media

- [Game interface](https://github.com/weraf/virusantivirus-game/blob/main/client/ui/game_ui.js): `client/ui/game_ui.js`
- [HTML manager](https://github.com/weraf/virusantivirus-game/blob/main/client/ui/htmlmanager/htmlmanager.js): `client/ui/htmlmanager/htmlmanager.js`
- [Translations](https://github.com/weraf/virusantivirus-game/blob/main/client/ui/translator.js): `client/ui/translator.js`
- [Audio manager](https://github.com/weraf/virusantivirus-game/blob/main/client/soundManager.js): `client/soundManager.js`

### Other components

- **Browser player**

## Connections

- Browser player → Web server: opens game (evidence: `README.md`)
- Web server → Socket service: starts socket (evidence: `webserver.js`)
- Socket service → Socket user: wraps connection (evidence: `server/server.js`)
- Socket service → Match lobby: routes actions (evidence: `server/server.js`)
- Match lobby → Player wrappers: creates players (evidence: `server/lobbyhandler.js`)
- Match lobby → AI player: creates AI (evidence: `server/lobbyhandler.js`)
- Match lobby → Game server: creates games (evidence: `server/lobbyhandler.js`)
- AI player → Move search: uses search (evidence: `server/aiplayer.js`)
- Game server → Map builder: builds board (evidence: `server/gameserver.js`)
- Game server → Map data: selects map (evidence: `server/gameserver.js`)
- Game server → Board model: creates board (evidence: `server/gameserver.js`)
- Game server → Turn and win state: tracks turns (evidence: `server/gameserver.js`)
- Map builder → Board model: populates nodes
- Board model → Network nodes: creates nodes (evidence: `client/shared/board.js`)
- Board model → Virus piece: owns piece (evidence: `client/shared/board.js`)
- Board model → Antivirus pieces: owns pieces (evidence: `client/shared/board.js`)
- Board model → Map bugs: owns bugs (evidence: `client/shared/board.js`)
- Browser player → Game scene: plays or watches (evidence: `README.md`)
- Game scene → Board model: creates board (evidence: `client/game.js`)
- Game scene → Turn and win state: starts state (evidence: `client/game.js`)
- Game scene → Board renderer: creates renderer (evidence: `client/game.js`)
- Game scene → Move input: handles input (evidence: `client/game.js`)
- Game scene → Game interface: creates interface (evidence: `client/game.js`)
- Game scene → Audio manager: starts audio (evidence: `client/game.js`)
- Move input → Board model: reads nodes (evidence: `client/inputhandler.js`)
- Board renderer → Board model: renders board (evidence: `client/gameDrawer.js`)
- Board renderer → Map bugs: renders bugs (evidence: `client/gameDrawer.js`)
- Board renderer → Virus piece: renders virus (evidence: `client/gameDrawer.js`)
- Game interface → HTML manager: loads components (evidence: `client/ui/game_ui.js`)
- Game interface → Translations: connects translations (evidence: `client/ui/game_ui.js`)
- Translations → HTML manager: updates components (evidence: `client/ui/translator.js`)
- Game interface → Turn and win state: displays state (evidence: `client/ui/game_ui.js`)
- Game scene → Socket service: exchanges events
