How get-convex/tic-tac-convex works
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).