How dellalu/sudoku works
Purpose and Entry Points
A dependency-free, mobile-first static Sudoku PWA. Browser startup, DOM rendering, and user-event orchestration live in src/main.js, loaded by index.html. The app is deployable to any static HTTPS host and can run offline after service-worker caching.
Browser UI and Application Control
src/main.js owns the interactive shell: rendering the board/keypad, dispatching player actions, timer/update UI, and coordinating engine and game-state APIs. src/styles.css provides the mobile-first presentation layer. This is a direct browser application rather than a client/server architecture.
Sudoku Engine
Core pure puzzle logic is isolated under src/engine/:
• src/engine/board.js represents and validates Sudoku board structure and constraints.
• src/engine/solver.js solves grids and supports uniqueness/validity checks.
• src/engine/generator.js builds puzzles with guaranteed unique solutions.
• src/engine/difficulty.js grades generated puzzles through logical, human-style solving techniques.
• src/engine/random.js supplies seeded deterministic randomness, enabling repeatable generation.
The engine boundary keeps generation and solving independent of DOM, persistence, and UI concerns.
Game State and Player Operations
src/game/state.js is the stateful gameplay layer between UI and engine. It tracks the generated puzzle, solution, player entries, notes, selected cell, timer-related progress, options, and undo/redo history. It applies moves, removes peer notes after placements, detects completion, and exposes state transitions for UI rendering. Engine validation protects game rules; state logic controls player-facing behavior.
Persistence and Save Transfer
src/game/storage.js persists resumable game data in browser localStorage and handles JSON export/import. Import is a trust boundary: save files are validated for version, size, solution integrity, and consistency between givens and solution before becoming active state. Undo/redo history is intentionally excluded from exported/imported data.
Offline PWA Lifecycle
manifest.webmanifest provides install metadata, while sw.js caches the static application shell for offline startup. The service worker lifecycle also supports an update-available flow surfaced by the browser UI in src/main.js. Secure hosting is required for full service-worker and install behavior outside localhost.
Runtime and Verification
The runtime is standard browser JavaScript/CSS/HTML, with no npm package dependencies. Development uses Python’s built-in HTTP server via package scripts. Engine correctness—including solving, uniqueness, generation, validity, and seeded determinism—is verified in tests/engine.test.js.
Main entry points: solver.js Solver · generator.js Puzzle generator · engine.test.js Engine verification · main.js UI controller
Components 15
Browser UI
- App document · Static browser entry point.
index.html - UI controller · Renders controls and orchestrates player actions.
src/main.js - Mobile styles
src/styles.css
Sudoku Engine
Pure puzzle logic independent of browser state.
- Board constraints · Represents and validates Sudoku grids.
src/engine/board.js - Solver · Solves grids and checks validity or uniqueness.
src/engine/solver.js - Puzzle generator · Creates puzzles with unique solutions.
src/engine/generator.js - Difficulty grader · Rates puzzles using human-style techniques.
src/engine/difficulty.js - Seeded random · Enables repeatable puzzle generation.
src/engine/random.js - Engine verification · Verifies solving, generation, validity, uniqueness, and deterministic seeds.
tests/engine.test.js
Game State & Saves
- Gameplay state · Tracks play progress, options, and undo/redo.
src/game/state.js - Save storage & transfer · Validates imports and persists resumable games.
src/game/storage.js - Browser localStorage
PWA Lifecycle
- Install manifest
manifest.webmanifest - Service worker · Caches the static application shell and manages updates.
sw.js - Static shell cache
Connections 22
- App document → UI controller: loads
- App document → Mobile styles: loads
- UI controller → Gameplay state: applies player actions
- UI controller → Save storage & transfer: save, export, import
- UI controller → Service worker: registers; receives updates
- Gameplay state → Board constraints: validates moves
- Gameplay state → Puzzle generator: starts games
- Gameplay state → Solver: checks solution state
- Save storage & transfer → Browser localStorage: persists resumable data
- Save storage & transfer → Board constraints: validates imported saves
- Save storage & transfer → Solver: checks solution integrity
- Puzzle generator → Solver: guarantees uniqueness
- Puzzle generator → Difficulty grader: grades puzzles
- Puzzle generator → Seeded random: uses seeded randomness
- Solver → Board constraints: uses constraints
- Difficulty grader → Solver: applies logical solving
- Service worker → Static shell cache: caches app shell
- Install manifest → App document: install metadata for
- Engine verification → Board constraints: verifies
- Engine verification → Solver: verifies
- Engine verification → Puzzle generator: verifies
- Engine verification → Seeded random: verifies determinism