# entibo/taipingu architecture

> Architecture diagram of the GitHub repository entibo/taipingu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/entibo/taipingu
- Repository: https://github.com/entibo/taipingu

## Overview

##### Project Type & Purpose
- This is a static single‐page web application (SPA) for a Japanese typing game.
- It ships as static assets (HTML, CSS, JS, JSON, fonts) and runs entirely in the browser.
- A small build pipeline (Makefiles, scripts) generates subsets of fonts and JSON sentence datasets from Tatoeba dumps.

##### High‐Level Components
A. Client (Browser)
- index.html: The shell that loads CSS and JS.
- index.css: Styles for layout, fonts, furigana, etc.
- index.js: Main application logic (UI, settings, game loop).
- romaji.js: Input‐mapping module that converts keyboard events into Japanese syllables.
- sentences/tatoeba/api.js: Client-side “API” module to fetch sentence JSON streams.

B. Static Data Store (Deployed)
- sentences/tatoeba/data: Thousands of JSON files, chunked and indexed by features (language, audio availability, readings).
- fonts (subsetted TTF/WOFF files): Two font styles, generated by fonts/Makefile.

C. External Services
- Tatoeba.org: Hosts audio recordings referenced by URL in sentence metadata.

D. Build & Generation Pipeline (Local Dev)
- sentences/tatoeba/Makefile + scripts/*.mjs:
- Fetch Tatoeba dump, filter Japanese sentences, generate chunked JSON & indices.
- fonts/Makefile: Subset Google Noto/Source Han fonts based on characters used in initial sentences.

##### Relationships & Data Flows
- Browser → Static Web Server: index.html, CSS, JS, fonts, JSON chunks are fetched over HTTP(S).
- index.js & api.js → sentences/tatoeba/data/*.json: fetch() calls return sentence objects.
- index.js → romaji.js: translates keypress events into kana/romaji comparison logic.
- Browser → Tatoeba.org: HTTP GET requests for audio URLs on demand.
- Developer (CLI) → Makefiles / scripts → fonts, sentences data: one‐time or periodic generation before deploy.

##### Architectural Patterns & Principles
- Client‐Side Rendering (CSR): All rendering and game logic runs in the browser.
- Static Site / Jamstack: Prebuilt assets served from a CDN or GitHub Pages.
- Modular JS: Separate modules for UI, input handling, data access.
- Chunked Data Loading: Sentence data is split into manageable JSON files to avoid huge single downloads.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser/Client Layer
    subgraph "Browser/Client"
        direction TB
        HTML["index.html"]:::client
        CSS["index.css"]:::client
        IndexJS["index.js"]:::client
        Romaji["romaji.js"]:::client
        Icons["icons.js"]:::client
        API["sentences/tatoeba/api.js"]:::client
    end

    %% Static Asset Server Layer
    subgraph "Static Asset Server"
        direction TB
        subgraph "Fonts"
            direction TB
            Fonts["/fonts"]:::server
        end
        subgraph "Sentence Data Store"
            direction TB
            DataDir[("/sentences/tatoeba/data/")]:::server
            Chunk0["chunks/0.json"]:::server
            LangIndex["languages.json"]:::server
            ReadingsIndex["readings-by-sentence.json"]:::server
            SentByLang["sentences-by-language/"]:::server
            AudioList["sentences-with-audio.json"]:::server
        end
    end

    %% External Services Layer
    subgraph "External Services"
        direction TB
        Tatoeba(("Tatoeba.org\n(Audio URLs)")):::external
    end

    %% Build Pipeline Layer
    subgraph "Build Pipeline"
        direction TB
        Pipeline["Developer CLI\n(make)"]:::build
        TatoebaMakefile["sentences/tatoeba/Makefile"]:::build
        FontMakefile["fonts/Makefile"]:::build
        Generate["scripts/generate.mjs"]:::build
        Aggregate["scripts/aggregate.mjs"]:::build
        ListChars["scripts/list-unique-characters.mjs"]:::build
        Shared["shared.mjs"]:::build
    end

    %% Connections
    HTML -->|"loads"| CSS
    HTML -->|"loads"| IndexJS
    IndexJS -->|"keypress → parse"| Romaji
    IndexJS -->|"uses icons"| Icons
    IndexJS -->|"fetch JSON"| API
    API -->|"fetch JSON"| DataDir
    API -->|"fetch JSON"| Chunk0
    API -->|"fetch JSON"| LangIndex
    API -->|"fetch JSON"| ReadingsIndex
    API -->|"fetch JSON"| SentByLang
    API -->|"fetch JSON"| AudioList
    IndexJS -->|"play audio"| Tatoeba
    BrowserLoad[("Browser\nHTTP GET")]:::client -->|"HTTP GET .html/.css/.js/.woff/.json"| HTML
    BrowserLoad -->|"HTTP GET assets"| Fonts
    Pipeline -->|"runs"| TatoebaMakefile
    Pipeline -->|"runs"| FontMakefile
    TatoebaMakefile -->|"executes"| Generate
    TatoebaMakefile -->|"executes"| Aggregate
    TatoebaMakefile -->|"executes"| ListChars
    TatoebaMakefile -->|"uses"| Shared

    %% Click Events
    click HTML "https://github.com/entibo/taipingu/blob/main/index.html"
    click CSS "https://github.com/entibo/taipingu/blob/main/index.css"
    click IndexJS "https://github.com/entibo/taipingu/blob/main/index.js"
    click Romaji "https://github.com/entibo/taipingu/blob/main/romaji.js"
    click Icons "https://github.com/entibo/taipingu/blob/main/icons.js"
    click API "https://github.com/entibo/taipingu/blob/main/sentences/tatoeba/api.js"
    click DataDir "https://github.com/entibo/taipingu/tree/main/sentences/tatoeba/data/"
    click Chunk0 "https://github.com/entibo/taipingu/blob/main/sentences/tatoeba/data/chunks/0.json"
    click LangIndex "https://github.com/entibo/taipingu/blob/main/sentences/tatoeba/data/languages.json"
    click ReadingsIndex "https://github.com/entibo/taipingu/blob/main/sentences/tatoeba/data/readings-by-sentence.json"
    click SentByLang "https://github.com/entibo/taipingu/tree/main/sentences/tatoeba/data/sentences-by-language/"
    click AudioList "https://github.com/entibo/taipingu/blob/main/sentences/tatoeba/data/sentences-with-audio.json"
    click FontMakefile "https://github.com/entibo/taipingu/tree/main/fonts/Makefile"
    click TatoebaMakefile "https://github.com/entibo/taipingu/tree/main/sentences/tatoeba/Makefile"
    click Generate "https://github.com/entibo/taipingu/blob/main/sentences/tatoeba/scripts/generate.mjs"
    click Aggregate "https://github.com/entibo/taipingu/blob/main/sentences/tatoeba/scripts/aggregate.mjs"
    click ListChars "https://github.com/entibo/taipingu/blob/main/sentences/tatoeba/scripts/list-unique-characters.mjs"
    click Shared "https://github.com/entibo/taipingu/blob/main/sentences/tatoeba/shared.mjs"

    %% Styles
    classDef client fill:#cce5ff,stroke:#333,stroke-width:1px,rx:5,ry:5
    classDef server fill:#d4edda,stroke:#333,stroke-width:1px
    classDef external fill:#ffe5b4,stroke:#333,stroke-width:1px,rx:5,ry:5
    classDef build fill:#e2e3e5,stroke:#333,stroke-width:1px,rx:5,ry:5
```
