An app for learning Chinese characters hanzi.bpev.me
README.md

HanziApp #

Made By Ben

The goal of HanziApp is to be a hanzi-learning supplement for learning Chinese.

We support both Traditional and Simplified Chinese, and Pinyin, Jyutping, and Zhuyin / Bopomofo. We are starting to add some Japanese, also, but that isn't really supported as of yet.

See screenshots

The core srs curriculum is focused on learning hanzi, and not words. We only add vocabulary in order to help solidify the hanzi. Right now, we aim for a useful baseline of Hanzi for conversational Chinese (focusing on HSK-3.0 bands 1-6). This app takes a lot of influence from Tofugu's WaniKani website for learning Japanese Kanji.

We also have side-games that focus on application of hanzi, which are NOT srs based (ala, not for memorization, but more for practice of usage). These are intended to be used when a user wants to practice more, but doesn't have any reviews scheduled. These include tasks such as pronouncing time, math, and introducing vocabulary that we skipped over. These mini-games should unlock when users learn the prerequisite hanzi.

Contributing #

If you want to contribute definitions, hints, or translations, refer to the data readme.

Elm application #

All browser-served files stay in www/, including the Elm source, compiled app.js, JavaScript bridge, and static assets. Build with make build and run locally with make serve.

The Elm application is organized by responsibility:

  • www/Main.elm wires up Browser.application.
  • www/Route.elm owns fragment routing, search-query decoding, and legacy URL canonicalization.
  • www/Ports.elm declares the JavaScript boundary. Port names are part of the contract with www/bridge/ and should remain stable.
  • www/App/Types.elm defines the shared application envelope. Feature messages are nested sum types, and workflow state is grouped into named records rather than flattened into one model. It does not import state or view implementations.
  • www/App/State.elm coordinates navigation, shared data, and cross-feature effects. Its root update delegates to focused feature updates.
  • www/App/View.elm composes the application shell and adapts shared data and callbacks for page views.
  • www/App/Context.elm contains shared, pure helpers for localization and interpreting the current snapshot.
  • www/Pages/ contains route-level screens and their state/data operations. Home.elm corresponds to #!/ and composes the welcome flow, study shortcuts, user summary, and progress dashboard. Settings.elm corresponds to #!/settings and owns its form rendering, events, and reset-confirmation state. Home, Downloads, and About own their page lifecycles. Study owns its rendering, while the app coordinates its resumable session and persistence. Views receive explicit inputs and callbacks rather than the entire application model.
  • www/Components/ contains features composed into pages, not independently routed screens. Progress.elm owns proficiency-list state/loading/rendering within Home; UserSummary.elm is shared by Home and Settings.
  • www/View/ contains small shared rendering helpers such as icons.
  • www/Utils/ contains the existing study, answer, subject, persistence, and localization modules. Keep domain logic here rather than in the application shell.

State and behavior ownership #

Responsibility Owner
Navigation, subjects, snapshots, clock, localization, theme Shared application state
Home composition and dashboard lifecycle Pages.Home
Dashboard selections, proficiency-list cache, HSK/TOCFL/JLPT loading and response assembly Components.Progress, nested under Home
Settings controls, page messages, reset confirmation Pages.Settings; persisted preference effects remain coordinated by the app
Audio download confirmations, busy/progress state, port requests and status decoding Pages.Downloads
License-loading lifecycle and presentation Pages.About
Study grading/scheduling Utils.Study; presentation in Pages.Study
Session restoration, assignment-write acknowledgements, locale changes, level-up coordination Application coordinator
Sync forms/devices, reference drafts, known-assignment selection, custom-set import, game state Named records and nested messages in App.Types, with focused coordinator updates in App.State

Page-owned state is retained inside the application model so it can survive navigation. That does not make the application responsible for its internal behavior. Pass shared snapshots, subjects, and localization as explicit inputs instead of duplicating them in page models. Progress lists load only when the dashboard is entered; license texts load only on About entry. Their caches survive navigation.

Keep one application update loop for coordinated workflows. Nested coordinator updates accept a feature message and the whole application model, returning the usual ( Model, Cmd Msg ); self-contained page updates need only their own model and explicit shared inputs. Callback composition tags page messages for the root loop without Html.map/Cmd.map plumbing. Small record-transform helpers handle nested state updates without adding a lens dependency.

Extract cohesive logic or views when useful; there is no requirement to give every widget an independent update loop or repeat a four-file layout for small features. Use custom Elm types internally (for example, game practice and display choices), converting to strings only at external boundaries.

Run make format to format Elm, make test-elm to check formatting and compile without emitting assets, and make test for those checks plus the regression and data-pipeline tests. The Elm regression checks in test/elm/ run through a small worker compiled in a temporary directory; they require Node.js in addition to Elm and do not add test files to the public bundle.

License #

Not all code or data used to build this project is my own; For dependencies, their individual licenses apply. For links to the license data of all dependencies, please use data/sources/licenses.tsv as a reference. Note that this list only includes direct dependencies, so it may not be inclusive. The VF font is from visual-fonts.com, and their license still applies font. Please purchase their font if you would like to use it.

Some code I have taken from elsewhere and modified. For that code, I have added a @license tag in the modified source. If you search the repository for those files, you will find them. For those, their individual licenses apply.

For all other code and data, the LICENSE applies.

Data #

Source files used to build the app's subject JSON. None of these files are directly included in the app bundle — everything is compiled to www/static/gen/ by the Python scripts in scripts/.

Data files are generally safe to edit by hand (as long as you don't change any ids), but changes to TSVs may be overwritten if the relevant generator command is re-run. See the script docs below for which commands affect which files.

Scripts #

Data tooling is run through make targets from the repository root:

make setup
make build-data
make build-data ARGS="--prod"
make build-data ARGS="--audio"
make build-data ARGS="--prod --audio"

make setup creates .venv/ and installs requirements.txt. Tests, make build-data, and all make data-* targets run setup automatically and reuse that environment; packages are installed again only when requirements change. Use PYTHON=python3.12 to choose the bootstrap interpreter or VENV=/path/to/venv to change its location.

The underlying dispatcher is also available directly (after setup):

.venv/bin/python scripts/data.py <command>
.venv/bin/python scripts/data.py --help

The data pipeline is implemented in Python under scripts/; the former Rust implementation has been removed. Run make test for offline data-pipeline sanity checks. Subject indexes match the retained Rust-derived baseline. Sentence-import and minor dependency-related presentation differences are accepted; see test/README.md for validation results.

Build commands #

Run by code contributors as part of the normal build process.

Command Description
make build-data Build subjects, progress, licenses, and all game assets; skip audio generation
make build-data ARGS="--prod" Build production data assets
make build-data ARGS="--audio" Prompt for locale, dictionary, and limit; generate app audio and zhuyin sprites before building all data

--prod and --audio can be combined. Individual build scripts remain available directly under scripts/ for specialized workflows.

Studio commands #

Run by translation and language data contributors when updating source files. Not needed for normal code development.

Command Description
make data-sort-dicts [ARGS=--lang=zh_CN] Sort TSVs by id (default) or by a target language's curriculum order
make data-update-dicts Add missing readings/meanings entries from dictionary sources
make data-update-sentences Process raw Tatoeba sentence exports into app sentence TSVs (requires opencc)
make data-games-audio-matrix Generate Audacity region CSV files

Directory Layout #

data/
├── other/          # Auxiliary data (licenses.tsv, voices.json)
└── lang/           # All language data
    ├── characters.tsv        # Shared CJK character registry: id, hant, hans
    ├── radicals.tsv          # Shared radical registry: id, hant, hans, alt
    ├── vocabulary.tsv        # Shared CJK vocabulary registry: id, hant, hans
    ├── zh_CN/                # Mainland Chinese target-language data
    │   ├── readings.tsv          # id, pinyin
    │   ├── progress/             # External word lists (HSK, frequency data)
    │   └── order/                # Curriculum order
    │       ├── characters.txt    # One line per level; chars in that level
    │       ├── vocabulary.csv
    │       └── radicals.csv
    ├── zh_HK/                # Cantonese target-language data
    │   └── (same structure as zh_CN/, readings use jyutping)
    ├── zh_TW/                # Taiwanese Mandarin target-language data
    │   └── (same structure as zh_CN/, readings use pinyin + zhuyin)
    ├── ja/                   # Japanese target-language data
    │   ├── reading.characters.tsv   # id, kunyomi, onyomi
    │   ├── reading.vocabulary.tsv   # id, reading (hiragana)
    │   └── (order/, progress/ same structure as zh_CN/)
    ├── en/                   # English user-language data
    │   ├── characters.tsv        # id, hant, value  (meanings)
    │   ├── vocabulary.tsv        # id, hant, value
    │   ├── radicals.tsv          # id, hant, name
    │   ├── hints/                # Mnemonic hints
    │   │   ├── meaning.characters.tsv
    │   │   ├── meaning.vocabulary.tsv
    │   │   ├── reading.characters.tsv
    │   │   └── reading.vocabulary.tsv
    │   ├── meanings/             # Locale-specific meaning overrides
    │   │   ├── ja.characters.tsv
    │   │   └── ja.vocabulary.tsv
    │   └── sentences/            # Example sentences keyed by target locale
    │       ├── zh_CN.tsv
    │       ├── zh_HK.tsv
    │       ├── zh_TW.tsv
    │       └── ja.tsv
    └── es/                   # Spanish user-language data
         └── (same structure as en/)

Curriculum Order #

Order files define which subjects are taught and in what sequence. They live at lang/{targetLang}/order/ and are the source of truth for what gets included in the compiled subject JSON.

  • characters.txt — one line per level, each character is one slug
  • vocabulary.csv — one row per level, comma-separated slugs
  • radicals.csv — one row per level, comma-separated slugs

Subjects not present in any order file are included in the output with hiddenAt set and level: 0 (accessible but not scheduled for review).

We currently do not, but in the future, we should also try and keep frequency in mind, to hopefully gracefully prepare users for things such as graded readers, such as these or these. Some frequency lists:

Rough level targets #

LVL CEFR HSK TOCFL Characters Words
1-10
11-20 A1 HSK 2 TOCFL 1 ~200
21-30 A2 HSK 3 TOCFL 2 ~900 ~1200
31-60 B1-2 HSK 5 TOCFL 4 ~1900 ~5000

Audio #

Audio generation is skipped by default and generated audio is not committed to the repo. Opt in after adding new curriculum items:

make build-data ARGS="--audio"

This prompts for locale (zh_CN, zh_HK, zh_TW, or ja), dictionary (character or vocabulary), and limit (default 0, meaning all missing items). It runs app audio generation followed by zhuyin audio sprite generation, then builds all data assets. Repeat for each locale/dictionary you want to update. The app audio script still asks for confirmation before requesting TTS.

Requires AZURE_SPEECH_KEY and AZURE_SPEECH_REGION in a .env file, and ffmpeg on $PATH. Generated files land in www/static/gen/audio/{locale}/.