# thanamn/subdivision-quiz architecture

> Architecture diagram of the GitHub repository thanamn/subdivision-quiz, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thanamn/subdivision-quiz
- Repository: https://github.com/thanamn/subdivision-quiz

## Overview

#### 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: [`src/app/App.tsx`](https://github.com/thanamn/subdivision-quiz/blob/main/src/app/App.tsx) (App orchestration), [`src/data/loadSubdivisionData.ts`](https://github.com/thanamn/subdivision-quiz/blob/main/src/data/loadSubdivisionData.ts) (Subdivision loader), [`src/domain/types.ts`](https://github.com/thanamn/subdivision-quiz/blob/main/src/domain/types.ts) (Subdivision domain), [`src/map/QuizMap.tsx`](https://github.com/thanamn/subdivision-quiz/blob/main/src/map/QuizMap.tsx) (Interactive map)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Browser App"]
  node_entry["Vite entry<br/>HTML bootstrap<br/>[index.html]"]
  node_main["React bootstrap<br/>entry module<br/>[main.tsx]"]
  node_app["App orchestration<br/>app shell<br/>[App.tsx]"]
  node_storage["Browser state<br/>persistence<br/>[storage.ts]"]
  node_navigation["Navigation and panels<br/>React UI<br/>[SidePanel.tsx]"]
  node_map["Interactive map<br/>SVG interaction<br/>[QuizMap.tsx]"]
  node_map_geometry["Map geometry<br/>geometry adapter<br/>[mapGeometry.ts]"]
end

subgraph group_quiz["Quiz Engines"]
  node_find_quiz["Find mode<br/>quiz state machine<br/>[useFindQuiz.ts]"]
  node_type_quiz["Type mode<br/>quiz state machine<br/>[useTypeQuiz.ts]"]
  node_quiz_contracts["Quiz contracts and progress<br/>shared quiz state<br/>[quizTypes.ts]"]
end

subgraph group_geo["Geographic Domain"]
  node_domain["Subdivision domain<br/>domain models<br/>[types.ts]"]
  node_name_resolution["Name resolution<br/>canonical lookup<br/>[nameIndex.ts]"]
  node_scope_policy["Scope and display policy<br/>geo policy<br/>[scope.ts]"]
end

subgraph group_data["Data Pipeline"]
  node_data_loader["Subdivision loader<br/>runtime loader"]
  node_topology["Topology conversion<br/>geo adapter<br/>[topology.ts]"]
  node_topology_asset[("Admin topology<br/>static dataset<br/>[admin1.topo.json]")]
  node_regions_asset["Country regions<br/>static metadata"]
  node_media["Subdivision media<br/>optional media loader"]
  node_media_asset["Media metadata<br/>static metadata"]
  node_build_data{{"Geodata build<br/>build script<br/>[build-data.mjs]"}}
  node_build_media{{"Media build<br/>build script"}}
  node_audit{{"Name-match audit<br/>validation script"}}
end

node_deploy{{"Static deployment<br/>CI workflow<br/>[deploy.yml]"}}

node_entry -->|"loads"| node_main
node_main -->|"mounts"| node_app
node_app -->|"persists UI state"| node_storage
node_app -->|"composes"| node_navigation
node_app -->|"composes"| node_map
node_app -->|"runs find mode"| node_find_quiz
node_app -->|"runs type mode"| node_type_quiz
node_app -->|"loads subdivisions"| node_data_loader
node_app -.->|"loads optional media"| node_media
node_find_quiz -->|"uses"| node_quiz_contracts
node_type_quiz -->|"uses"| node_quiz_contracts
node_type_quiz -->|"resolves guesses"| node_name_resolution
node_quiz_contracts -->|"stores progress"| node_storage
node_map -->|"renders"| node_map_geometry
node_map -->|"applies scope and colors"| node_scope_policy
node_map_geometry -->|"maps features"| node_domain
node_data_loader -->|"converts through"| node_topology
node_topology -->|"reads"| node_topology_asset
node_data_loader -->|"reads"| node_regions_asset
node_data_loader -->|"produces"| node_domain
node_name_resolution -->|"matches"| node_domain
node_scope_policy -->|"filters"| node_domain
node_media -->|"reads"| node_media_asset
node_build_data -->|"generates"| node_topology_asset
node_build_data -->|"updates"| node_regions_asset
node_build_media -->|"generates"| node_media_asset
node_audit -.->|"audits names"| node_topology_asset
node_deploy -->|"publishes static app"| node_entry

click node_entry "https://github.com/thanamn/subdivision-quiz/blob/main/index.html"
click node_main "https://github.com/thanamn/subdivision-quiz/blob/main/src/main.tsx"
click node_app "https://github.com/thanamn/subdivision-quiz/blob/main/src/app/App.tsx"
click node_storage "https://github.com/thanamn/subdivision-quiz/blob/main/src/app/storage.ts"
click node_navigation "https://github.com/thanamn/subdivision-quiz/blob/main/src/components/SidePanel.tsx"
click node_map "https://github.com/thanamn/subdivision-quiz/blob/main/src/map/QuizMap.tsx"
click node_map_geometry "https://github.com/thanamn/subdivision-quiz/blob/main/src/map/mapGeometry.ts"
click node_find_quiz "https://github.com/thanamn/subdivision-quiz/blob/main/src/quiz/find/useFindQuiz.ts"
click node_type_quiz "https://github.com/thanamn/subdivision-quiz/blob/main/src/quiz/type/useTypeQuiz.ts"
click node_quiz_contracts "https://github.com/thanamn/subdivision-quiz/blob/main/src/quiz/quizTypes.ts"
click node_domain "https://github.com/thanamn/subdivision-quiz/blob/main/src/domain/types.ts"
click node_name_resolution "https://github.com/thanamn/subdivision-quiz/blob/main/src/geo/nameIndex.ts"
click node_scope_policy "https://github.com/thanamn/subdivision-quiz/blob/main/src/geo/scope.ts"
click node_data_loader "https://github.com/thanamn/subdivision-quiz/blob/main/src/data/loadSubdivisionData.ts"
click node_topology "https://github.com/thanamn/subdivision-quiz/blob/main/src/geo/topology.ts"
click node_topology_asset "https://github.com/thanamn/subdivision-quiz/blob/main/public/data/admin1.topo.json"
click node_regions_asset "https://github.com/thanamn/subdivision-quiz/blob/main/public/data/country-regions.json"
click node_media "https://github.com/thanamn/subdivision-quiz/blob/main/src/data/loadSubdivisionMedia.ts"
click node_media_asset "https://github.com/thanamn/subdivision-quiz/blob/main/public/data/subdivision-media.json"
click node_build_data "https://github.com/thanamn/subdivision-quiz/blob/main/scripts/build-data.mjs"
click node_build_media "https://github.com/thanamn/subdivision-quiz/blob/main/scripts/build-subdivision-media.mjs"
click node_audit "https://github.com/thanamn/subdivision-quiz/blob/main/scripts/audit-short-latin-matches.mjs"
click node_deploy "https://github.com/thanamn/subdivision-quiz/blob/main/.github/workflows/deploy.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_main,node_app,node_storage,node_navigation,node_map,node_map_geometry toneBlue
class node_find_quiz,node_type_quiz,node_quiz_contracts toneAmber
class node_domain,node_name_resolution,node_scope_policy toneMint
class node_data_loader,node_topology,node_topology_asset,node_regions_asset,node_media,node_media_asset,node_build_data,node_build_media,node_audit toneRose
class node_deploy toneNeutral
```

## Components

### Browser App

- [Vite entry](https://github.com/thanamn/subdivision-quiz/blob/main/index.html): HTML bootstrap · `index.html`
- [React bootstrap](https://github.com/thanamn/subdivision-quiz/blob/main/src/main.tsx): entry module · `src/main.tsx`
- [App orchestration](https://github.com/thanamn/subdivision-quiz/blob/main/src/app/App.tsx): app shell · Owns scope, mode, progress, and composition. · `src/app/App.tsx`
- [Browser state](https://github.com/thanamn/subdivision-quiz/blob/main/src/app/storage.ts): persistence · `src/app/storage.ts`
- [Navigation and panels](https://github.com/thanamn/subdivision-quiz/blob/main/src/components/SidePanel.tsx): React UI · Top bar, scope picker, side panel, and result lists. · `src/components/SidePanel.tsx`
- [Interactive map](https://github.com/thanamn/subdivision-quiz/blob/main/src/map/QuizMap.tsx): SVG interaction · Binds quiz state to map events and rendering. · `src/map/QuizMap.tsx`
- [Map geometry](https://github.com/thanamn/subdivision-quiz/blob/main/src/map/mapGeometry.ts): geometry adapter · `src/map/mapGeometry.ts`

### Quiz Engines

- [Find mode](https://github.com/thanamn/subdivision-quiz/blob/main/src/quiz/find/useFindQuiz.ts): quiz state machine · `src/quiz/find/useFindQuiz.ts`
- [Type mode](https://github.com/thanamn/subdivision-quiz/blob/main/src/quiz/type/useTypeQuiz.ts): quiz state machine · Resolves textual and ambiguous guesses. · `src/quiz/type/useTypeQuiz.ts`
- [Quiz contracts and progress](https://github.com/thanamn/subdivision-quiz/blob/main/src/quiz/quizTypes.ts): shared quiz state · Shared mode contracts, timer, and durable progress. · `src/quiz/quizTypes.ts`

### Geographic Domain

- [Subdivision domain](https://github.com/thanamn/subdivision-quiz/blob/main/src/domain/types.ts): domain models · `src/domain/types.ts`
- [Name resolution](https://github.com/thanamn/subdivision-quiz/blob/main/src/geo/nameIndex.ts): canonical lookup · Normalizes names, aliases, and ambiguities. · `src/geo/nameIndex.ts`
- [Scope and display policy](https://github.com/thanamn/subdivision-quiz/blob/main/src/geo/scope.ts): geo policy · Selectable scopes, colors, and source-data corrections. · `src/geo/scope.ts`

### Data Pipeline

- [Subdivision loader](https://github.com/thanamn/subdivision-quiz/blob/main/src/data/loadSubdivisionData.ts): runtime loader · Converts public topology and region metadata into features. · `src/data/loadSubdivisionData.ts`
- [Topology conversion](https://github.com/thanamn/subdivision-quiz/blob/main/src/geo/topology.ts): geo adapter · `src/geo/topology.ts`
- [Admin topology](https://github.com/thanamn/subdivision-quiz/blob/main/public/data/admin1.topo.json): static dataset · `public/data/admin1.topo.json`
- [Country regions](https://github.com/thanamn/subdivision-quiz/blob/main/public/data/country-regions.json): static metadata · `public/data/country-regions.json`
- [Subdivision media](https://github.com/thanamn/subdivision-quiz/blob/main/src/data/loadSubdivisionMedia.ts): optional media loader · Loads metadata for map-adjacent previews. · `src/data/loadSubdivisionMedia.ts`
- [Media metadata](https://github.com/thanamn/subdivision-quiz/blob/main/public/data/subdivision-media.json): static metadata · `public/data/subdivision-media.json`
- [Geodata build](https://github.com/thanamn/subdivision-quiz/blob/main/scripts/build-data.mjs): build script · Generates and updates shipped geographic data. · `scripts/build-data.mjs`
- [Media build](https://github.com/thanamn/subdivision-quiz/blob/main/scripts/build-subdivision-media.mjs): build script · `scripts/build-subdivision-media.mjs`
- [Name-match audit](https://github.com/thanamn/subdivision-quiz/blob/main/scripts/audit-short-latin-matches.mjs): validation script · `scripts/audit-short-latin-matches.mjs`

### Other components

- [Static deployment](https://github.com/thanamn/subdivision-quiz/blob/main/.github/workflows/deploy.yml): CI workflow · `.github/workflows/deploy.yml`

## Connections

- 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
