# get-convex/tic-tac-convex architecture

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

- Interactive diagram: https://gitdiagram.com/get-convex/tic-tac-convex
- Repository: https://github.com/get-convex/tic-tac-convex

## Overview

##### Project Type and Purpose
- This is a single-page web application (SPA) built with React and TypeScript, delivered via Vite, that lets users play multiplayer Tic-Tac-Toe against human or AI opponents. All game state and AI logic live in the browser; there is no server component in the repo.

##### Top-Level Structure
- “public/” & index.html: static assets and HTML entry point
- “src/”
- main.tsx & App.tsx – app bootstrap & root component
- routes.ts – client-side routing with type-route
- components/ – UI components (Auth, GameBoard, GameList, common/Button, common/Redirect)
- game/ – core game logic (gameLogic.ts), AI hook (useAIPlayer.ts), state hook (useGameState.ts)
- assets & styles – Tailwind CSS, PostCSS, index.css
- Config & tooling: tsconfig*, vite.config.ts, tailwind.config.js, eslint.config.js, bun.lockb.

##### Key Architectural Elements
a. UI Layer (React Components)
- Entry: App.tsx renders layout, injects RouteProvider, shows GameList or GameBoard based on route.
- Common Components: style‐agnostic Button, Redirect handle navigation and user actions.
b. Routing Layer
- routes.ts defines URL → component mappings; RouteProvider wraps App.
c. State Management Layer
- useGameState hook manages in-memory game data and syncs it to localStorage.
- Exposes actions: create/join game, add AI, make moves.
d. Game Logic & AI Layer
- gameLogic.ts: pure functions checkWinner, getAvailableMoves.
- useAIPlayer: watches game state, triggers AI moves via gameLogic.
e. Persistence
- localStorage used for session continuity; no external database.
f. Build & Tooling
- Vite bundler, TypeScript compiler, Tailwind CSS processor, ESLint.

##### Detail Orientation
- Submodule: Routing (routes.ts), Authentication component, GameList vs GameBoard.
- Call out the two custom hooks separately.
- If desired, annotate data schemas (Player, GameState, Game).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User & Browser
    User["User"]:::external
    Browser["Browser"]:::external

    %% UI Layer
    subgraph "UI Layer"
        direction TB
        Main["main.tsx"]:::frontend
        App["App.tsx"]:::frontend
        Auth["Auth Component"]:::frontend
        GameList["GameList Component"]:::frontend
        GameBoard["GameBoard Component"]:::frontend
        Button["Button Component"]:::frontend
        Redirect["Redirect Component"]:::frontend
    end

    %% Routing Layer
    subgraph "Routing Layer"
        direction TB
        Routes["routes.ts"]:::frontend
    end

    %% Game Engine Layer
    subgraph "Game Engine"
        direction TB
        GameState["useGameState Hook"]:::logic
        AIPlayer["useAIPlayer Hook"]:::logic
        Logic["gameLogic.ts"]:::logic
    end

    %% Persistence Layer
    subgraph "Persistence"
        direction TB
        Storage[/"localStorage"/]:::persist
    end

    %% Assets & Styles
    subgraph "Assets & Styles"
        direction TB
        Assets["assets/"]:::frontend
        Styles["index.css"]:::frontend
    end

    %% Build & Tooling
    subgraph "Build & Tooling"
        direction TB
        Vite["vite.config.ts"]:::tooling
        TSConfig["tsconfig*.json"]:::tooling
        ESLint["eslint.config.js"]:::tooling
    end

    %% Connections
    User --> Browser
    Browser --> Main
    Main --> App
    App --> Routes
    Routes --> Auth
    Routes --> GameList
    Routes --> GameBoard
    Auth --> GameState
    GameList --> GameState
    GameBoard --> GameState
    GameState --> GameList
    GameState --> GameBoard
    GameState --> Storage
    GameState --> AIPlayer
    AIPlayer --> Logic
    Logic --> GameState
    Main --> Assets
    Main --> Styles
    Vite --> Main
    TSConfig --> Main
    ESLint --> Main

    %% Click Events
    click Main "https://github.com/get-convex/tic-tac-convex/blob/main/src/main.tsx"
    click App "https://github.com/get-convex/tic-tac-convex/blob/main/src/App.tsx"
    click Routes "https://github.com/get-convex/tic-tac-convex/blob/main/src/routes.ts"
    click Auth "https://github.com/get-convex/tic-tac-convex/blob/main/src/components/Auth.tsx"
    click GameList "https://github.com/get-convex/tic-tac-convex/blob/main/src/components/GameList.tsx"
    click GameBoard "https://github.com/get-convex/tic-tac-convex/blob/main/src/components/GameBoard.tsx"
    click Button "https://github.com/get-convex/tic-tac-convex/blob/main/src/components/common/Button.tsx"
    click Redirect "https://github.com/get-convex/tic-tac-convex/blob/main/src/components/common/Redirect.tsx"
    click Logic "https://github.com/get-convex/tic-tac-convex/blob/main/src/game/gameLogic.ts"
    click AIPlayer "https://github.com/get-convex/tic-tac-convex/blob/main/src/game/useAIPlayer.ts"
    click GameState "https://github.com/get-convex/tic-tac-convex/blob/main/src/game/useGameState.ts"
    click Styles "https://github.com/get-convex/tic-tac-convex/blob/main/src/index.css"
    click Assets "https://github.com/get-convex/tic-tac-convex/tree/main/src/assets/"
    click Vite "https://github.com/get-convex/tic-tac-convex/blob/main/vite.config.ts"
    click TSConfig "https://github.com/get-convex/tic-tac-convex/blob/main/tsconfig.json"
    click ESLint "https://github.com/get-convex/tic-tac-convex/blob/main/eslint.config.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#005B96,color:#003f6b
    classDef logic fill:#E0F8D8,stroke:#2E8B57,color:#2E8B57
    classDef persist fill:#FFE4B5,stroke:#CC8400,color:#8B4513
    classDef tooling fill:#F2F2F2,stroke:#999999,color:#333333
    classDef external fill:#F5F5F5,stroke:#CCCCCC,color:#333333,stroke-dasharray: 5 5
```
