# kokincho/grafight architecture

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

- Interactive diagram: https://gitdiagram.com/kokincho/grafight
- Repository: https://github.com/kokincho/grafight

## Overview

Grafight is a browser artillery game where players enter mathematical functions to define projectile paths and try to eliminate opposing soldiers. The main flow runs from game setup and function entry through expression compilation, trajectory simulation, collision resolution, and a rendered result. README-documented branches include four function modes, turn-based and real-time play, a 12-stage campaign, customization, saves, and replay. The excerpts show core game and parser behavior; several feature relationships are documented only in the README, so those edges cite it.

Main entry points: [`game.js`](https://github.com/kokincho/grafight/blob/main/game.js) (Game control), [`index.html`](https://github.com/kokincho/grafight/blob/main/index.html) (Game interface), [`parser.js`](https://github.com/kokincho/grafight/blob/main/parser.js) (Expression parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_play["Play and setup"]
  node_game_ui["Game interface<br/>[index.html]"]
  node_game_control["Game control<br/>[game.js]"]
  node_function_input["Function input<br/>[game.js]"]
end

subgraph group_simulation["Shot simulation"]
  node_expression_parser["Expression parser<br/>[parser.js]"]
  node_trajectory_solver["Trajectory simulation<br/>[game.js]"]
  node_terrain["Terrain and obstacles<br/>[game.js]"]
  node_combat["Collision and combat<br/>[game.js]"]
  node_canvas_render["Canvas rendering<br/>[game.js]"]
end

subgraph group_gameplay["Game modes"]
  node_local_modes["Local multiplayer<br/>[game.js]"]
  node_campaign["Campaign stages<br/>[game.js]"]
  node_shot_options["Shot options<br/>[game.js]"]
  node_soldier_state["Soldier state<br/>[game.js]"]
end

subgraph group_support["Persistence and review"]
  node_save_resume["Save and resume<br/>[game.js]"]
  node_progress_store[("Campaign progress<br/>[game.js]")]
  node_replay["Replay and logs<br/>[game.js]"]
end

node_player(("Player"))
node_browser(("Browser"))

node_player -->|"uses"| node_game_ui
node_game_ui -.->|"starts play"| node_game_control
node_game_control -.->|"collects input"| node_function_input
node_function_input -->|"compiles expression"| node_expression_parser
node_game_control -->|"creates shots"| node_trajectory_solver
node_trajectory_solver -->|"evaluates function"| node_expression_parser
node_trajectory_solver -.->|"checks obstacles"| node_terrain
node_game_control -.->|"resolves shots"| node_combat
node_combat -.->|"updates soldiers"| node_soldier_state
node_canvas_render -.->|"draws board"| node_game_ui
node_game_control -->|"runs mode"| node_local_modes
node_game_control -->|"loads stages"| node_campaign
node_game_control -->|"applies options"| node_shot_options
node_campaign -->|"saves progress"| node_progress_store
node_player -->|"saves or resumes"| node_save_resume
node_game_control -.->|"manages session"| node_save_resume
node_game_control -.->|"records match"| node_replay
node_player -->|"reviews match"| node_replay
node_browser -->|"stores locally"| node_progress_store

click node_game_ui "https://github.com/kokincho/grafight/blob/main/index.html"
click node_game_control "https://github.com/kokincho/grafight/blob/main/game.js"
click node_function_input "https://github.com/kokincho/grafight/blob/main/game.js"
click node_expression_parser "https://github.com/kokincho/grafight/blob/main/parser.js"
click node_trajectory_solver "https://github.com/kokincho/grafight/blob/main/game.js"
click node_terrain "https://github.com/kokincho/grafight/blob/main/game.js"
click node_combat "https://github.com/kokincho/grafight/blob/main/game.js"
click node_canvas_render "https://github.com/kokincho/grafight/blob/main/game.js"
click node_local_modes "https://github.com/kokincho/grafight/blob/main/game.js"
click node_campaign "https://github.com/kokincho/grafight/blob/main/game.js"
click node_shot_options "https://github.com/kokincho/grafight/blob/main/game.js"
click node_soldier_state "https://github.com/kokincho/grafight/blob/main/game.js"
click node_save_resume "https://github.com/kokincho/grafight/blob/main/game.js"
click node_progress_store "https://github.com/kokincho/grafight/blob/main/game.js"
click node_replay "https://github.com/kokincho/grafight/blob/main/game.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_ui,node_game_control,node_function_input,node_browser toneBlue
class node_expression_parser,node_trajectory_solver,node_terrain,node_combat,node_canvas_render toneAmber
class node_local_modes,node_campaign,node_shot_options,node_soldier_state toneMint
class node_save_resume,node_progress_store,node_replay toneRose
class node_player toneIndigo
```

## Components

### Play and setup

- [Game interface](https://github.com/kokincho/grafight/blob/main/index.html): `index.html`
- [Game control](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`
- [Function input](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`

### Shot simulation

- [Expression parser](https://github.com/kokincho/grafight/blob/main/parser.js): `parser.js`
- [Trajectory simulation](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`
- [Terrain and obstacles](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`
- [Collision and combat](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`
- [Canvas rendering](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`

### Game modes

- [Local multiplayer](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`
- [Campaign stages](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`
- [Shot options](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`
- [Soldier state](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`

### Persistence and review

- [Save and resume](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`
- [Campaign progress](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`
- [Replay and logs](https://github.com/kokincho/grafight/blob/main/game.js): `game.js`

### Other components

- **Player**
- **Browser**

## Connections

- Player → Game interface: uses (evidence: `README.md`)
- Game interface → Game control: starts play
- Game control → Function input: collects input (evidence: `game.js`)
- Function input → Expression parser: compiles expression (evidence: `game.js`)
- Game control → Trajectory simulation: creates shots (evidence: `game.js`)
- Trajectory simulation → Expression parser: evaluates function (evidence: `game.js`)
- Trajectory simulation → Terrain and obstacles: checks obstacles (evidence: `game.js`)
- Game control → Collision and combat: resolves shots (evidence: `game.js`)
- Collision and combat → Soldier state: updates soldiers (evidence: `game.js`)
- Canvas rendering → Game interface: draws board
- Game control → Local multiplayer: runs mode (evidence: `README.md`)
- Game control → Campaign stages: loads stages (evidence: `README.md`)
- Game control → Shot options: applies options (evidence: `README.md`)
- Campaign stages → Campaign progress: saves progress (evidence: `README.md`)
- Player → Save and resume: saves or resumes (evidence: `README.md`)
- Game control → Save and resume: manages session (evidence: `game.js`)
- Game control → Replay and logs: records match (evidence: `game.js`)
- Player → Replay and logs: reviews match (evidence: `README.md`)
- Browser → Campaign progress: stores locally (evidence: `README.md`)
