# hiroto-shida/rubikstation architecture

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

- Interactive diagram: https://gitdiagram.com/hiroto-shida/rubikstation
- Repository: https://github.com/hiroto-shida/rubikstation

## Overview

##### Project Type and Purpose
- This is a client‐only, single‐page application (SPA) built with React + TypeScript and Vite.

##### High-Level Architectural Overview
- Static Hosting Layer (e.g. GitHub Pages, Netlify)
- Serves index.html, /public assets, and the built files under docs/
- PWA Infrastructure
- manifest.webmanifest, service worker (sw.js + workbox), registerSW.js for offline support and “install app”
- Browser (Client)
- React Application (built by Vite)
- React Router (pages under src/pages)
- State Management (stores + context provider)
- Components (UI parts, procedures, timer, scramble, model, record & chart)
- Persistence Layer (cookies via src/tools/getBooleanCookies)

##### Main Components and Their Relationships
- Hosting & CDN
→ Service Worker caches assets → Browser
- React App (entry: main.tsx)
→ App.css + index.css
→ TimerStateProvider wraps everything
→ Router switches between pages (Index, Procedure, RubicModel, Help, Release, NotFound)
- Pages
- Index: combines scramble display (src/components/scramble), timer (src/components/timer), and record graph (src/components/record/Chart)
- Procedure: displays step-by-step solution components (src/components/procedure/Step1–Step7, StyledRubicModel, etc.)
- RubicModel: interactive cube model (src/components/rubicModel/*)
- Help & Release: static content pages
- Components communicate via:
- Props and presenters/containers
- Shared hooks (useCubePosition, useRotateCube, useKeyEvent, etc.)
- Global state stores (inspectionStore, modalOpenStore, procedureDrawerOpenStore)

##### Architectural Patterns & Design Principles
- Container–Presenter pattern for all UI components
- Unidirectional data flow with React Context + lightweight stores
- Hook abstraction for cross-cutting concerns (resize, touch, key events)
- PWA caching strategy with Workbox

##### Step-by-Step Creation Process
– Static Hosting (top)
– PWA Layer
– Client App (center)
– Persistence (bottom)
2. Inside Client App, nest:
– Around it, group Pages. Inside each Page, show key child components (Index has Timer, Scramble, Chart).
3. Service Worker to Client App for fetch and cache.

##### Final Touches
- Arrowheads indicate direction of data or control flow.
- Non-obvious interactions (e.g. “useKeyEvent hook listens for spacebar to start the timer”).

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph Static Hosting Layer
    SH["docs/"]:::hosting
  end

  subgraph PWA Layer
    manifest["manifest.webmanifest"]:::pwa
    sw["sw.js"]:::pwa
    regSW["registerSW.js"]:::pwa
    workbox["workbox-5ffe50d4.js"]:::pwa
  end

  subgraph Client Application
    subgraph "App Shell"
      entry["main.tsx"]:::entry
      app["App.tsx"]:::app
      css1["App.css"]:::app
      css2["index.css"]:::app
      timerProv["TimerStateProvider.tsx"]:::provider
      router["Router"]:::runtime
    end

    subgraph Pages
      idx["Index"]:::page
      proc["Procedure"]:::page
      model["RubicModel"]:::page
      help["Help"]:::page
      rel["Release"]:::page
      nf["NotFound"]:::page
    end

    subgraph "Shared Components"
      scr["Scramble"]:::component
      timerC["Timer"]:::component
      record["Record & Chart"]:::component
      procParts["Procedure Steps"]:::component
      rm["RubikModel"]:::component
      layout["Layout & Typography"]:::component
    end

    subgraph "Hooks & Tools"
      hook1["useCubePosition"]:::hook
      hook2["useRotateCube"]:::hook
      hook3["useKeyEvent"]:::hook
      hook4["useResize"]:::hook
      hook5["useTouchEvent"]:::hook
      cookieTool["getBooleanCookies"]:::tool
    end

    subgraph "State Stores"
      store1["inspectionStore"]:::store
      store2["modalOpenStore"]:::store
      store3["procedureDrawerOpenStore"]:::store
    end
  end

  subgraph Persistence
    cookies["Cookies"]:::persistence
  end

  SH -->|serves| manifest
  SH -->|serves| sw
  SH -->|serves| regSW
  SH -->|serves| workbox
  manifest -->|register| sw
  sw -->|caches assets| entry
  entry -->|imports| app
  app -->|imports| router
  app -->|wraps with| timerProv
  router -->|routes to| idx
  router -->|routes to| proc
  router -->|routes to| model
  router -->|routes to| help
  router -->|routes to| rel
  router -->|routes to| nf
  idx -->|uses| scr
  idx -->|uses| timerC
  idx -->|uses| record
  proc -->|uses| procParts
  model -->|uses| rm
  scr -->|uses| hook1
  scr -->|uses| hook4
  timerC -->|uses| hook3
  timerC -->|uses| hook5
  timerC -->|uses| hook2
  record -->|persists| cookieTool
  record -->|reads/writes| cookies
  store1 -->|provides| app
  store2 -->|provides| proc
  store3 -->|provides| proc
  procParts -->|uses| store3
  idx -->|uses| store1
  proc -->|uses| store2

  click SH "https://github.com/hiroto-shida/rubikstation/tree/main/docs/"
  click manifest "https://github.com/hiroto-shida/rubikstation/blob/main/docs/manifest.webmanifest"
  click sw "https://github.com/hiroto-shida/rubikstation/blob/main/docs/sw.js"
  click regSW "https://github.com/hiroto-shida/rubikstation/blob/main/docs/registerSW.js"
  click workbox "https://github.com/hiroto-shida/rubikstation/blob/main/docs/workbox-5ffe50d4.js"
  click entry "https://github.com/hiroto-shida/rubikstation/blob/main/src/main.tsx"
  click app "https://github.com/hiroto-shida/rubikstation/blob/main/src/App.tsx"
  click css1 "https://github.com/hiroto-shida/rubikstation/blob/main/src/App.css"
  click css2 "https://github.com/hiroto-shida/rubikstation/blob/main/src/index.css"
  click timerProv "https://github.com/hiroto-shida/rubikstation/blob/main/src/providers/TimerStateProvider.tsx"
  click idx "https://github.com/hiroto-shida/rubikstation/blob/main/src/pages/Index/container.tsx"
  click proc "https://github.com/hiroto-shida/rubikstation/blob/main/src/pages/Procedure/container.tsx"
  click model "https://github.com/hiroto-shida/rubikstation/blob/main/src/pages/RubicModel/container.tsx"
  click help "https://github.com/hiroto-shida/rubikstation/blob/main/src/pages/Help/container.tsx"
  click rel "https://github.com/hiroto-shida/rubikstation/blob/main/src/pages/Release/container.tsx"
  click nf "https://github.com/hiroto-shida/rubikstation/blob/main/src/pages/NotFound/container.tsx"
  click scr "https://github.com/hiroto-shida/rubikstation/blob/main/src/components/scramble/Scramble/container.tsx"
  click timerC "https://github.com/hiroto-shida/rubikstation/blob/main/src/components/timer/Timer/container.tsx"
  click record "https://github.com/hiroto-shida/rubikstation/blob/main/src/components/record/Chart/container.tsx"
  click procParts "https://github.com/hiroto-shida/rubikstation/blob/main/src/components/procedure/Step1/container.tsx"
  click rm "https://github.com/hiroto-shida/rubikstation/blob/main/src/components/rubicModel/RubicModel/container.tsx"
  click layout "https://github.com/hiroto-shida/rubikstation/blob/main/src/components/layout/Layout/container.tsx"
  click hook1 "https://github.com/hiroto-shida/rubikstation/blob/main/src/hooks/useCubePosition.ts"
  click hook2 "https://github.com/hiroto-shida/rubikstation/blob/main/src/hooks/useRotateCube.ts"
  click hook3 "https://github.com/hiroto-shida/rubikstation/blob/main/src/hooks/useKeyEvent.ts"
  click hook4 "https://github.com/hiroto-shida/rubikstation/blob/main/src/hooks/useResize.ts"
  click hook5 "https://github.com/hiroto-shida/rubikstation/blob/main/src/hooks/useTouchEvent.ts"
  click cookieTool "https://github.com/hiroto-shida/rubikstation/blob/main/src/tools/getBooleanCookies.ts"

  classDef hosting fill:#f0f0f0,stroke:#999
  classDef pwa fill:#ffe4b2,stroke:#d48b00
  classDef entry fill:#e0f7fa,stroke:#0097a7
  classDef app fill:#bbdefb,stroke:#0d47a1
  classDef provider fill:#c8e6c9,stroke:#2e7d32
  classDef runtime fill:#d1c4e9,stroke:#512da8
  classDef page fill:#bbdefb,stroke:#1565c0
  classDef component fill:#b3e5fc,stroke:#0277bd
  classDef hook fill:#dcedc8,stroke:#558b2f
  classDef tool fill:#fff9c4,stroke:#f9a825
  classDef store fill:#c8e6c9,stroke:#2e7d32
  classDef persistence fill:#dcedc8,stroke:#558b2f
```
