# buttaiwan/writemyfont architecture

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

- Interactive diagram: https://gitdiagram.com/buttaiwan/writemyfont
- Repository: https://github.com/buttaiwan/writemyfont

## Overview

##### Project type and purpose
- This is a single-page, client-side font-drawing tool (“FontDrawer”) built with HTML5 Canvas and JavaScript.
- It supports Traditional Chinese and Japanese interfaces and persists in-progress work in IndexedDB.

##### File structure
- Top level:
- pages/ — static assets (HTML, CSS, JS) served to the browser.
- brushes/ — (presumably custom drawing brushes or presets).
- glist/ — offline tools/scripts and data for generating character lists (Ruby and JavaScript scripts plus text tables).
- .github/, .prettierignore, ChangeLog.md, LICENSE, README.md.
- Static pages:
- index.html, ja.html — UI shells for different languages.
- style.css — shared styling.
- fontdrawer.js (in pages/) — core drawing and font-gen logic.
- potrace.js, pressure-drawing.js, cglyphlist.js, jglyphlist.js — supporting scripts loaded by pages.
- No server-side code — fully client-side with build/deploy via static hosting.

##### README for additional insights
- Architecture is implicit:
- Canvas drawing component
- IndexedDB persistence
- Vectorization pipeline (raster → SVG via potrace.js)
- Font packaging pipeline (SVG → glyph outlines → OTF via opentype.js)
- Offline glist/ folder is a generator for character list inputs.

##### Elements
- User input → Canvas → IndexedDB
- Canvas output → potrace.js → SVG paths → opentype.js → Font blob → Download
- Offline data files → glist scripts → output JS → served to UI
- UI components (light blue)
- Data-transformation pipeline (orange)
- Persistence/storage (green)
- Offline tooling (grey)

##### Detailed capture of essential elements
- External libraries (potrace.js, opentype.js) as labeled modules.
- If desired, annotate protocols/APIs (e.g., Canvas API, IndexedDB API, Blob API).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client-side Browser Components
    subgraph "Client-side (Browser)"
        direction TB
        User["User"]:::external
        subgraph "UI Layer"
            direction TB
            UI_index["index.html"]:::ui
            UI_ja["ja.html"]:::ui
            Style["style.css"]:::ui
            CGlyph["cglyphlist.js"]:::ui
            JGlyph["jglyphlist.js"]:::ui
        end
        Canvas_module["Canvas Drawing & Pressure Simulation"]:::pipeline
        Persistence_db[(IndexedDB)]:::storage
        Vectorization["Vectorization Module\n(potrace.js)"]:::pipeline
        FontGen["Font Generation Module\n(opentype.js)"]:::pipeline
        Export["Download/Export Module\n(Blob API)"]:::pipeline
    end

    %% Offline Tools
    subgraph "Offline Tools"
        direction TB
        Text["*.txt"]:::offline
        MakeC["make_glist_c.rb"]:::offline
        MakeJ["make_glist_j.rb"]:::offline
    end

    %% Data Flow
    User -->|"interacts with"| UI_index
    User --> UI_ja
    UI_index -->|"loads scripts"| Canvas_module
    UI_index --> CGlyph
    UI_index --> JGlyph
    UI_ja --> Canvas_module
    UI_ja --> CGlyph
    UI_ja --> JGlyph

    Canvas_module -->|"save strokes"| Persistence_db
    Canvas_module -->|"raster image"| Vectorization
    Vectorization -->|"SVG paths"| FontGen
    FontGen -->|"OTF blob"| Export
    Export -->|"file save"| User

    Text --> MakeC
    Text --> MakeJ
    MakeC --> CGlyph
    MakeJ --> JGlyph

    %% Click Events
    click UI_index "https://github.com/buttaiwan/writemyfont/blob/main/pages/index.html"
    click UI_ja "https://github.com/buttaiwan/writemyfont/blob/main/pages/ja.html"
    click Style "https://github.com/buttaiwan/writemyfont/blob/main/pages/style.css"
    click Canvas_module "https://github.com/buttaiwan/writemyfont/blob/main/pages/fontdrawer.js"
    click Canvas_module "https://github.com/buttaiwan/writemyfont/blob/main/pages/pressure-drawing.js"
    click Persistence_db "https://github.com/buttaiwan/writemyfont/blob/main/pages/fontdrawer.js"
    click Vectorization "https://github.com/buttaiwan/writemyfont/blob/main/pages/potrace.js"
    click FontGen "https://github.com/buttaiwan/writemyfont/blob/main/pages/fontdrawer.js"
    click Export "https://github.com/buttaiwan/writemyfont/blob/main/pages/fontdrawer.js"
    click MakeC "https://github.com/buttaiwan/writemyfont/blob/main/glist/make_glist_c.rb"
    click MakeJ "https://github.com/buttaiwan/writemyfont/blob/main/glist/make_glist_j.rb"
    click Text "https://github.com/buttaiwan/writemyfont/blob/main/glist/*.txt"
    click CGlyph "https://github.com/buttaiwan/writemyfont/blob/main/pages/cglyphlist.js"
    click JGlyph "https://github.com/buttaiwan/writemyfont/blob/main/pages/jglyphlist.js"

    %% Styles
    classDef ui fill:#D6EAF8,stroke:#3498DB;
    classDef pipeline fill:#F9E79F,stroke:#F39C12;
    classDef storage fill:#ABEBC6,stroke:#28B463;
    classDef offline fill:#D5D8DC,stroke:#7F8C8D;
    classDef external fill:#FFFFFF,stroke:#000000,stroke-dasharray: 2 2;
```
