# bhavyasachula/chessjs architecture

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

- Interactive diagram: https://gitdiagram.com/bhavyasachula/chessjs
- Repository: https://github.com/bhavyasachula/chessjs

## Overview

This is a small browser-based, two-player chess game with spectator support. Players interact with a rendered board; the browser sends moves to the server, which checks player turns, applies moves using chess.js, and broadcasts accepted moves and board state. The server also assigns player roles and serves the game page. Source excerpts show the main flow; the view template’s contents and client-side script loading are not shown, so those details are not inferred.

Main entry points: [`app.js`](https://github.com/bhavyasachula/chessjs/blob/main/app.js) (HTTP and socket server), [`public/js/chessgame.js`](https://github.com/bhavyasachula/chessjs/blob/main/public/js/chessgame.js) (Board interaction), [`views/chess.ejs`](https://github.com/bhavyasachula/chessjs/blob/main/views/chess.ejs) (Chess page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Browser game"]
  node_page["Chess page<br/>[chess.ejs]"]
  node_board["Board interaction<br/>[chessgame.js]"]
  node_clientstate["Client chess state<br/>[chessgame.js]"]
end

subgraph group_server["Game server"]
  node_server["HTTP and socket server<br/>[app.js]"]
  node_roles["Player roles<br/>[app.js]"]
  node_gamestate["Game rules and state<br/>[app.js]"]
end

node_player(("Player or spectator"))
node_chessjs["chess.js engine"]

node_player -->|"opens game"| node_page
node_server -->|"renders"| node_page
node_player -->|"drags pieces"| node_board
node_board -->|"sends moves"| node_server
node_server -->|"assigns roles"| node_roles
node_server -->|"applies moves"| node_gamestate
node_server -->|"calls move"| node_chessjs
node_server -->|"broadcasts state"| node_board
node_board -->|"updates and renders"| node_clientstate
node_clientstate -.->|"uses chess rules"| node_chessjs

click node_page "https://github.com/bhavyasachula/chessjs/blob/main/views/chess.ejs"
click node_board "https://github.com/bhavyasachula/chessjs/blob/main/public/js/chessgame.js"
click node_clientstate "https://github.com/bhavyasachula/chessjs/blob/main/public/js/chessgame.js"
click node_server "https://github.com/bhavyasachula/chessjs/blob/main/app.js"
click node_roles "https://github.com/bhavyasachula/chessjs/blob/main/app.js"
click node_gamestate "https://github.com/bhavyasachula/chessjs/blob/main/app.js"

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_page,node_board,node_clientstate toneBlue
class node_server,node_roles,node_gamestate toneAmber
class node_player,node_chessjs toneIndigo
```

## Components

### Browser game

- [Chess page](https://github.com/bhavyasachula/chessjs/blob/main/views/chess.ejs): `views/chess.ejs`
- [Board interaction](https://github.com/bhavyasachula/chessjs/blob/main/public/js/chessgame.js): `public/js/chessgame.js`
- [Client chess state](https://github.com/bhavyasachula/chessjs/blob/main/public/js/chessgame.js): `public/js/chessgame.js`

### Game server

- [HTTP and socket server](https://github.com/bhavyasachula/chessjs/blob/main/app.js): `app.js`
- [Player roles](https://github.com/bhavyasachula/chessjs/blob/main/app.js): `app.js`
- [Game rules and state](https://github.com/bhavyasachula/chessjs/blob/main/app.js): `app.js`

### Other components

- **Player or spectator**
- **chess.js engine**

## Connections

- Player or spectator → Chess page: opens game
- HTTP and socket server → Chess page: renders (evidence: `app.js`)
- Player or spectator → Board interaction: drags pieces (evidence: `public/js/chessgame.js`)
- Board interaction → HTTP and socket server: sends moves (evidence: `public/js/chessgame.js`)
- HTTP and socket server → Player roles: assigns roles (evidence: `app.js`)
- HTTP and socket server → Game rules and state: applies moves (evidence: `app.js`)
- HTTP and socket server → chess.js engine: calls move (evidence: `app.js`)
- HTTP and socket server → Board interaction: broadcasts state (evidence: `app.js`)
- Board interaction → Client chess state: updates and renders (evidence: `public/js/chessgame.js`)
- Client chess state → chess.js engine: uses chess rules
