# josh-ay/tic-tac-toe architecture

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

- Interactive diagram: https://gitdiagram.com/josh-ay/tic-tac-toe
- Repository: https://github.com/josh-ay/tic-tac-toe
- Video tour (about a minute): https://gitdiagram.com/josh-ay/tic-tac-toe/video

## Overview

This is a small, terminal-based Tic Tac Toe game. The user chooses a marker and numbered square; `main.py` coordinates input, alternates the user's move with a random computer move, checks for a winner, displays the outcome, and offers replay. `Brain` tracks available squares and evaluates winning lines, while `Board` stores and updates the displayed board. The optional-looking screen-clear behavior uses `pyautogui`; source excerpts show its call but not how it behaves across environments.

Main entry points: [`main.py`](https://github.com/josh-ay/tic-tac-toe/blob/main/main.py) (Game coordinator), [`brain.py`](https://github.com/josh-ay/tic-tac-toe/blob/main/brain.py) (Rules and options), [`clear.py`](https://github.com/josh-ay/tic-tac-toe/blob/main/clear.py) (Screen clearing), [`board.py`](https://github.com/josh-ay/tic-tac-toe/blob/main/board.py) (Board state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Game flow"]
  node_main["Game coordinator<br/>[main.py]"]
end

subgraph group_logic["Game logic"]
  node_brain["Rules and options<br/>[brain.py]"]
  node_board["Board state<br/>[board.py]"]
end

subgraph group_terminal["Terminal display"]
  node_clear["Screen clearing<br/>[clear.py]"]
end

node_user(("Player"))
node_pyautogui["pyautogui"]
node_random["Python random"]

node_user -->|"enters moves"| node_main
node_main -->|"calls game methods"| node_brain
node_main -->|"creates and updates"| node_board
node_main -->|"chooses computer move"| node_random
node_main -->|"requests clearing"| node_clear
node_brain -->|"reads board"| node_board
node_clear -->|"uses controls"| node_pyautogui

click node_main "https://github.com/josh-ay/tic-tac-toe/blob/main/main.py"
click node_brain "https://github.com/josh-ay/tic-tac-toe/blob/main/brain.py"
click node_board "https://github.com/josh-ay/tic-tac-toe/blob/main/board.py"
click node_clear "https://github.com/josh-ay/tic-tac-toe/blob/main/clear.py"

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_main,node_pyautogui toneBlue
class node_brain,node_board toneAmber
class node_clear toneMint
class node_user,node_random toneIndigo
```

## Components

### Game flow

- [Game coordinator](https://github.com/josh-ay/tic-tac-toe/blob/main/main.py): `main.py`

### Game logic

- [Rules and options](https://github.com/josh-ay/tic-tac-toe/blob/main/brain.py): `brain.py`
- [Board state](https://github.com/josh-ay/tic-tac-toe/blob/main/board.py): `board.py`

### Terminal display

- [Screen clearing](https://github.com/josh-ay/tic-tac-toe/blob/main/clear.py): `clear.py`

### Other components

- **Player**
- **pyautogui**
- **Python random**

## Connections

- Player → Game coordinator: enters moves
- Game coordinator → Rules and options: calls game methods
- Game coordinator → Board state: creates and updates
- Game coordinator → Python random: chooses computer move
- Game coordinator → Screen clearing: requests clearing
- Rules and options → Board state: reads board
- Screen clearing → pyautogui: uses controls
