# eltaweel1/advanced_tic_tac_toe architecture

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

- Interactive diagram: https://gitdiagram.com/eltaweel1/advanced_tic_tac_toe
- Repository: https://github.com/eltaweel1/advanced_tic_tac_toe

## Overview

##### Project type and purpose
- This is a desktop application: an “Advanced Tic Tac Toe” game written in C++ using the Qt framework.
- Purpose: provide a GUI-based tic-tac-toe with user login/registration, AI opponents at multiple difficulties, play-history per user, and two-player mode.

##### File structure (high-level)
- Top‐level .pro file: Qt project descriptor.
- Core modules (src): ai.{cpp,h}, board.{cpp,h}, gamelogic.{cpp,h}, usermanager.{cpp,h}
- GUI modules (gui): mainwindow.{h,cpp,ui}, loginform, registerform, gamesetupdialog, historydialog
- Data storage (database): users.txt, history.txt under build or root
- Tests: test/test_gamelogic.cpp

##### Key insights from README
- Project is layered: UI forms, game logic/AI/user management, file-based persistence.
- Tech stack: C++/Qt, OOP, local file system for “database.”

##### Main components
a. Presentation Layer (GUI)
- LoginForm
- RegisterForm
- MainWindow
- GameSetupDialog
- HistoryDialog
b. Application/Domain Layer
- UserManager (handles login, registration, file I/O for users.txt)
- GameLogic (enforces rules, tracks game state)
- Board (data structure representing the board)
- AI (computes moves based on difficulty)
c. Data Layer (Persistence)
- FileStorage for users (users.txt)
- FileStorage for game history (history.txt)
d. External/Tools
- Qt framework (signals & slots, .ui processing)
- Test suite (test/test_gamelogic.cpp)

##### Relationships and interactions
- UI → Domain: e.g., MainWindow calls GameLogic to start/advance a game; AI queries Board & GameLogic.
- UI ↔ UserManager: LoginForm/RegisterForm invoke UserManager to authenticate or register users.
- Domain → Data: UserManager reads/writes users.txt; GameLogic or HistoryDialog writes game results to history.txt.
- Data → UI: HistoryDialog reads history.txt via UserManager or a HistoryService.
- All components depend on Qt (for windowing, events, object macros).

##### Architectural patterns/design principles
- Layered architecture (Presentation → Domain → Data).
- Separation of concerns: UI code (dialogs/windows) is separate from core logic (GameLogic, AI).
- Single Responsibility: each class has one clear purpose (Board = model, UserManager = auth & storage).
- File‐based repository pattern for persistence.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer (GUI)
    subgraph "GUI (Qt)"
        direction TB
        LoginForm["LoginForm"]:::gui
        RegisterForm["RegisterForm"]:::gui
        MainWindow["MainWindow"]:::gui
        GameSetupDialog["GameSetupDialog"]:::gui
        HistoryDialog["HistoryDialog"]:::gui
    end

    %% Domain Logic Layer
    subgraph "Domain Logic"
        direction TB
        UserManager["UserManager"]:::domain
        GameLogic["GameLogic"]:::domain
        Board["Board"]:::domain
        AI["AI"]:::domain
    end

    %% Data Layer (Persistence)
    subgraph "File Storage"
        direction TB
        UsersTXT["users.txt"]:::data
        HistoryTXT["history.txt"]:::data
    end

    %% External/Tools
    subgraph "External"
        direction TB
        QtFramework["Qt Framework (.pro)"]:::external
        TestSuite["Test Suite"]:::external
    end

    %% UI -> Domain interactions
    LoginForm -->|"authenticate()"| UserManager
    RegisterForm -->|"register()"| UserManager
    MainWindow -->|"startGame()"| GameLogic
    MainWindow -->|"requestUser()"| UserManager
    GameSetupDialog -->|"configureGame()"| GameLogic
    HistoryDialog -->|"loadHistory()"| HistoryTXT

    %% Domain -> Data interactions
    UserManager -->|"loadUsers()/saveUsers()"| UsersTXT
    GameLogic -->|"saveHistory()"| HistoryTXT

    %% Domain internal interactions
    AI -->|"computeMove()"| Board
    AI -->|"evaluateMove()"| GameLogic
    GameLogic -->|"updateBoard()"| Board

    %% External dependencies
    QtFramework -.-> LoginForm
    QtFramework -.-> RegisterForm
    QtFramework -.-> MainWindow
    QtFramework -.-> GameSetupDialog
    QtFramework -.-> HistoryDialog
    QtFramework -.-> UserManager
    QtFramework -.-> GameLogic
    QtFramework -.-> Board
    QtFramework -.-> AI
    TestSuite -.-> GameLogic

    %% Click Events
    click LoginForm "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/loginform.cpp"
    click RegisterForm "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/registerform.cpp"
    click MainWindow "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/mainwindow.ui"
    click GameSetupDialog "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/gamesetupdialog.cpp"
    click HistoryDialog "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/historydialog.cpp"
    click UserManager "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/usermanager.cpp"
    click GameLogic "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/gamelogic.cpp"
    click Board "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/board.cpp"
    click AI "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/ai.cpp"
    click UsersTXT "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/build/Desktop_Qt_6_9_0_MinGW_64_bit-Debug/users.txt"
    click HistoryTXT "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/build/Desktop_Qt_6_9_0_MinGw_64_bit-Debug/history.txt"
    click QtFramework "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/advanced_tic_tac_toe.pro"
    click TestSuite "https://github.com/eltaweel1/advanced_tic_tac_toe/blob/main/test/test_gamelogic.cpp"

    %% Styles
    classDef gui fill:#D0E6FF,stroke:#0366D6,stroke-width:1px
    classDef domain fill:#DFF4DD,stroke:#2C662D,stroke-width:1px
    classDef data fill:#FFF5CC,stroke:#927700,stroke-width:1px
    classDef external fill:#EDEDED,stroke:#777777,stroke-width:1px
```
