# morgan1998/kanji-wizard-data-pipeline architecture

> Architecture diagram of the GitHub repository morgan1998/kanji-wizard-data-pipeline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/morgan1998/kanji-wizard-data-pipeline
- Repository: https://github.com/morgan1998/kanji-wizard-data-pipeline

## Overview

#### Purpose
A Node.js data-processing repository that builds enriched Japanese kanji/vocabulary datasets, likely for TSV export and Anki-style study material. It combines kanji, JMdict-derived vocabulary, JLPT classifications, and vocabulary-frequency data from the cited upstream sources.

#### Entry Points and Operations
- `src/index.js` is the likely CLI/application entry point, with argument handling in `src/utils/cli-parser.js`.
- `src/pipeline.js` coordinates the processing stages.
- `src/build-tsv.js` provides the output-building path.
- `scripts/download-data.js` obtains or refreshes required source datasets before processing.

#### Input Loading Boundary
Source-specific loaders normalize external dataset files into internal records:
- `src/io/loaders/kanji-loader.js`
- `src/io/loaders/vocab-loader.js`
- `src/io/loaders/associated-vocab-jlpt-map-loader.js`
- `src/io/loaders/associated-vocab-frequency-map-loader.js`

This boundary isolates differences among kanji data, dictionary vocabulary, JLPT vocabulary lists, and frequency datasets.

#### Vocabulary Analysis and Association
Vocabulary is tokenized and connected back to kanji:
- `src/processors/tokenizers/vocab-tokenizer.js`
- `src/services/morphology.js`
- `src/processors/enrichers/kanji-associated-vocab-assigner.js`

The morphology service is the linguistic-analysis boundary; tokenization results enable the pipeline to determine which vocabulary entries are associated with each kanji rather than relying only on raw string matching.

#### Enrichment Stages
The pipeline augments associated vocabulary with study-relevant metadata:
- `src/processors/enrichers/associated-vocab-jlpt-assigner.js`
- `src/processors/enrichers/associated-vocab-frequency-assigner.js`
- `types/kanji-entry-schema.ts`

JLPT and frequency maps are applied to vocabulary associated with each kanji. The TypeScript schema defines the intended structure of the final kanji-entry model, even though runtime code is JavaScript.

#### Selection and Output
Filtering constrains generated records before serialization:
- `src/processors/filterers/jlpt-filterer.js`
- `src/processors/filterers/frequency-filterer.js`
- `src/io/writer.js`

Control flow is: acquire source data → load/normalize records and lookup maps → tokenize vocabulary → associate vocabulary to kanji → enrich with JLPT/frequency metadata → filter → build/write TSV output.

#### External Data and Infrastructure
The repository depends on downloadable public datasets rather than a hosted application backend: JLPT kanji data, JMdict-simplified vocabulary, JLPT vocabulary classifications, and JPDB/Yomitan-derived frequency information. Runtime infrastructure is local Node.js execution with filesystem-based input/output; no web server or database is indicated by the tree.

Main entry points: [`scripts/download-data.js`](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/scripts/download-data.js) (Dataset downloader), [`src/pipeline.js`](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/pipeline.js) (Processing pipeline), [`src/io/loaders/kanji-loader.js`](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/loaders/kanji-loader.js) (Kanji loader), [`src/io/loaders/vocab-loader.js`](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/loaders/vocab-loader.js) (Vocabulary loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_acquisition["Data acquisition"]
  node_download["Dataset downloader<br/>Node script<br/>[download-data.js]"]
  node_sources[("Public source datasets<br/>external data")]
end

subgraph group_input["Input normalization"]
  node_kanji_loader["Kanji loader<br/>[kanji-loader.js]"]
  node_vocab_loader["Vocabulary loader<br/>[vocab-loader.js]"]
  node_jlpt_map_loader["JLPT map loader"]
  node_frequency_map_loader["Frequency map loader"]
end

subgraph group_processing["Processing pipeline"]
  node_cli{{"CLI entry point<br/>Node CLI<br/>[index.js]"}}
  node_cli_parser["Argument parser<br/>CLI utility<br/>[cli-parser.js]"]
  node_pipeline["Processing pipeline<br/>orchestrator<br/>[pipeline.js]"]
  node_vocab_tokenizer["Vocabulary tokenizer<br/>[vocab-tokenizer.js]"]
  node_morphology{{"Morphology service<br/>linguistic analysis<br/>[morphology.js]"}}
  node_association["Kanji-vocabulary association<br/>enricher"]
  node_jlpt_enricher["JLPT enrichment<br/>enricher"]
  node_frequency_enricher["Frequency enrichment<br/>enricher"]
  node_kanji_schema["Kanji entry schema<br/>TypeScript schema"]
end

subgraph group_output["Selection and export"]
  node_jlpt_filter["JLPT filter<br/>[jlpt-filterer.js]"]
  node_frequency_filter["Frequency filter"]
  node_tsv_builder["TSV builder<br/>serializer<br/>[build-tsv.js]"]
  node_writer["TSV writer<br/>filesystem output<br/>[writer.js]"]
end

node_sources -.->|"downloaded by"| node_download
node_download -->|"local kanji data"| node_kanji_loader
node_download -->|"local vocabulary data"| node_vocab_loader
node_download -->|"local JLPT lists"| node_jlpt_map_loader
node_download -->|"local frequency data"| node_frequency_map_loader
node_cli -->|"parses options"| node_cli_parser
node_cli -->|"runs"| node_pipeline
node_pipeline -->|"loads kanji"| node_kanji_loader
node_pipeline -->|"loads vocabulary"| node_vocab_loader
node_pipeline -->|"loads JLPT map"| node_jlpt_map_loader
node_pipeline -->|"loads frequency map"| node_frequency_map_loader
node_vocab_loader -->|"vocabulary records"| node_vocab_tokenizer
node_vocab_tokenizer -->|"analyzes tokens"| node_morphology
node_morphology -->|"token analysis"| node_association
node_kanji_loader -->|"kanji records"| node_association
node_association -->|"associated vocabulary"| node_jlpt_enricher
node_jlpt_map_loader -->|"JLPT lookup"| node_jlpt_enricher
node_jlpt_enricher -->|"enriched entries"| node_frequency_enricher
node_frequency_map_loader -->|"frequency lookup"| node_frequency_enricher
node_frequency_enricher -->|"enriched kanji entries"| node_jlpt_filter
node_jlpt_filter -->|"JLPT-selected entries"| node_frequency_filter
node_frequency_filter -->|"selected entries"| node_tsv_builder
node_kanji_schema -.->|"output model"| node_tsv_builder
node_tsv_builder -->|"TSV content"| node_writer

click node_download "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/scripts/download-data.js"
click node_cli "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/index.js"
click node_cli_parser "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/utils/cli-parser.js"
click node_pipeline "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/pipeline.js"
click node_kanji_loader "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/loaders/kanji-loader.js"
click node_vocab_loader "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/loaders/vocab-loader.js"
click node_jlpt_map_loader "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/loaders/associated-vocab-jlpt-map-loader.js"
click node_frequency_map_loader "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/loaders/associated-vocab-frequency-map-loader.js"
click node_vocab_tokenizer "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/tokenizers/vocab-tokenizer.js"
click node_morphology "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/services/morphology.js"
click node_association "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/enrichers/kanji-associated-vocab-assigner.js"
click node_jlpt_enricher "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/enrichers/associated-vocab-jlpt-assigner.js"
click node_frequency_enricher "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/enrichers/associated-vocab-frequency-assigner.js"
click node_kanji_schema "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/types/kanji-entry-schema.ts"
click node_jlpt_filter "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/filterers/jlpt-filterer.js"
click node_frequency_filter "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/filterers/frequency-filterer.js"
click node_tsv_builder "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/build-tsv.js"
click node_writer "https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/writer.js"

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_download,node_sources toneBlue
class node_kanji_loader,node_vocab_loader,node_jlpt_map_loader,node_frequency_map_loader toneAmber
class node_cli,node_cli_parser,node_pipeline,node_vocab_tokenizer,node_morphology,node_association,node_jlpt_enricher,node_frequency_enricher,node_kanji_schema toneMint
class node_jlpt_filter,node_frequency_filter,node_tsv_builder,node_writer toneRose
```

## Components

### Data acquisition

- [Dataset downloader](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/scripts/download-data.js): Node script · Refreshes public source datasets locally. · `scripts/download-data.js`
- **Public source datasets**: external data · Kanji, JMdict vocabulary, JLPT lists, and frequency data.

### Input normalization

- [Kanji loader](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/loaders/kanji-loader.js): loader · `src/io/loaders/kanji-loader.js`
- [Vocabulary loader](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/loaders/vocab-loader.js): loader · Normalizes JMdict-derived vocabulary. · `src/io/loaders/vocab-loader.js`
- [JLPT map loader](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/loaders/associated-vocab-jlpt-map-loader.js): loader · `src/io/loaders/associated-vocab-jlpt-map-loader.js`
- [Frequency map loader](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/loaders/associated-vocab-frequency-map-loader.js): loader · `src/io/loaders/associated-vocab-frequency-map-loader.js`

### Processing pipeline

- [CLI entry point](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/index.js): Node CLI · `src/index.js`
- [Argument parser](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/utils/cli-parser.js): CLI utility · `src/utils/cli-parser.js`
- [Processing pipeline](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/pipeline.js): orchestrator · `src/pipeline.js`
- [Vocabulary tokenizer](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/tokenizers/vocab-tokenizer.js): tokenizer · `src/processors/tokenizers/vocab-tokenizer.js`
- [Morphology service](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/services/morphology.js): linguistic analysis · Provides token analysis used for kanji association. · `src/services/morphology.js`
- [Kanji-vocabulary association](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/enrichers/kanji-associated-vocab-assigner.js): enricher · `src/processors/enrichers/kanji-associated-vocab-assigner.js`
- [JLPT enrichment](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/enrichers/associated-vocab-jlpt-assigner.js): enricher · `src/processors/enrichers/associated-vocab-jlpt-assigner.js`
- [Frequency enrichment](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/enrichers/associated-vocab-frequency-assigner.js): enricher · `src/processors/enrichers/associated-vocab-frequency-assigner.js`
- [Kanji entry schema](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/types/kanji-entry-schema.ts): TypeScript schema · Defines the final enriched kanji-entry model. · `types/kanji-entry-schema.ts`

### Selection and export

- [JLPT filter](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/filterers/jlpt-filterer.js): filter · `src/processors/filterers/jlpt-filterer.js`
- [Frequency filter](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/processors/filterers/frequency-filterer.js): filter · `src/processors/filterers/frequency-filterer.js`
- [TSV builder](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/build-tsv.js): serializer · `src/build-tsv.js`
- [TSV writer](https://github.com/morgan1998/kanji-wizard-data-pipeline/blob/main/src/io/writer.js): filesystem output · Writes generated study-material data to local files. · `src/io/writer.js`

## Connections

- Public source datasets → Dataset downloader: downloaded by
- Dataset downloader → Kanji loader: local kanji data
- Dataset downloader → Vocabulary loader: local vocabulary data
- Dataset downloader → JLPT map loader: local JLPT lists
- Dataset downloader → Frequency map loader: local frequency data
- CLI entry point → Argument parser: parses options
- CLI entry point → Processing pipeline: runs
- Processing pipeline → Kanji loader: loads kanji
- Processing pipeline → Vocabulary loader: loads vocabulary
- Processing pipeline → JLPT map loader: loads JLPT map
- Processing pipeline → Frequency map loader: loads frequency map
- Vocabulary loader → Vocabulary tokenizer: vocabulary records
- Vocabulary tokenizer → Morphology service: analyzes tokens
- Morphology service → Kanji-vocabulary association: token analysis
- Kanji loader → Kanji-vocabulary association: kanji records
- Kanji-vocabulary association → JLPT enrichment: associated vocabulary
- JLPT map loader → JLPT enrichment: JLPT lookup
- JLPT enrichment → Frequency enrichment: enriched entries
- Frequency map loader → Frequency enrichment: frequency lookup
- Frequency enrichment → JLPT filter: enriched kanji entries
- JLPT filter → Frequency filter: JLPT-selected entries
- Frequency filter → TSV builder: selected entries
- Kanji entry schema → TSV builder: output model
- TSV builder → TSV writer: TSV content
