# mattcg/language-subtag-registry architecture

> Architecture diagram of the GitHub repository mattcg/language-subtag-registry, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mattcg/language-subtag-registry
- Repository: https://github.com/mattcg/language-subtag-registry

## Overview

The project is a data conversion and packaging tool that takes IANA’s official language subtag registry (in the record-jar format) and converts it into a set of neatly organized JSON files. These JSON files, stored in the data/ folder, make lookups fast by providing both a flat registry (registry.json) and various keyed indices (e.g., language.json, macrolanguage.json) along with indexing metadata (meta.json). There’s also an importer script to update the JSON files from the latest official version.

##### Main Components
- Data Ingestion / Importer: Represented by scripts/importer.js which triggers the conversion from the official IANA record (the input source) into JSON.
- JSON Data Store: The data/ folder containing organized JSON files (e.g., registry.json, meta.json, language.json, macrolanguage.json, etc.) which hold the processed data.
- Metadata and Index Files: Highlight the presence of meta.json and various specialized JSON files organized by “scope” and “type” (such as language.json, extlang.json, script.json, etc.).
- Configuration and Build Tools: Include package.json (npm scripts and dependency management), .travis.yml (CI integration), eslint.config.js (code quality/linting), and datapackage.json (package information).
- External Dependencies: Although not directly coded here, note that the updater script relies on downloading or converting data from the official IANA source.

##### Relationships and Data Flow
- The process starts from an external source (IANA’s record-jar registry) which is fetched/updated by running the importer (via “npm run import”).
- The importer script processes the incoming data and converts it into a well-structured JSON format.
- After conversion, the updated JSON files are stored in the data/ directory. These files are organized by record type or scope to allow fast lookups.
- The configuration files (package.json, .travis.yml, and eslint.config.js) ensure that the project can be built, maintained, and integrated with CI systems effectively.
- The README also connects this project to another repository (language-tags) that provides a JavaScript API for using these JSON files, so external usage or integration is indicated.

##### Important Architectural Patterns or Design Principles
- Separation of Concerns: The importer script is solely responsible for data transformation, while the data/ folder acts as a persistent store of the processed data.
- Modularity: Each JSON file is created by a defined criterion (type or scope), which makes the system extensible and the data lookups efficient.
- Automation and CI: With npm scripts and configuration files like .travis.yml, the system is designed to automate updates and enforce code quality.
- Simplicity in Data Lookup: The usage of flat arrays and keyed JSON objects for indexes suggests a design focused on fast and efficient data access.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["IANA Record-Jar (External Source)"]:::external
    B["Importer Module\n(scripts/importer.js)"]:::importer
    C["JSON Data Store\n(data/json/)"]:::database
    subgraph "Configuration & Build Tools"
        D1["package.json"]:::config
        D2[".travis.yml"]:::config
        D3["eslint.config.js"]:::config
        D4["datapackage.json"]:::config
    end
    E["Language Tags API"]:::external

    A -->|"npm_run_import"| B
    D1 -->|"CI/CD"| B
    D2 -->|"CI/CD"| B
    D3 -->|"CI/CD"| B
    D4 -->|"CI/CD"| B
    B -->|"store_processed_JSON"| C
    C -->|"fast_lookups"| E

    click B "https://github.com/mattcg/language-subtag-registry/blob/master/scripts/importer.js"
    click C "https://github.com/mattcg/language-subtag-registry/tree/master/data/json/"
    click D1 "https://github.com/mattcg/language-subtag-registry/blob/master/package.json"
    click D2 "https://github.com/mattcg/language-subtag-registry/blob/master/.travis.yml"
    click D3 "https://github.com/mattcg/language-subtag-registry/blob/master/eslint.config.js"
    click D4 "https://github.com/mattcg/language-subtag-registry/blob/master/datapackage.json"

    classDef external fill:#FFD700,stroke:#333,stroke-width:2px,color:#000;
    classDef importer fill:#ADD8E6,stroke:#333,stroke-width:2px,color:#000;
    classDef database fill:#98FB98,stroke:#333,stroke-width:2px,color:#000;
    classDef config fill:#FFB6C1,stroke:#333,stroke-width:2px,color:#000;
```
