How arcomage/arcomage-hd works
Project type and purpose
• This is a front-end-only, browser-based full-stack "application" (no custom backend) implementing a Progressive Web App (PWA) card game.
• Its purpose is to render a real-time, turn-based card game (ArcoMage HD), support AI opponents, and enable peer-to-peer multiplayer via WebRTC.
File structure
• Top-level “src” contains application code, split into:
• components (UI/React)
• reducers (Redux state slices)
• epics (redux-observable side-effects with RxJS)
• ai (CPU decision logic)
• webrtc (PeerJS wrapper and STUN config)
• i18n (internationalization contexts and locale data)
• utils (hooks, helpers)
• “store.tsx” wires Redux store + middleware (epics).
• “index.tsx” bootstraps React app and registers the PWA service worker (Workbox).
• “assets” and “public” (index.html) feed into the Vite/Bun build.
• “tools/” contains dev scripts for data processing, i18n extraction, asset generation (not run in production).
• Configuration files (tsconfig.json, vite.config.ts, bunfig.toml) set up transpilation/bundling.
README for additional insights
• Tech stack: TypeScript, React, Redux, redux-observable, RxJS, WebRTC (PeerJS), Workbox PWA.
• Multiplayer Mode: P2P via STUN servers + PeerJS signaling, no custom server after handshake.
• Offline support: Service Worker caches assets, data, settings for offline play.
• AI Mode: Local synchronous computation (ai module).
a. Main components to include:
• Browser & User Device
• React UI layer (components)
• Redux Store (state) & Reducers
• Epics (redux-observable/RxJS side-effects)
• AI Engine (ai module)
• Networking Layer (PeerJS client, STUN servers, signaling server)
• PWA Service Worker (Workbox cache) & Cache Storage
• Assets (images, audio, localization)
b. Relationships & interactions:
• User inputs → React events → dispatch Redux actions
• Actions → Reducers update Store → UI re-renders
• Selected actions → Epics intercept → async flows:
– AI Epic: reads state, runs ai.getMaxScore, dispatches move actions
– Multiplayer Epics: send/receive over WebRTC → dispatch remote actions
• On load: Service Worker intercepts fetch requests, serves from Cache or Network
• PeerJS: initial handshake via signaling server → STUN servers → direct P2P channel
c. Architectural patterns & principles:
• Flux pattern (unidirectional data flow)
• Reactive programming (RxJS Observables in Epics)
• Modular separation: UI / State / Side-Effects / Domain logic (AI/Multiplayer)
• PWA pattern: offline first, caching strategies
d. Key technologies & libraries:
• React + CSS Modules / SCSS / Tailwind for UI
• Redux for state management
• redux-observable & RxJS for orchestrating async and side-effects
• PeerJS + WebRTC (STUN + signaling) for P2P networking
• Workbox for service worker and caching
• Vite + Bun for bundling and dev server