# barbacoa08/andesite-battleship architecture

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

- Interactive diagram: https://gitdiagram.com/barbacoa08/andesite-battleship
- Repository: https://github.com/barbacoa08/andesite-battleship

## Overview

##### Project type and purpose
- This is a React-and-TypeScript single-page application (SPA) that implements a 1v1 Battleship game.
- It lives entirely in the browser, is hosted as static assets (Netlify), and has no separate backend service in this repo.
- Key purpose: deliver an interactive Battleship UX (drag-and-drop setup, turn-based play) with all game logic on the client.

##### File structure
- Top-level files and config:
– index.html, netlify.toml → static entry point + hosting config
– package.json, pnpm-lock, pnpm-workspace → monorepo/package manager setup
– tsconfig.*, vite.config.ts → TypeScript + build config
– .github/workflows → CI for lint/tests
- src directory breakdown:
– src/main.tsx → React app bootstrap
– src/Router.tsx → client-side routing (Home vs Battleship pages)
– src/GlobalContext.tsx → React Context for shared game state
– src/pages → high-level views: Home.page.tsx, Battleship.page.tsx
– src/components → UI building blocks, including Battleship (board, messages, headers, drag-and-drop logic), Welcome, ToDos
– src/components/Battleship/utils → core game algorithms (auto-place, place-ship, starting-board, rotation handler, use-game-state hook)
– test-utils + vitest.config → local testing setup

##### README for additional insights
- Focus areas: gameplay UX, APIs (functions/hooks for game logic), code structure.
- No mention of server or database—everything is client-side.
- CI/CD expectations: demo the working app, discuss tradeoffs, reliability, scaling (though minimal back end).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    subgraph "User Interaction Layer"
        User["User"]:::user
    end

    %% Browser & Hosting
    subgraph "Browser & Hosting"
        Browser["Browser"]:::infra
        indexHtml["index.html"]:::infra
        netlifyToml["netlify.toml"]:::infra
        publicDir["public/"]:::infra
        Netlify["Netlify/CDN"]:::infra
    end

    %% React SPA Application
    subgraph "React SPA"
        main["App Bootstrap\nsrc/main.tsx"]:::app
        Router["Router\nsrc/Router.tsx"]:::app
        GlobalContext["GlobalContext\nsrc/GlobalContext.tsx"]:::state

        subgraph "Pages"
            Home["Home Page\nsrc/pages/Home.page.tsx"]:::pages
            BattleshipPage["Battleship Page\nsrc/pages/Battleship.page.tsx"]:::pages
        end

        subgraph "Components"
            Welcome["Welcome Component\nsrc/components/Welcome/Welcome.tsx"]:::ui
            ToDos["ToDos Component\nsrc/components/ToDos.tsx"]:::ui

            subgraph "Battleship Components"
                BattleshipWrapper["Battleship Wrapper\nsrc/components/Battleship/Battleship.tsx"]:::ui
                Board["BattleshipBoard\nsrc/components/Battleship/BattleshipBoard.tsx"]:::ui
                Headers["PlayerHeaders\nsrc/components/Battleship/PlayerHeaders.tsx"]:::ui
                Messages["Messages\nsrc/components/Battleship/Messages.tsx"]:::ui
            end
        end

        subgraph "Game Logic Utils"
            AutoPlace["Auto-place Algorithm\nsrc/components/Battleship/utils/auto-place/auto-place.ts"]:::logic
            PlaceShip["Place-ship Logic\nsrc/components/Battleship/utils/place-ship/place-ship.ts"]:::logic
            StartingBoard["Starting-board\nsrc/components/Battleship/utils/starting-board/starting-board.ts"]:::logic
            RotationHandler["Rotation-handler Hook\nsrc/components/Battleship/utils/use-rotation-handler/use-rotation-handler.ts"]:::logic
            GameStateHook["Game-state Hook\nsrc/components/Battleship/utils/use-game-state/use-game-state.tsx"]:::logic
            UtilsIndex["Utils Barrel\nsrc/components/Battleship/utils/index.ts"]:::logic
            ComponentsIndex["Components Barrel\nsrc/components/index.ts"]:::logic
            PagesIndex["Pages Barrel\nsrc/pages/index.ts"]:::logic
        end
    end

    %% Build & CI Pipeline
    subgraph "Build & Test Pipeline"
        Vite["Vite Config\nvite.config.ts"]:::infra
        TSConfig["TypeScript Configs\n(tsconfig.json, tsconfig.app.json, tsconfig.node.json)"]:::infra
        Vitest["Vitest Setup\nvitest.config.ts"]:::infra
        TestUtils["test-utils/"]:::infra
        CI["GitHub Actions\n.github/workflows/run-checks.yml"]:::infra
    end

    %% Data and Control Flow
    User -->|interacts| Browser
    Browser -->|loads| indexHtml
    Browser -->|serves| main
    main -->|initializes| Router
    main -->|provides| GlobalContext
    Router -->|routes to| Home
    Router -->|routes to| BattleshipPage
    GlobalContext -->|provides state| Home
    GlobalContext -->|provides state| BattleshipPage
    Home -->|renders| Welcome
    Home -->|renders| ToDos
    BattleshipPage -->|renders| BattleshipWrapper
    BattleshipWrapper -->|uses| Board
    BattleshipWrapper -->|uses| Headers
    BattleshipWrapper -->|uses| Messages
    BattleshipWrapper -->|dispatches| GameStateHook
    GameStateHook -->|calls| AutoPlace
    GameStateHook -->|calls| PlaceShip
    GameStateHook -->|calls| StartingBoard
    GameStateHook -->|uses| RotationHandler
    GameStateHook -->|exports via| UtilsIndex
    Welcome -->|exported by| ComponentsIndex
    ToDos -->|exported by| ComponentsIndex
    Home -->|exported by| PagesIndex
    BattleshipPage -->|exported by| PagesIndex

    %% Build & CI Flow
    Vite -->|bundles| main
    TSConfig -->|type-checks| main
    Vitest -->|tests| GameStateHook
    Vitest -->|tests| AutoPlace
    Vitest -->|tests| PlaceShip
    CI -->|runs on push| Vitest
    CI -->|runs on push| TSConfig
    CI -->|runs on push| Vite
    main -->|outputs| publicDir
    publicDir -->|deployed to| Netlify
    Netlify -->|serves| Browser

    %% Click Events
    click main "https://github.com/barbacoa08/andesite-battleship/blob/main/src/main.tsx"
    click Router "https://github.com/barbacoa08/andesite-battleship/blob/main/src/Router.tsx"
    click GlobalContext "https://github.com/barbacoa08/andesite-battleship/blob/main/src/GlobalContext.tsx"
    click Home "https://github.com/barbacoa08/andesite-battleship/blob/main/src/pages/Home.page.tsx"
    click BattleshipPage "https://github.com/barbacoa08/andesite-battleship/blob/main/src/pages/Battleship.page.tsx"
    click Welcome "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Welcome/Welcome.tsx"
    click ToDos "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/ToDos.tsx"
    click BattleshipWrapper "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Battleship/Battleship.tsx"
    click Board "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Battleship/BattleshipBoard.tsx"
    click Headers "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Battleship/PlayerHeaders.tsx"
    click Messages "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Battleship/Messages.tsx"
    click AutoPlace "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Battleship/utils/auto-place/auto-place.ts"
    click PlaceShip "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Battleship/utils/place-ship/place-ship.ts"
    click StartingBoard "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Battleship/utils/starting-board/starting-board.ts"
    click RotationHandler "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Battleship/utils/use-rotation-handler/use-rotation-handler.ts"
    click GameStateHook "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Battleship/utils/use-game-state/use-game-state.tsx"
    click UtilsIndex "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/Battleship/utils/index.ts"
    click ComponentsIndex "https://github.com/barbacoa08/andesite-battleship/blob/main/src/components/index.ts"
    click PagesIndex "https://github.com/barbacoa08/andesite-battleship/blob/main/src/pages/index.ts"

    %% Styles
    classDef user fill:#FFD700,stroke:#333,stroke-width:1px
    classDef infra fill:#DDDDDD,stroke:#333,stroke-width:1px
    classDef app fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef state fill:#FFD700,stroke:#333,stroke-width:1px
    classDef pages fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef ui fill:#B0E0E6,stroke:#333,stroke-width:1px
    classDef logic fill:#98FB98,stroke:#333,stroke-width:1px
```
