# asubah/minitok-template architecture

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

- Interactive diagram: https://gitdiagram.com/asubah/minitok-template
- Repository: https://github.com/asubah/minitok-template

## Overview

minitok is a course-project tokenizer: users provide a JSON token specification and source text, which the CLI turns into tokens using regex-compiled finite automata and maximal-munch scanning. The README also documents a separate BPE comparison exercise and a scratch-BPE bonus. Source excerpts show CLI dispatch and the automata/regex interfaces; connections between compiler stages are included where the README explicitly describes them. The comparison exercise has no implementation file in the supplied tree.

Main entry points: [`minitok/__main__.py`](https://github.com/asubah/minitok-template/blob/main/minitok/__main__.py) (Tokenize CLI), [`minitok/automata.py`](https://github.com/asubah/minitok-template/blob/main/minitok/automata.py) (Combined token DFA), [`minitok/regex_compiler.py`](https://github.com/asubah/minitok-template/blob/main/minitok/regex_compiler.py) (Thompson compiler), [`minitok/bpe_from_scratch.py`](https://github.com/asubah/minitok-template/blob/main/minitok/bpe_from_scratch.py) (Scratch BPE)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_specification["Token specification"]
  node_spec_loader["Spec loader<br/>[spec.py]"]
end

subgraph group_automata["Automata compilation"]
  node_regex_parser["Regex parser<br/>[regex_compiler.py]"]
  node_regex_compiler["Thompson compiler<br/>[regex_compiler.py]"]
  node_nfa["NFA model<br/>[automata.py]"]
  node_determinizer["Subset construction<br/>[automata.py]"]
  node_token_dfa["Combined token DFA<br/>[automata.py]"]
end

subgraph group_runtime["Tokenization runtime"]
  node_scanner["Maximal-munch scanner<br/>[automata.py]"]
  node_cli["Tokenize CLI<br/>[__main__.py]"]
  node_bpe["Scratch BPE"]
end

subgraph group_llm["LLM comparison"]
  node_tiktoken["tiktoken"]
  node_comparison["Tokenizer comparison"]
end

node_user(("Project user"))

node_user -->|"runs"| node_cli
node_cli -->|"loads spec"| node_spec_loader
node_cli -->|"builds DFA"| node_token_dfa
node_cli -->|"scans text"| node_scanner
node_regex_parser -.->|"parses for"| node_regex_compiler
node_regex_compiler -->|"compiles to"| node_nfa
node_token_dfa -->|"compiles patterns"| node_regex_compiler
node_token_dfa -->|"determinizes"| node_determinizer
node_determinizer -->|"reads NFA"| node_nfa
node_scanner -->|"uses DFA"| node_token_dfa
node_user -->|"trains or encodes"| node_bpe
node_user -->|"compares tokenizers"| node_comparison
node_comparison -->|"uses encoding"| node_tiktoken
node_comparison -->|"compares output"| node_scanner
node_comparison -->|"compares output"| node_bpe

click node_spec_loader "https://github.com/asubah/minitok-template/blob/main/minitok/spec.py"
click node_regex_parser "https://github.com/asubah/minitok-template/blob/main/minitok/regex_compiler.py"
click node_regex_compiler "https://github.com/asubah/minitok-template/blob/main/minitok/regex_compiler.py"
click node_nfa "https://github.com/asubah/minitok-template/blob/main/minitok/automata.py"
click node_determinizer "https://github.com/asubah/minitok-template/blob/main/minitok/automata.py"
click node_token_dfa "https://github.com/asubah/minitok-template/blob/main/minitok/automata.py"
click node_scanner "https://github.com/asubah/minitok-template/blob/main/minitok/automata.py"
click node_cli "https://github.com/asubah/minitok-template/blob/main/minitok/__main__.py"
click node_bpe "https://github.com/asubah/minitok-template/blob/main/minitok/bpe_from_scratch.py"

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_spec_loader,node_user toneBlue
class node_regex_parser,node_regex_compiler,node_nfa,node_determinizer,node_token_dfa toneAmber
class node_scanner,node_cli,node_bpe toneMint
class node_tiktoken,node_comparison toneRose
```

## Components

### Token specification

- [Spec loader](https://github.com/asubah/minitok-template/blob/main/minitok/spec.py): `minitok/spec.py`

### Automata compilation

- [Regex parser](https://github.com/asubah/minitok-template/blob/main/minitok/regex_compiler.py): `minitok/regex_compiler.py`
- [Thompson compiler](https://github.com/asubah/minitok-template/blob/main/minitok/regex_compiler.py): `minitok/regex_compiler.py`
- [NFA model](https://github.com/asubah/minitok-template/blob/main/minitok/automata.py): `minitok/automata.py`
- [Subset construction](https://github.com/asubah/minitok-template/blob/main/minitok/automata.py): `minitok/automata.py`
- [Combined token DFA](https://github.com/asubah/minitok-template/blob/main/minitok/automata.py): `minitok/automata.py`

### Tokenization runtime

- [Maximal-munch scanner](https://github.com/asubah/minitok-template/blob/main/minitok/automata.py): `minitok/automata.py`
- [Tokenize CLI](https://github.com/asubah/minitok-template/blob/main/minitok/__main__.py): `minitok/__main__.py`
- [Scratch BPE](https://github.com/asubah/minitok-template/blob/main/minitok/bpe_from_scratch.py): `minitok/bpe_from_scratch.py`

### LLM comparison

- **tiktoken**
- **Tokenizer comparison**

### Other components

- **Project user**

## Connections

- Project user → Tokenize CLI: runs (evidence: `README.md`)
- Tokenize CLI → Spec loader: loads spec (evidence: `minitok/__main__.py`)
- Tokenize CLI → Combined token DFA: builds DFA (evidence: `minitok/__main__.py`)
- Tokenize CLI → Maximal-munch scanner: scans text (evidence: `minitok/__main__.py`)
- Regex parser → Thompson compiler: parses for (evidence: `minitok/regex_compiler.py`)
- Thompson compiler → NFA model: compiles to (evidence: `README.md`)
- Combined token DFA → Thompson compiler: compiles patterns (evidence: `README.md`)
- Combined token DFA → Subset construction: determinizes (evidence: `README.md`)
- Subset construction → NFA model: reads NFA (evidence: `minitok/automata.py`)
- Maximal-munch scanner → Combined token DFA: uses DFA (evidence: `README.md`)
- Project user → Scratch BPE: trains or encodes (evidence: `README.md`)
- Project user → Tokenizer comparison: compares tokenizers (evidence: `README.md`)
- Tokenizer comparison → tiktoken: uses encoding (evidence: `README.md`)
- Tokenizer comparison → Maximal-munch scanner: compares output (evidence: `README.md`)
- Tokenizer comparison → Scratch BPE: compares output (evidence: `README.md`)
