# anmolllll311/battleship architecture

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

- Interactive diagram: https://gitdiagram.com/anmolllll311/battleship
- Repository: https://github.com/anmolllll311/battleship

## Overview

Aegis is a browser-based, peer-to-peer Battleship game with cryptographic board commitments. The principal workflow is to set up a fleet, exchange compressed WebRTC offer/answer codes, then exchange game messages over a data channel while proving attacked cells against prior commitments. The excerpts show the controller wiring to the crypto and transport engines, and a hit sound call. QR libraries and the camera appear to support code exchange, but the relevant wiring is not shown; those relationships are therefore omitted.

Main entry points: [`game.js`](https://github.com/anmolllll311/battleship/blob/main/game.js) (Game controller), [`webrtc.js`](https://github.com/anmolllll311/battleship/blob/main/webrtc.js) (WebRTC transport), [`crypto.js`](https://github.com/anmolllll311/battleship/blob/main/crypto.js) (Board commitments), [`audio.js`](https://github.com/anmolllll311/battleship/blob/main/audio.js) (Synthesized audio)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gameplay["Game experience"]
  node_game["Game controller<br/>[game.js]"]
  node_webpage["Game page<br/>[index.html]"]
end

subgraph group_connection["Peer connection"]
  node_transport["WebRTC transport<br/>[webrtc.js]"]
  node_qrscan["QR decoding<br/>[lib-jsqr.js]"]
  node_qrscanbundle["QR decoder bundle<br/>[jsqr.bundle.js]"]
  node_qrcreate["QR generation<br/>[qrcode.bundle.js]"]
end

subgraph group_integrity["Fair play and feedback"]
  node_commitments["Board commitments<br/>[crypto.js]"]
  node_sound["Synthesized audio<br/>[audio.js]"]
end

node_player(("Player"))
node_opponent(("Opponent"))

node_player -.->|"plays"| node_game
node_game -->|"creates"| node_transport
node_game -->|"creates"| node_commitments
node_game -->|"plays hit"| node_sound
node_transport -.->|"P2P messages"| node_opponent

click node_game "https://github.com/anmolllll311/battleship/blob/main/game.js"
click node_webpage "https://github.com/anmolllll311/battleship/blob/main/index.html"
click node_transport "https://github.com/anmolllll311/battleship/blob/main/webrtc.js"
click node_commitments "https://github.com/anmolllll311/battleship/blob/main/crypto.js"
click node_sound "https://github.com/anmolllll311/battleship/blob/main/audio.js"
click node_qrscan "https://github.com/anmolllll311/battleship/blob/main/lib-jsqr.js"
click node_qrscanbundle "https://github.com/anmolllll311/battleship/blob/main/jsqr.bundle.js"
click node_qrcreate "https://github.com/anmolllll311/battleship/blob/main/qrcode.bundle.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_game,node_webpage toneBlue
class node_transport,node_qrscan,node_qrscanbundle,node_qrcreate toneAmber
class node_commitments,node_sound toneMint
class node_player,node_opponent toneIndigo
```

## Components

### Game experience

- [Game controller](https://github.com/anmolllll311/battleship/blob/main/game.js): `game.js`
- [Game page](https://github.com/anmolllll311/battleship/blob/main/index.html): `index.html`

### Peer connection

- [WebRTC transport](https://github.com/anmolllll311/battleship/blob/main/webrtc.js): `webrtc.js`
- [QR decoding](https://github.com/anmolllll311/battleship/blob/main/lib-jsqr.js): `lib-jsqr.js`
- [QR decoder bundle](https://github.com/anmolllll311/battleship/blob/main/jsqr.bundle.js): `jsqr.bundle.js`
- [QR generation](https://github.com/anmolllll311/battleship/blob/main/qrcode.bundle.js): `qrcode.bundle.js`

### Fair play and feedback

- [Board commitments](https://github.com/anmolllll311/battleship/blob/main/crypto.js): `crypto.js`
- [Synthesized audio](https://github.com/anmolllll311/battleship/blob/main/audio.js): `audio.js`

### Other components

- **Player**
- **Opponent**

## Connections

- Player → Game controller: plays
- Game controller → WebRTC transport: creates (evidence: `game.js`)
- Game controller → Board commitments: creates (evidence: `game.js`)
- Game controller → Synthesized audio: plays hit (evidence: `game.js`)
- WebRTC transport → Opponent: P2P messages
