# mcalus3/color-wars-web architecture

> Architecture diagram of the GitHub repository mcalus3/color-wars-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mcalus3/color-wars-web
- Repository: https://github.com/mcalus3/color-wars-web

## Overview

#### Purpose and runtime
ColorWars is a browser-based, local hot-seat territory game for up to eight players. It is a TypeScript React application using Redux for Model-View-Update-style state management, Konva-backed game rendering, and react-bootstrap controls. Static hosting is implied by the browser entry document at `public/index.html`.

#### Application entry and composition
`src/index.tsx` mounts the React application and loads global styling from `src/index.css`; `src/ColorWars/Game.tsx` is the game-level composition root. It assembles the board, player/status displays, controls, settings, and input surfaces. `src/registerServiceWorker.ts` provides the optional client-side service-worker integration boundary.

#### Central game state and dispatch boundary
Redux is the authoritative game model. Action names and shared constants originate in `src/ColorWars/ReduxStore/actionTypes.ts` and `src/ColorWars/ReduxStore/constants.ts`; the root state transition layer is `src/ColorWars/ReduxStore/reducers/GameReducer.ts`. UI components do not need to own simulation state: container adapters in `src/ColorWars/ReduxStore/containers/Game.ts` and `src/ColorWars/ReduxStore/containers/GameBoard.ts` connect rendered views to state and dispatch.

#### Simulation lifecycle
Game setup creates or changes the world, player count, board dimensions, and map configuration through reducer-stage modules such as `src/ColorWars/ReduxStore/reducers/GameLogic/CreateWorld.ts`, `src/ColorWars/ReduxStore/reducers/GameLogic/SetPlayersAmount.ts`, and `src/ColorWars/ReduxStore/reducers/GameLogic/ResizeBoard.ts`. Runtime advancement is centered on `src/ColorWars/ReduxStore/reducers/GameLogic/Tick.ts`, which advances the match timer and player/game evolution per update cycle.

#### Rules, movement, and territory
Player movement is controlled through keyboard/input direction changes in `src/ColorWars/ReduxStore/reducers/GameLogic/HandleKeyboardInput.ts` and `src/ColorWars/ReduxStore/reducers/GameLogic/changeDirection.ts`. Territory capture and tail-cutting outcomes are encapsulated by `src/ColorWars/ReduxStore/reducers/GameLogic/claimingAlgorithm.ts`; player creation and mutations are handled by `src/ColorWars/ReduxStore/reducers/GameLogic/addPlayer.ts` and `src/ColorWars/ReduxStore/reducers/GameLogic/modifyPlayer.ts`. This reducer layer is the key boundary for gameplay-rule changes.

#### Rendering and interaction
The visual board is represented by `src/ColorWars/ReactView/components/GameBoard.tsx`, with field-level rendering in `src/ColorWars/ReactView/components/Fields.tsx` and player trails in `src/ColorWars/ReactView/components/Tails.tsx`. HUD/state projections include `src/ColorWars/ReactView/components/ScoreBoard.tsx`, `src/ColorWars/ReactView/components/GameElements/Timer.tsx`, and `src/ColorWars/ReactView/components/GameElements/KillsLabel.tsx`. Touch input is isolated in `src/ColorWars/ReactView/components/TouchScreen.tsx`.

#### Configuration and AI
In-match settings are exposed through `src/ColorWars/ReactView/components/SettingsComponent.tsx` and player-specific controls under `src/ColorWars/ReactView/components/Settings/PlayerSettings.tsx`; corresponding state changes pass through Redux containers. AI-controlled players are managed separately from rendering by `src/ColorWars/AI/AIManager.ts`, `src/ColorWars/AI/UpdateAi.ts`, and `src/ColorWars/AI/AiFunctions.ts`, which should produce the same movement/state actions used for human players.

#### Data model and deployment boundary
Shared game object types and initial state live in `src/ColorWars/utils/objectTypes.ts` and `src/ColorWars/utils/initialState.ts`, defining the model consumed by reducers, AI, and views. There is no backend or external game service evident: matches run entirely in the browser, with public assets under `public/`.

Main entry points: [`src/ColorWars/ReduxStore/reducers/GameReducer.ts`](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/reducers/GameReducer.ts) (Game reducer), [`src/ColorWars/Game.tsx`](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/Game.tsx) (Game composition), [`src/index.tsx`](https://github.com/mcalus3/color-wars-web/blob/master/src/index.tsx) (React entry), [`src/ColorWars/ReduxStore/containers/GameBoard.ts`](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/containers/GameBoard.ts) (Board container)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bootstrap["Browser bootstrap"]
  node_html["Browser document<br/>static host<br/>[index.html]"]
  node_entry["React entry<br/>mount<br/>[index.tsx]"]
  node_service_worker["Service worker bridge<br/>optional integration"]
end

subgraph group_ui["React UI"]
  node_game_root["Game composition<br/>React root<br/>[Game.tsx]"]
  node_game_container["Game container<br/>Redux adapter<br/>[Game.ts]"]
  node_board_container["Board container<br/>Redux adapter<br/>[GameBoard.ts]"]
  node_board_view["Konva board<br/>rendered board<br/>[GameBoard.tsx]"]
  node_board_layers["Fields and tails<br/>board layers<br/>[Fields.tsx]"]
  node_hud["Score and status HUD<br/>state projection<br/>[ScoreBoard.tsx]"]
  node_settings["Settings and player controls<br/>input controls"]
  node_touch_input["Touch input<br/>input surface<br/>[TouchScreen.tsx]"]
end

subgraph group_state["Redux game engine"]
  node_reducer{{"Game reducer<br/>root state transition<br/>[GameReducer.ts]"}}
  node_actions["Actions and constants<br/>Redux protocol<br/>[actionTypes.ts]"]
  node_setup["World setup<br/>reducer logic<br/>[CreateWorld.ts]"]
  node_tick["Match tick<br/>reducer logic<br/>[Tick.ts]"]
  node_movement_rules["Movement and territory rules<br/>reducer logic"]
  node_game_model[("Game types and initial state<br/>shared model<br/>[objectTypes.ts]")]
end

subgraph group_automation["AI control"]
  node_ai_manager["AI manager<br/>automated controller<br/>[AIManager.ts]"]
  node_ai_logic["AI update and decisions<br/>AI logic<br/>[UpdateAi.ts]"]
end

node_html -->|"loads"| node_entry
node_entry -->|"mounts"| node_game_root
node_entry -.->|"optionally registers"| node_service_worker
node_game_root -->|"composes"| node_game_container
node_game_root -->|"composes"| node_board_container
node_game_root -->|"composes"| node_hud
node_game_root -->|"composes"| node_settings
node_game_root -->|"composes"| node_touch_input
node_game_container -->|"reads and dispatches"| node_reducer
node_board_container -->|"reads and dispatches"| node_reducer
node_board_container -->|"supplies state"| node_board_view
node_board_view -->|"renders"| node_board_layers
node_hud -->|"projects state"| node_reducer
node_settings -->|"dispatches changes"| node_reducer
node_touch_input -->|"dispatches direction"| node_reducer
node_actions -->|"defines action protocol"| node_reducer
node_reducer -->|"delegates setup"| node_setup
node_reducer -->|"delegates updates"| node_tick
node_reducer -->|"delegates rules"| node_movement_rules
node_reducer -->|"uses state model"| node_game_model
node_ai_manager -->|"runs"| node_ai_logic
node_ai_logic -->|"dispatches movement actions"| node_reducer
node_ai_logic -->|"reads game state"| node_game_model

click node_html "https://github.com/mcalus3/color-wars-web/blob/master/public/index.html"
click node_entry "https://github.com/mcalus3/color-wars-web/blob/master/src/index.tsx"
click node_service_worker "https://github.com/mcalus3/color-wars-web/blob/master/src/registerServiceWorker.ts"
click node_game_root "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/Game.tsx"
click node_game_container "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/containers/Game.ts"
click node_board_container "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/containers/GameBoard.ts"
click node_board_view "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReactView/components/GameBoard.tsx"
click node_board_layers "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReactView/components/Fields.tsx"
click node_hud "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReactView/components/ScoreBoard.tsx"
click node_settings "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReactView/components/SettingsComponent.tsx"
click node_touch_input "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReactView/components/TouchScreen.tsx"
click node_reducer "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/reducers/GameReducer.ts"
click node_actions "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/actionTypes.ts"
click node_setup "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/reducers/GameLogic/CreateWorld.ts"
click node_tick "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/reducers/GameLogic/Tick.ts"
click node_movement_rules "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/reducers/GameLogic/HandleKeyboardInput.ts"
click node_game_model "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/utils/objectTypes.ts"
click node_ai_manager "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/AI/AIManager.ts"
click node_ai_logic "https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/AI/UpdateAi.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_html,node_entry,node_service_worker toneBlue
class node_game_root,node_game_container,node_board_container,node_board_view,node_board_layers,node_hud,node_settings,node_touch_input toneAmber
class node_reducer,node_actions,node_setup,node_tick,node_movement_rules,node_game_model toneMint
class node_ai_manager,node_ai_logic toneRose
```

## Components

### Browser bootstrap

- [Browser document](https://github.com/mcalus3/color-wars-web/blob/master/public/index.html): static host · `public/index.html`
- [React entry](https://github.com/mcalus3/color-wars-web/blob/master/src/index.tsx): mount · `src/index.tsx`
- [Service worker bridge](https://github.com/mcalus3/color-wars-web/blob/master/src/registerServiceWorker.ts): optional integration · `src/registerServiceWorker.ts`

### React UI

- [Game composition](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/Game.tsx): React root · `src/ColorWars/Game.tsx`
- [Game container](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/containers/Game.ts): Redux adapter · `src/ColorWars/ReduxStore/containers/Game.ts`
- [Board container](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/containers/GameBoard.ts): Redux adapter · `src/ColorWars/ReduxStore/containers/GameBoard.ts`
- [Konva board](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReactView/components/GameBoard.tsx): rendered board · Renders fields and player trails. · `src/ColorWars/ReactView/components/GameBoard.tsx`
- [Fields and tails](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReactView/components/Fields.tsx): board layers · `src/ColorWars/ReactView/components/Fields.tsx`
- [Score and status HUD](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReactView/components/ScoreBoard.tsx): state projection · `src/ColorWars/ReactView/components/ScoreBoard.tsx`
- [Settings and player controls](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReactView/components/SettingsComponent.tsx): input controls · `src/ColorWars/ReactView/components/SettingsComponent.tsx`
- [Touch input](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReactView/components/TouchScreen.tsx): input surface · `src/ColorWars/ReactView/components/TouchScreen.tsx`

### Redux game engine

- [Game reducer](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/reducers/GameReducer.ts): root state transition · Authoritative game model and dispatch boundary. · `src/ColorWars/ReduxStore/reducers/GameReducer.ts`
- [Actions and constants](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/actionTypes.ts): Redux protocol · `src/ColorWars/ReduxStore/actionTypes.ts`
- [World setup](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/reducers/GameLogic/CreateWorld.ts): reducer logic · Creates worlds and changes players, board size, and map configuration. · `src/ColorWars/ReduxStore/reducers/GameLogic/CreateWorld.ts`
- [Match tick](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/reducers/GameLogic/Tick.ts): reducer logic · Advances timer and match evolution. · `src/ColorWars/ReduxStore/reducers/GameLogic/Tick.ts`
- [Movement and territory rules](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/ReduxStore/reducers/GameLogic/HandleKeyboardInput.ts): reducer logic · Handles direction, captures, tail cuts, and player mutations. · `src/ColorWars/ReduxStore/reducers/GameLogic/HandleKeyboardInput.ts`
- [Game types and initial state](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/utils/objectTypes.ts): shared model · `src/ColorWars/utils/objectTypes.ts`

### AI control

- [AI manager](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/AI/AIManager.ts): automated controller · Produces the same movement actions as human players. · `src/ColorWars/AI/AIManager.ts`
- [AI update and decisions](https://github.com/mcalus3/color-wars-web/blob/master/src/ColorWars/AI/UpdateAi.ts): AI logic · `src/ColorWars/AI/UpdateAi.ts`

## Connections

- Browser document → React entry: loads
- React entry → Game composition: mounts
- React entry → Service worker bridge: optionally registers
- Game composition → Game container: composes
- Game composition → Board container: composes
- Game composition → Score and status HUD: composes
- Game composition → Settings and player controls: composes
- Game composition → Touch input: composes
- Game container → Game reducer: reads and dispatches
- Board container → Game reducer: reads and dispatches
- Board container → Konva board: supplies state
- Konva board → Fields and tails: renders
- Score and status HUD → Game reducer: projects state
- Settings and player controls → Game reducer: dispatches changes
- Touch input → Game reducer: dispatches direction
- Actions and constants → Game reducer: defines action protocol
- Game reducer → World setup: delegates setup
- Game reducer → Match tick: delegates updates
- Game reducer → Movement and territory rules: delegates rules
- Game reducer → Game types and initial state: uses state model
- AI manager → AI update and decisions: runs
- AI update and decisions → Game reducer: dispatches movement actions
- AI update and decisions → Game types and initial state: reads game state
