# mdross95/tic-tac-toe architecture

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

- Interactive diagram: https://gitdiagram.com/mdross95/tic-tac-toe
- Repository: https://github.com/mdross95/tic-tac-toe

## Overview

##### Project type and purpose
- This is a standalone, command-line C++ “game engine” project (likely a turn-based board game).
- It provides both the core game executable (“game”) and a test suite executable (“test”).

##### File structure
- Top-level source files (.cpp / .hpp) implement all major components:
- Game.hpp/.cpp – orchestrates the main game loop
- Board.hpp/.cpp – represents the board state (Spot objects)
- Spot.hpp/.cpp – represents a single board cell
- Player.hpp/.cpp – abstract base class for players
- HumanPlayer.hpp/.cpp and AIPlayer.hpp/.cpp – concrete Player subclasses (Strategy pattern)
- CreatePlayers.hpp/.cpp – Factory that instantiates players based on user choice
- SetupGame.hpp/.cpp – collects player types/parameters, initializes Game and Board
- InputOutput.hpp/.cpp – handles console I/O (prompting, drawing board, reading moves)
- Makefile – build targets for game and test
- “game” directory contains the game’s main.cpp (entry point).
- “test” directory contains test.cpp (unit/integration tests entry point).

##### README
- Confirms two build targets: `make game` and `make test`.

- UI Layer
- InputOutput
- Domain Model
- Spot
- Board (aggregates Spots)
- Game Controller
- Game (game loop, turn management)
- SetupGame (initialization)
- CreatePlayers (player factory)
- Player Strategies
- Player interface
- HumanPlayer (reads moves via InputOutput)
- AIPlayer (computes moves via some algorithm)
- Validation Layer
- Test Harness (separate “test” executable using the same Domain and Controller components)

b. Relationships and interactions
- SetupGame → CreatePlayers → Player instances
- SetupGame → Board
- Game ↔ Board (reads and writes cell state)
- Game ↔ Player (Game invokes Player::makeMove(Board&))
- Player (Human/AI) ↔ InputOutput (for I/O)
- After each Player move, Game calls Validate to enforce rules
- On game end, InputOutput displays result
- Test executable depends on all modules except InputOutput (can mock/stub I/O)

c. Architectural patterns and design principles
- Strategy pattern (Player interface + HumanPlayer/AIPlayer)
- Factory pattern (CreatePlayers)
- Single Responsibility (separate I/O, validation, game logic, board representation)
- Layered design: UI → Controller → Domain → Validation

d. Key technologies and build artifacts
- C++17 (or earlier) with header/source separation
- Makefile targets (“game” and “test”)
- Directory-based separation of production code and test code

##### Elements
- Initialize: SetupGame → CreatePlayers → Player
- Control flow: Game → Player → (via InputOutput or AI logic)
- State change: Game → Board → Spot
- Validation: Game → Validate → Board
- Output result: Game → InputOutput
- Tests: TestSuite → [all core modules]
- Controller/Orchestration (Game, SetupGame, CreatePlayers) in another
- Domain model (Board, Spot) in a third
- Strategy implementations (HumanPlayer, AIPlayer) in a fourth
- Validation in a fifth
- Test harness in a sixth

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        IO["InputOutput"]:::ui
    end

    %% Controller Layer
    subgraph "Controller"
        SG["SetupGame"]:::controller
        CP["CreatePlayers"]:::controller
        G["Game"]:::controller
    end

    %% Domain Model
    subgraph "Domain Model"
        B["Board"]:::domain
        S["Spot"]:::domain
    end

    %% Strategy Pattern
    subgraph "Player Strategies"
        PI["Player"]:::strategy
        HP["HumanPlayer"]:::strategy
        AP["AIPlayer"]:::strategy
    end

    %% Validation Layer
    subgraph "Validation"
        V["Validate"]:::validation
    end

    %% Test Harness
    subgraph "Test Suite"
        TS["TestSuite"]:::test
    end

    %% Relationships
    SG --> CP
    SG --> B
    CP --> PI
    G --> B
    G --> PI
    G --> V
    G --> IO
    PI --> IO
    HP --> IO
    AP --> IO
    B --> S
    TS --> SG
    TS --> CP
    TS --> G
    TS --> B
    TS --> S
    TS --> PI
    TS --> HP
    TS --> AP
    TS --> V

    %% Click Events
    click IO "https://github.com/mdross95/tic-tac-toe/blob/master/InputOutput.hpp"
    click SG "https://github.com/mdross95/tic-tac-toe/blob/master/SetupGame.hpp"
    click CP "https://github.com/mdross95/tic-tac-toe/blob/master/CreatePlayers.hpp"
    click G "https://github.com/mdross95/tic-tac-toe/blob/master/Game.hpp"
    click B "https://github.com/mdross95/tic-tac-toe/blob/master/Board.hpp"
    click S "https://github.com/mdross95/tic-tac-toe/blob/master/Spot.hpp"
    click PI "https://github.com/mdross95/tic-tac-toe/blob/master/Player.hpp"
    click HP "https://github.com/mdross95/tic-tac-toe/blob/master/HumanPlayer.hpp"
    click AP "https://github.com/mdross95/tic-tac-toe/blob/master/AIPlayer.hpp"
    click V "https://github.com/mdross95/tic-tac-toe/blob/master/Validate.hpp"
    click TS "https://github.com/mdross95/tic-tac-toe/blob/master/test/test.cpp"

    %% Styles
    classDef ui fill:#ffcccc,stroke:#cc0000,stroke-width:2px
    classDef controller fill:#ccffcc,stroke:#009900,stroke-width:2px
    classDef domain fill:#ccccff,stroke:#0000cc,stroke-width:2px
    classDef strategy fill:#ffebcc,stroke:#cc8800,stroke-width:2px
    classDef validation fill:#f2ccff,stroke:#9900cc,stroke-width:2px
    classDef test fill:#e6e6e6,stroke:#666666,stroke-width:2px
```
