# danoverkill/tic_tac_toe architecture

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

- Interactive diagram: https://gitdiagram.com/danoverkill/tic_tac_toe
- Repository: https://github.com/danoverkill/tic_tac_toe

## Overview

#### Purpose and Entry Points
This is a browser-based vanilla JavaScript Tic Tac Toe game using ES modules. `index.html` hosts the board and score UI, loads `main.js`, and `style.css` supplies presentation. `main.js` is the integration boundary between DOM events/rendering and game-domain modules.

Paths: `index.html`, `main.js`, `style.css`

#### UI Integration and Round Controls
`main.js` binds board-cell clicks, updates visible marks/messages/player indicators, blocks invalid input, and creates or handles the “Next Round” interaction. It must respect controller state so the user cannot place marks after a completed round or while the AI is pending.

Paths: `main.js`, `index.html`

#### Board State Model
`GameBoard.js` owns the mutable board-array representation and board-level operations such as placing marks, locating available cells, and resetting for a new round. Other modules should interact through this board abstraction rather than directly coupling to DOM cells.

Paths: `GameBoard.js`, `main.js`

#### Game Orchestration and Rules
`GameControl.js` coordinates player turns, submits moves to the board, evaluates win combinations and ties, ends rounds, and exposes the round outcome (`continue`, `tie`, or `win`) to the UI layer. It is the primary control-flow boundary between raw board state and presentation.

Paths: `GameControl.js`, `GameBoard.js`, `main.js`

#### Player Domain Objects
`Player.js` constructs the human and AI player entities, including identity and assigned mark. `GameControl.js` uses these players to determine current turn and winner, while `main.js` reflects that state in the score/turn display.

Paths: `Player.js`, `GameControl.js`, `main.js`

#### Asynchronous AI Turn Stage
After a valid human move, the controller/UI enters an AI-thinking state (`aiIsThinking`) and schedules AI play. `AiTurn.js` chooses a random available move, which is then processed through the same board and result-evaluation path as a human move. This asynchronous boundary is material: stale or delayed callbacks can desynchronize the displayed turn indicator after AI win/tie rounds.

Paths: `AiTurn.js`, `GameControl.js`, `main.js`

#### Runtime and Dependencies
The application runs entirely in the browser with native ES modules; no backend, database, package runtime, or external service is indicated. State is in memory and resets between rounds, so scores or outcomes are not persisted across page reloads.

Paths: `index.html`, `main.js`, `README.md`

Main entry points: [`GameControl.js`](https://github.com/danoverkill/tic_tac_toe/blob/main/GameControl.js) (Game controller), [`main.js`](https://github.com/danoverkill/tic_tac_toe/blob/main/main.js) (UI integration), [`AiTurn.js`](https://github.com/danoverkill/tic_tac_toe/blob/main/AiTurn.js) (AI move selection), [`GameBoard.js`](https://github.com/danoverkill/tic_tac_toe/blob/main/GameBoard.js) (Board state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser runtime"]
  node_html["Game page<br/>HTML entry<br/>[index.html]"]
  node_styles["Styles<br/>CSS<br/>[style.css]"]
  node_main["UI integration<br/>ES module<br/>[main.js]"]
  node_memory[("In-memory state<br/>runtime state")]
end

subgraph group_domain["Game domain"]
  node_control["Game controller<br/>orchestrator<br/>[GameControl.js]"]
  node_board[("Board state<br/>state model<br/>[GameBoard.js]")]
  node_players["Players<br/>domain factory<br/>[Player.js]"]
  node_ai["AI move selection<br/>async turn stage<br/>[AiTurn.js]"]
end

node_html -->|"loads module"| node_main
node_html -->|"applies"| node_styles
node_main -->|"submits moves / reads outcome"| node_control
node_main -->|"schedules AI turn"| node_ai
node_main -->|"renders scores and state"| node_memory
node_control -->|"places moves, checks cells, resets"| node_board
node_control -->|"tracks turn and winner"| node_players
node_control -->|"maintains round outcome"| node_memory
node_ai -->|"reads available cells"| node_board
node_ai -->|"returns AI move for normal processing"| node_control
node_board -->|"stores board array"| node_memory

click node_html "https://github.com/danoverkill/tic_tac_toe/blob/main/index.html"
click node_styles "https://github.com/danoverkill/tic_tac_toe/blob/main/style.css"
click node_main "https://github.com/danoverkill/tic_tac_toe/blob/main/main.js"
click node_control "https://github.com/danoverkill/tic_tac_toe/blob/main/GameControl.js"
click node_board "https://github.com/danoverkill/tic_tac_toe/blob/main/GameBoard.js"
click node_players "https://github.com/danoverkill/tic_tac_toe/blob/main/Player.js"
click node_ai "https://github.com/danoverkill/tic_tac_toe/blob/main/AiTurn.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_html,node_styles,node_main,node_memory toneBlue
class node_control,node_board,node_players,node_ai toneAmber
```

## Components

### Browser runtime

Native ES-module game with in-memory round state.

- [Game page](https://github.com/danoverkill/tic_tac_toe/blob/main/index.html): HTML entry · Hosts board and score UI and loads the module entry. · `index.html`
- [Styles](https://github.com/danoverkill/tic_tac_toe/blob/main/style.css): CSS · `style.css`
- [UI integration](https://github.com/danoverkill/tic_tac_toe/blob/main/main.js): ES module · Binds DOM events, renders game state, and manages round controls. · `main.js`
- **In-memory state**: runtime state · Round state and scores reset on page reload.

### Game domain

- [Game controller](https://github.com/danoverkill/tic_tac_toe/blob/main/GameControl.js): orchestrator · Coordinates turns, outcomes, and round lifecycle. · `GameControl.js`
- [Board state](https://github.com/danoverkill/tic_tac_toe/blob/main/GameBoard.js): state model · Owns mutable cells, legal placements, available cells, and resets. · `GameBoard.js`
- [Players](https://github.com/danoverkill/tic_tac_toe/blob/main/Player.js): domain factory · Creates human and AI identities with marks. · `Player.js`
- [AI move selection](https://github.com/danoverkill/tic_tac_toe/blob/main/AiTurn.js): async turn stage · Selects a random available move after the thinking delay. · `AiTurn.js`

## Connections

- Game page → UI integration: loads module
- Game page → Styles: applies
- UI integration → Game controller: submits moves / reads outcome
- UI integration → AI move selection: schedules AI turn
- UI integration → In-memory state: renders scores and state
- Game controller → Board state: places moves, checks cells, resets
- Game controller → Players: tracks turn and winner
- Game controller → In-memory state: maintains round outcome
- AI move selection → Board state: reads available cells
- AI move selection → Game controller: returns AI move for normal processing
- Board state → In-memory state: stores board array
