How hanshuebner/html-scrabble works
Project Type and Purpose
• This is a full-stack, real-time web application.
• Frontend: static HTML/JavaScript/CSS assets under the client/ folder implement the board UI, drag-and-drop, chat, audio cues, and game‐list pages.
• Backend: a Node.js server (server.js) provides HTTP endpoints, serves the static client files, manages game state, and handles real-time communication (likely via WebSockets or long polling).
• Persistence: in-memory game data flushed to disk via a simple “dirty” JSON log (see db.js), option to swap in Redis (redis.js).
• External integrations: SMTP (via nodemailer) for invitation emails, optional basic HTTP auth for the game list.
File Structure
• Top-level:
– server.js: entry point for the Node.js server
– package.json/package-lock.json: dependencies (express, nodemailer, dirty, maybe socket.io, etc.)
– config-default.json: default server settings (port, baseUrl, mailTransportConfig, gameListLogin).
– db.js & redis.js: persistence layers.
– icebox.js & icebox-test.js: custom lightweight test runner.
– run.sh, run-tests.sh, makefile: scripts for starting the server and running tests.
• client/:
– HTML pages (game.html, games.html, make-game.html)
– CSS (common.css, game.css, etc.)
– JavaScript libraries: MochiKit, jQuery, Underscore
– App logic: game.js, games.js, make-game.js, ui.js, scrabble.js, etc.
– Audio assets, images.
• No heavy build process, assets are served as-is.
Extract Architectural Patterns and Major Components
• Client-Server separation:
– Browser (UI)
– Node.js HTTP/WebSocket server
• Real-time messaging: bidirectional channel for moves and chat.
• Stateless vs. Stateful layers:
– Server holds game state in memory + logs to disk
– Persistence adapter (dirty JSON or Redis) behind a thin interface.
• External Services:
– SMTP for emails
– Optional HTTP Basic Auth protecting game list.
a. Main Components:
– Browser Client
· UI Layer: HTML/CSS/JS assets
· Game Engine: Scrabble board logic (drag/drop, tile placement, turn management)
· Chat and Notification handler
– Network Layer: HTTP (GET static, POST invites, game-list auth) + Real-time channel (WebSocket or long-polling)
– Node.js Server
· Router/HTTP server (Express or built-in)
· WebSocket/message broker (socket.io or custom)
· Game Logic module (move validation, turn rotation, scoring)
· Persistence Adapter (db.js for dirty JSON, redis.js if enabled)
· Email module (nodemailer)
– Storage
· In-memory objects
· Disk-backed JSON log (data.db)
· (Optional) Redis server
– External SMTP server
b. Relationships & Interactions:
1. Client loads HTML/CSS/JS over HTTP from Server.
2. Upon game creation/join, Client ↔ Server exchange via HTTP or WebSockets:
– “Create Game” request → Server stores new game state → Server responds with game key.
– “Make Move” or “Chat Message” → Server validates / broadcasts to all participants via real-time channel.
3. Server persists game events immediately to data.db (dirty JSON) and/or Redis.
4. Invitation flow: Server uses nodemailer → SMTP → recipient email client.
5. Optional: HTTP Basic Auth for game list URLs.
c. Architectural Patterns & Principles:
– Single server process handling both HTTP static assets and real-time messaging.
– Adapter pattern for persistence (swappable db.js or redis.js).
– Event-driven model: client actions emit events, server broadcasts events back.
– “Zero-effort deployment”: no heavyweight database server required by default.
d. Key Technologies & Libraries:
– Backend: Node.js, nodemailer, dirty (node-dirty), possibly socket.io
– Frontend: jQuery, MochiKit, Underscore, custom scrabble.js, CSS3 drag/drop
– Persistence: node-dirty JSON log, Redis (optional)
– Testing: custom Icebox test runner
Elements
• Asset delivery (HTTP GET)
• Game-move & chat messages (WebSocket)
• Persistence writes (DB adapter → JSON log/Redis)
• Email dispatch (Server → SMTP)
• Frontend components (blue)
• Backend modules (green)