# sjvasquez/handwriting-synthesis architecture

> Architecture diagram of the GitHub repository sjvasquez/handwriting-synthesis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sjvasquez/handwriting-synthesis
- Repository: https://github.com/sjvasquez/handwriting-synthesis

## Overview

This is a research implementation of Graves-style handwriting synthesis. The main user flow supplies text plus optional style exemplars and bias to `Hand.write`, which samples stroke sequences with the pretrained recurrent model and writes SVG. A separate data-preparation and training path supports retraining. The graph preserves the documented style/priming and bias capabilities; edges are limited to README statements and visible source-index references, so unsampled internals are not inferred.

Main entry points: [`demo.py`](https://github.com/sjvasquez/handwriting-synthesis/blob/master/demo.py) (Hand API), [`rnn.py`](https://github.com/sjvasquez/handwriting-synthesis/blob/master/rnn.py) (Recurrent model), [`prepare_data.py`](https://github.com/sjvasquez/handwriting-synthesis/blob/master/prepare_data.py) (Corpus preparation), [`tf_base_model.py`](https://github.com/sjvasquez/handwriting-synthesis/blob/master/tf_base_model.py) (Training runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Generation interface"]
  node_hand["Hand API<br/>[demo.py]"]
  node_lyrics["Demo lyrics<br/>[lyrics.py]"]
  node_styles["Style exemplars"]
  node_sampler["Stroke sampler<br/>[rnn.py]"]
  node_svg["SVG output<br/>[demo.py]"]
end

subgraph group_data["Data and rendering"]
  node_preparation["Corpus preparation<br/>[prepare_data.py]"]
  node_corpus["Raw handwriting data"]
  node_arrays["Prepared arrays"]
  node_drawing["Stroke drawing utilities<br/>[drawing.py]"]
  node_batches["Batch data frame<br/>[data_frame.py]"]
end

subgraph group_model["Synthesis model"]
  node_model["Recurrent model<br/>[rnn.py]"]
  node_attention["Attention LSTM cell<br/>[rnn_cell.py]"]
  node_sequence_ops["Sequence operations<br/>[rnn_ops.py]"]
  node_tensor_utils["Tensor utilities<br/>[tf_utils.py]"]
end

subgraph group_training["Training runtime"]
  node_trainer["Training runtime<br/>[tf_base_model.py]"]
  node_checkpoint[("Pretrained checkpoint")]
end

node_user(("Text user"))

node_user -->|"provides text"| node_hand
node_hand -->|"requests samples"| node_sampler
node_hand -->|"writes SVG"| node_svg
node_hand -->|"loads exemplars"| node_styles
node_hand -->|"uses drawing"| node_drawing
node_hand -->|"uses demo text"| node_lyrics
node_preparation -->|"reads corpus"| node_corpus
node_preparation -->|"encodes strokes"| node_drawing
node_preparation -->|"saves arrays"| node_arrays
node_sampler -->|"runs model"| node_model
node_model -->|"uses batches"| node_batches
node_model -->|"uses cell"| node_attention
node_model -->|"uses sequence ops"| node_sequence_ops
node_model -->|"uses tensor ops"| node_tensor_utils
node_model -->|"inherits trainer"| node_trainer
node_trainer -->|"restores model"| node_checkpoint

click node_hand "https://github.com/sjvasquez/handwriting-synthesis/blob/master/demo.py"
click node_lyrics "https://github.com/sjvasquez/handwriting-synthesis/blob/master/lyrics.py"
click node_styles "https://github.com/sjvasquez/handwriting-synthesis/tree/master/styles"
click node_sampler "https://github.com/sjvasquez/handwriting-synthesis/blob/master/rnn.py"
click node_svg "https://github.com/sjvasquez/handwriting-synthesis/blob/master/demo.py"
click node_preparation "https://github.com/sjvasquez/handwriting-synthesis/blob/master/prepare_data.py"
click node_corpus "https://github.com/sjvasquez/handwriting-synthesis/tree/master/data/raw"
click node_arrays "https://github.com/sjvasquez/handwriting-synthesis/tree/master/data"
click node_drawing "https://github.com/sjvasquez/handwriting-synthesis/blob/master/drawing.py"
click node_batches "https://github.com/sjvasquez/handwriting-synthesis/blob/master/data_frame.py"
click node_model "https://github.com/sjvasquez/handwriting-synthesis/blob/master/rnn.py"
click node_attention "https://github.com/sjvasquez/handwriting-synthesis/blob/master/rnn_cell.py"
click node_sequence_ops "https://github.com/sjvasquez/handwriting-synthesis/blob/master/rnn_ops.py"
click node_tensor_utils "https://github.com/sjvasquez/handwriting-synthesis/blob/master/tf_utils.py"
click node_trainer "https://github.com/sjvasquez/handwriting-synthesis/blob/master/tf_base_model.py"
click node_checkpoint "https://github.com/sjvasquez/handwriting-synthesis/tree/master/checkpoints"

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_hand,node_lyrics,node_styles,node_sampler,node_svg,node_user toneBlue
class node_preparation,node_corpus,node_arrays,node_drawing,node_batches toneAmber
class node_model,node_attention,node_sequence_ops,node_tensor_utils toneMint
class node_trainer,node_checkpoint toneRose
```

## Components

### Generation interface

- [Hand API](https://github.com/sjvasquez/handwriting-synthesis/blob/master/demo.py): `demo.py`
- [Demo lyrics](https://github.com/sjvasquez/handwriting-synthesis/blob/master/lyrics.py): `lyrics.py`
- [Style exemplars](https://github.com/sjvasquez/handwriting-synthesis/tree/master/styles): `styles`
- [Stroke sampler](https://github.com/sjvasquez/handwriting-synthesis/blob/master/rnn.py): `rnn.py`
- [SVG output](https://github.com/sjvasquez/handwriting-synthesis/blob/master/demo.py): `demo.py`

### Data and rendering

- [Corpus preparation](https://github.com/sjvasquez/handwriting-synthesis/blob/master/prepare_data.py): `prepare_data.py`
- [Raw handwriting data](https://github.com/sjvasquez/handwriting-synthesis/tree/master/data/raw): `data/raw`
- [Prepared arrays](https://github.com/sjvasquez/handwriting-synthesis/tree/master/data): `data`
- [Stroke drawing utilities](https://github.com/sjvasquez/handwriting-synthesis/blob/master/drawing.py): `drawing.py`
- [Batch data frame](https://github.com/sjvasquez/handwriting-synthesis/blob/master/data_frame.py): `data_frame.py`

### Synthesis model

- [Recurrent model](https://github.com/sjvasquez/handwriting-synthesis/blob/master/rnn.py): `rnn.py`
- [Attention LSTM cell](https://github.com/sjvasquez/handwriting-synthesis/blob/master/rnn_cell.py): `rnn_cell.py`
- [Sequence operations](https://github.com/sjvasquez/handwriting-synthesis/blob/master/rnn_ops.py): `rnn_ops.py`
- [Tensor utilities](https://github.com/sjvasquez/handwriting-synthesis/blob/master/tf_utils.py): `tf_utils.py`

### Training runtime

- [Training runtime](https://github.com/sjvasquez/handwriting-synthesis/blob/master/tf_base_model.py): `tf_base_model.py`
- [Pretrained checkpoint](https://github.com/sjvasquez/handwriting-synthesis/tree/master/checkpoints): `checkpoints`

### Other components

- **Text user**

## Connections

- Text user → Hand API: provides text (evidence: `readme.md`)
- Hand API → Stroke sampler: requests samples (evidence: `demo.py`)
- Hand API → SVG output: writes SVG (evidence: `readme.md`)
- Hand API → Style exemplars: loads exemplars (evidence: `demo.py`)
- Hand API → Stroke drawing utilities: uses drawing (evidence: `demo.py`)
- Hand API → Demo lyrics: uses demo text (evidence: `demo.py`)
- Corpus preparation → Raw handwriting data: reads corpus (evidence: `prepare_data.py`)
- Corpus preparation → Stroke drawing utilities: encodes strokes (evidence: `prepare_data.py`)
- Corpus preparation → Prepared arrays: saves arrays (evidence: `prepare_data.py`)
- Stroke sampler → Recurrent model: runs model (evidence: `demo.py`)
- Recurrent model → Batch data frame: uses batches (evidence: `rnn.py`)
- Recurrent model → Attention LSTM cell: uses cell (evidence: `rnn.py`)
- Recurrent model → Sequence operations: uses sequence ops (evidence: `rnn.py`)
- Recurrent model → Tensor utilities: uses tensor ops (evidence: `rnn.py`)
- Recurrent model → Training runtime: inherits trainer (evidence: `rnn.py`)
- Training runtime → Pretrained checkpoint: restores model
