# passgage/connect-four-game architecture

> Architecture diagram of the GitHub repository passgage/connect-four-game, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/passgage/connect-four-game
- Repository: https://github.com/passgage/connect-four-game

## Overview

##### Main Components Structure

a) Core Application Layer
- Redux store as a central state management hub
- Main pages (MainMenu, Game, Rules)
- Layout component as a wrapper

b) Game Logic Layer
- Separate the AI logic (minimax algorithm)
- Worker thread implementation for CPU-intensive tasks
- Game state management
- Win condition checking

##### Detailed Component Breakdown

a) UI Components Hierarchy
- MenuWrapper
- Modal system
- Game board components
- Control elements (Counter, Timer, etc.)

b) State Management Flow
- Redux store connections
- Game slice
- Modal slice
- State update patterns

##### Specific Implementation Details

**[Frontend Application]**
- [Redux Store]
- Game Slice
- Modal Slice
- [UI Layer]
- Layout
- Menu System
- Game Components
- [Game Logic]
- Main Thread
- Web Worker (AI)
- [Helper Functions]
- AI Move Calculator
- Board Score Evaluator
- Win Condition Checker

##### Technical Stack Highlights

Clear integration points for:
- React components
- Redux Toolkit state management
- Styled Components styling system
- Web Workers for AI processing

##### Testing Coverage

A separate section showing:
- Component test coverage
- Helper function tests
- Store tests
- E2E testing with Cypress

##### Specific Architecture Patterns

Emphasize:
- Component composition pattern
- State management centralization
- Worker thread offloading
- Responsive design implementation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef state fill:#2ecc71,stroke:#27ae60,color:white
    classDef logic fill:#f1c40f,stroke:#f39c12,color:black
    classDef worker fill:#e74c3c,stroke:#c0392b,color:white
    classDef test fill:#9b59b6,stroke:#8e44ad,color:white

    %% Main Application Structure
    subgraph CoreApp["Core Application Layer"]
        Store["Redux Store"]:::state
        GameSlice["Game Slice"]:::state
        ModalSlice["Modal Slice"]:::state
        
        Store --> GameSlice
        Store --> ModalSlice
    end

    subgraph UILayer["UI Layer"]
        Layout["Layout Component"]:::frontend
        
        subgraph Pages["Main Pages"]
            MainMenu["Main Menu"]:::frontend
            GamePage["Game Page"]:::frontend
            RulesPage["Rules Page"]:::frontend
        end
        
        subgraph Components["UI Components"]
            MenuWrapper["Menu Wrapper"]:::frontend
            Modal["Modal System"]:::frontend
            GameBoard["Game Board"]:::frontend
            Counter["Counter"]:::frontend
            Timer["Timer"]:::frontend
        end
        
        subgraph GameComponents["Game Components"]
            Board["Board"]:::frontend
            ControlGrid["Control Grid"]:::frontend
            CounterGrid["Counter Grid"]:::frontend
            GameInfo["Game Info"]:::frontend
            PlayerInfo["Player Info"]:::frontend
        end
    end

    subgraph GameLogic["Game Logic Layer"]
        MainThread["Main Thread"]:::logic
        WebWorker["Web Worker"]:::worker
        
        subgraph Helpers["Helper Functions"]
            AIMoveCalc["AI Move Calculator"]:::logic
            BoardScore["Board Score Evaluator"]:::logic
            WinChecker["Win Condition Checker"]:::logic
        end
    end

    subgraph Testing["Testing Coverage"]
        E2ETests["E2E Tests"]:::test
        ComponentTests["Component Tests"]:::test
        StoreTests["Store Tests"]:::test
        HelperTests["Helper Tests"]:::test
    end

    %% Relationships
    Layout --> Pages
    Layout --> Components
    GamePage --> GameComponents
    MainThread --> WebWorker
    WebWorker --> AIMoveCalc
    AIMoveCalc --> BoardScore
    GameBoard --> WinChecker
    Store --> UILayer

    %% Click Events
    click Store "https://github.com/passgage/connect-four-game/blob/main/src/store/store.ts"
    click GameSlice "https://github.com/passgage/connect-four-game/blob/main/src/store/gameSlice.ts"
    click ModalSlice "https://github.com/passgage/connect-four-game/blob/main/src/store/modalSlice.ts"
    click MainMenu "https://github.com/passgage/connect-four-game/blob/main/src/pages/MainMenu.tsx"
    click GamePage "https://github.com/passgage/connect-four-game/blob/main/src/pages/Game.tsx"
    click RulesPage "https://github.com/passgage/connect-four-game/blob/main/src/pages/Rules.tsx"
    click Layout "https://github.com/passgage/connect-four-game/blob/main/src/components/UI/layout/Layout.tsx"
    click AIMoveCalc "https://github.com/passgage/connect-four-game/blob/main/src/helpers/aiMove.ts"
    click WebWorker "https://github.com/passgage/connect-four-game/blob/main/src/helpers/worker.ts"
    click WinChecker "https://github.com/passgage/connect-four-game/blob/main/src/helpers/checkForWin.ts"
    click BoardScore "https://github.com/passgage/connect-four-game/blob/main/src/helpers/boardScore.ts"
    click MenuWrapper "https://github.com/passgage/connect-four-game/blob/main/src/components/UI/menuWrapper/MenuWrapper.tsx"
    click Modal "https://github.com/passgage/connect-four-game/blob/main/src/components/UI/modal/Modal.tsx"
    click GameBoard "https://github.com/passgage/connect-four-game/blob/main/src/components/game/gameBoard/GameBoard.tsx"
    click Counter "https://github.com/passgage/connect-four-game/blob/main/src/components/UI/counter/Counter.tsx"
    click Timer "https://github.com/passgage/connect-four-game/blob/main/src/components/UI/timer/Timer.tsx"
    click Board "https://github.com/passgage/connect-four-game/blob/main/src/components/game/board/Board.tsx"
    click ControlGrid "https://github.com/passgage/connect-four-game/blob/main/src/components/game/controlGrid/ControlGrid.tsx"
    click CounterGrid "https://github.com/passgage/connect-four-game/blob/main/src/components/game/counterGrid/CounterGrid.tsx"
    click GameInfo "https://github.com/passgage/connect-four-game/blob/main/src/components/game/gameInfo/GameInfo.tsx"
    click PlayerInfo "https://github.com/passgage/connect-four-game/blob/main/src/components/game/playerInfo/PlayerInfo.tsx"
    click E2ETests "https://github.com/passgage/connect-four-game/blob/main/cypress/e2e/pvpmodec_spec..cy.ts"
    click ComponentTests "https://github.com/passgage/connect-four-game/tree/main/src/components"
    click StoreTests "https://github.com/passgage/connect-four-game/tree/main/src/store/__test__"
    click HelperTests "https://github.com/passgage/connect-four-game/tree/main/src/helpers/__test__"
```
