How thanamn/subdivision-quiz works
Purpose and Runtime
This is a Vite-built React/TypeScript single-page geography quiz for identifying world administrative subdivisions on an interactive map. The browser is the primary runtime; static assets and generated geographic datasets are served from public/data/. Application startup is index.html → src/main.tsx → src/app/App.tsx.
Application Composition
src/app/App.tsx is the orchestration layer: it loads subdivision data, owns app-level scope/mode/progress state, and composes the map, quiz controls, side panel, tutorial, and notices. src/app/dataUrls.ts centralizes public dataset locations, while src/app/storage.ts handles browser-persisted UI/application state.
Key UI boundaries are:
• Map interaction: src/map/QuizMap.tsx, src/map/MapShapes.tsx, src/map/MapControls.tsx
• Navigation, scope, and status UI: src/components/TopBar.tsx, src/components/ScopePicker.tsx, src/components/SidePanel.tsx
• Progress/result presentation: src/components/ProgressStats.tsx, src/components/CompletedList.tsx, src/components/MissingList.tsx
Geographic Data Pipeline
The shipped map topology is public/data/admin1.topo.json; region metadata and country relationships are in public/data/country-regions.json. Runtime loaders in src/data/loadSubdivisionData.ts and src/geo/topology.ts convert these static files into application domain features.
Build scripts generate and audit these assets:
• scripts/build-data.mjs produces/updates geographic data.
• scripts/build-subdivision-media.mjs produces public/data/subdivision-media.json.
• scripts/audit-short-latin-matches.mjs validates naming/matching quality.
public/data/freshness-audit.md and public/data/README.md document dataset maintenance expectations.
Geo Domain and Name Resolution
src/domain/types.ts defines core subdivision/domain shapes. Geographic normalization and lookup are separated from rendering: src/geo/normalization.ts, src/geo/nameIndex.ts, and src/geo/aliases.ts turn user-entered or displayed names into canonical subdivision matches.
Country colors and selectable geographic scopes are defined in src/geo/countryColors.ts and src/geo/scope.ts. Explicit source-data corrections and display policies live in src/geo/overrides/displayNames.ts and src/geo/overrides/vietnam2025.ts, preserving a boundary between raw topology and quiz-facing names.
Quiz Engines
Two quiz modes share common contracts in src/quiz/quizTypes.ts:
• Find mode selects a target and expects map interaction. Its state machine and action UI are in src/quiz/find/useFindQuiz.ts, src/quiz/find/FindActions.tsx, and src/quiz/find/FindPrompt.tsx.
• Type mode accepts textual guesses, resolves normalized/ambiguous matches, and updates quiz state. Its core is src/quiz/type/useTypeQuiz.ts, with input and disambiguation in src/quiz/type/TypeGuessForm.tsx and src/quiz/type/AmbiguousMatches.tsx.
Quiz completion, misses, wrong clicks, and recent answers feed shared panel components. Timing and durable progress are isolated in src/quiz/useQuizTimer.ts and src/quiz/progressStorage.ts, using browser storage rather than a backend.
Map Rendering Boundary
src/map/mapGeometry.ts transforms loaded topology/domain features into renderable geometry; src/map/mapTypes.ts defines map-facing contracts. src/map/QuizMap.tsx binds quiz state to SVG/map events, src/map/MapShapes.tsx renders and styles regions, and src/map/MapTooltip.tsx presents hover context. This boundary keeps geometry and pointer behavior separate from name matching and quiz progression.
Media, Deployment, and External Dependencies
Optional subdivision imagery/media metadata is loaded through src/data/loadSubdivisionMedia.ts, modeled in src/domain/subdivisionMedia.ts, and displayed by src/components/SubdivisionMediaPreview.tsx; its static source is public/data/subdivision-media.json.
There is no indicated application server or database. Deployment is automated by .github/workflows/deploy.yml, consistent with static Vite hosting. External inputs are the prebuilt topology, region metadata, and subdivision media files under public/data/.
Main entry points: App.tsx App orchestration · loadSubdivisionData.ts Subdivision loader · types.ts Subdivision domain · QuizMap.tsx Interactive map
Components 23
Browser App
- Vite entry
index.html - React bootstrap
src/main.tsx - App orchestration · Owns scope, mode, progress, and composition.
src/app/App.tsx - Browser state
src/app/storage.ts - Navigation and panels · Top bar, scope picker, side panel, and result lists.
src/components/SidePanel.tsx - Interactive map · Binds quiz state to map events and rendering.
src/map/QuizMap.tsx - Map geometry
src/map/mapGeometry.ts
Quiz Engines
- Find mode
src/quiz/find/useFindQuiz.ts - Type mode · Resolves textual and ambiguous guesses.
src/quiz/type/useTypeQuiz.ts - Quiz contracts and progress · Shared mode contracts, timer, and durable progress.
src/quiz/quizTypes.ts
Geographic Domain
- Subdivision domain
src/domain/types.ts - Name resolution · Normalizes names, aliases, and ambiguities.
src/geo/nameIndex.ts - Scope and display policy · Selectable scopes, colors, and source-data corrections.
src/geo/scope.ts
Data Pipeline
- Subdivision loader · Converts public topology and region metadata into features.
src/data/loadSubdivisionData.ts - Topology conversion
src/geo/topology.ts - Admin topology
public/data/admin1.topo.json - Country regions
public/data/country-regions.json - Subdivision media · Loads metadata for map-adjacent previews.
src/data/loadSubdivisionMedia.ts - Media metadata
public/data/subdivision-media.json - Geodata build · Generates and updates shipped geographic data.
scripts/build-data.mjs - Media build
scripts/build-subdivision-media.mjs - Name-match audit
scripts/audit-short-latin-matches.mjs
Other components
- Static deployment
.github/workflows/deploy.yml
Connections 28
- Vite entry → React bootstrap: loads
- React bootstrap → App orchestration: mounts
- App orchestration → Browser state: persists UI state
- App orchestration → Navigation and panels: composes
- App orchestration → Interactive map: composes
- App orchestration → Find mode: runs find mode
- App orchestration → Type mode: runs type mode
- App orchestration → Subdivision loader: loads subdivisions
- App orchestration → Subdivision media: loads optional media
- Find mode → Quiz contracts and progress: uses
- Type mode → Quiz contracts and progress: uses
- Type mode → Name resolution: resolves guesses
- Quiz contracts and progress → Browser state: stores progress
- Interactive map → Map geometry: renders
- Interactive map → Scope and display policy: applies scope and colors
- Map geometry → Subdivision domain: maps features
- Subdivision loader → Topology conversion: converts through
- Topology conversion → Admin topology: reads
- Subdivision loader → Country regions: reads
- Subdivision loader → Subdivision domain: produces
- Name resolution → Subdivision domain: matches
- Scope and display policy → Subdivision domain: filters
- Subdivision media → Media metadata: reads
- Geodata build → Admin topology: generates
- Geodata build → Country regions: updates
- Media build → Media metadata: generates
- Name-match audit → Admin topology: audits names
- Static deployment → Vite entry: publishes static app