# sehajimal/tic-tac-toe architecture

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

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

## Overview

##### Project type and purpose
- This is a pair of Java-based Tic-Tac-Toe console applications (“AdvancedPlay” and “RegularPlay”), each packaged as a single Maven module.
- Purpose: Provide a CLI game (Player vs Player or Player vs Computer) with in-memory domain logic using OOP, and in the AdvancedPlay version, a slightly more sophisticated AI/board modifier component.

##### File structure
- Top-level directories:
- AdvancedPlay/ and RegularPlay/ – two separate Maven projects
- Each has pom.xml, .mvn/ for Maven wrapper, src/main/java/play for code, src/test for unit tests, target/ for build artifacts.
- play/ package contains:
- App.java – entry point / presentation layer (CLI)
- Domain model: Board.java, Game.java, Player.java (+ HumanPlayer, ComputerPlayer)
- Service/repository layers: ComputerService.java, ComputerRepository.java, GameRepository.java (and BoardModifier.java in AdvancedPlay)
- No external database or web framework – all data is in memory; no external services.

##### Key README insights
- Two modes: PvP and PvC
- “AI-Powered Computer Player” implies a strategy component (ComputerService + BoardModifier in AdvancedPlay)
- Console UI, no network or persistence beyond in-memory.

##### Main components and their relationships
a. Presentation Layer
- App (CLI): reads user input, displays the board, orchestrates game loop.
b. Domain Layer
- Board: grid representation and utilities.
- Player (abstract): common interface for HumanPlayer vs ComputerPlayer.
c. Service/AI Layer
- ComputerService: decides AI moves, invokes BoardModifier (AdvancedPlay) to simulate/evaluate.
- BoardModifier (AdvancedPlay only): generates and scores possible board states using simple heuristics or minimax.
d. Repository Layer (in-memory)
- GameRepository: holds current or past Game instances (e.g., for “replay option”).
- ComputerRepository: (AdvancedPlay) caches evaluated board positions or AI decision history.
e. Build & Test
- Maven plugin compiles and packages JAR.
- src/test/java/play/AppTest.java validates core flow.

##### Architectural patterns & principles
- Layered architecture: Presentation → Domain → Service/AI → Repository
- Dependency inversion: App depends on abstract Player interface, not concrete classes.
- Single Responsibility: BoardModifier and ComputerService isolated AI logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        CLI["CLI App\n(play.App)"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        Game["Game\n(play.Game)"]:::domain
        Board["Board\n(play.Board)"]:::domain
        PlayerI["Player (interface)\n(play.Player)"]:::domain
        Human["HumanPlayer\n(play.HumanPlayer)"]:::domain
        CompP["ComputerPlayer\n(play.ComputerPlayer)"]:::domain
    end

    %% Service/AI Layer
    subgraph "Service/AI Layer"
        CS["ComputerService\n(play.ComputerService)"]:::ai
        BM["BoardModifier\n(play.BoardModifier)"]:::ai
    end

    %% Repository Layer
    subgraph "Repository Layer"
        GR["GameRepository\n(play.GameRepository)"]:::repo
        CR["ComputerRepository\n(play.ComputerRepository)"]:::repo
    end

    %% Test Boundary
    subgraph "Test Boundary"
        AppTest["AppTest\n(play.AppTest)"]:::test
    end

    %% Relationships
    CLI -->|"startGame()/nextMove()"| Game
    Game -->|"read/write board"| Board
    Game -->|"requestMove()"| Human
    Game -->|"requestMove()"| CompP
    CompP -->|"getMove()"| CS
    CS -->|"evaluateBoard()"| BM
    CS -->|"cache lookup"| CR
    Game -->|"save/load"| GR
    AppTest -.->|tests CLI flow| CLI

    %% Click Events
    click CLI "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/main/java/play/App.java"
    click CLI "https://github.com/sehajimal/tic-tac-toe/blob/main/RegularPlay/src/main/java/play/App.java"
    click Game "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/main/java/play/Game.java"
    click Game "https://github.com/sehajimal/tic-tac-toe/blob/main/RegularPlay/src/main/java/play/Game.java"
    click Board "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/main/java/play/Board.java"
    click Board "https://github.com/sehajimal/tic-tac-toe/blob/main/RegularPlay/src/main/java/play/Board.java"
    click PlayerI "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/main/java/play/Player.java"
    click PlayerI "https://github.com/sehajimal/tic-tac-toe/blob/main/RegularPlay/src/main/java/play/Player.java"
    click Human "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/main/java/play/HumanPlayer.java"
    click Human "https://github.com/sehajimal/tic-tac-toe/blob/main/RegularPlay/src/main/java/play/HumanPlayer.java"
    click CompP "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/main/java/play/ComputerPlayer.java"
    click CompP "https://github.com/sehajimal/tic-tac-toe/blob/main/RegularPlay/src/main/java/play/ComputerPlayer.java"
    click CS "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/main/java/play/ComputerService.java"
    click CS "https://github.com/sehajimal/tic-tac-toe/blob/main/RegularPlay/src/main/java/play/ComputerService.java"
    click BM "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/main/java/play/BoardModifier.java"
    click GR "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/main/java/play/GameRepository.java"
    click GR "https://github.com/sehajimal/tic-tac-toe/blob/main/RegularPlay/src/main/java/play/GameRepository.java"
    click CR "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/main/java/play/ComputerRepository.java"
    click AppTest "https://github.com/sehajimal/tic-tac-toe/blob/main/AdvancedPlay/src/test/java/play/AppTest.java"
    click AppTest "https://github.com/sehajimal/tic-tac-toe/blob/main/RegularPlay/src/test/java/play/AppTest.java"

    %% Styles
    classDef presentation fill:#d4f4dd,stroke:#333,stroke-width:1px
    classDef domain fill:#d0e7ff,stroke:#333,stroke-width:1px
    classDef ai fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef repo fill:#e0e0e0,stroke:#333,stroke-width:1px
    classDef test fill:#f0f0f0,stroke:#333,stroke-width:1px,stroke-dasharray:5 5
```
