# tharana-dev/markov-chain-generator architecture

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

- Interactive diagram: https://gitdiagram.com/tharana-dev/markov-chain-generator
- Repository: https://github.com/tharana-dev/markov-chain-generator

## Overview

This is a dependency-free Markov text generator and word-transition graph toolkit. The demo workflow samples a local corpus, tokenizes it into sentences, builds transition and starter-frequency data, then produces text and graph-search results for terminal and append-only log output. The tokenizer, model, generation, and search stages are distinct; logging is documented and visible in the demo. Edges reflect calls shown in the excerpts or README; no separate external service is involved.

Main entry points: [`main.py`](https://github.com/tharana-dev/markov-chain-generator/blob/main/main.py) (Demo Orchestrator), [`chain.py`](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py) (Transition Counts), [`tokenizer.py`](https://github.com/tharana-dev/markov-chain-generator/blob/main/tokenizer.py) (Sentence Tokenizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_processing["Text Processing"]
  node_tokenizer["Sentence Tokenizer<br/>[tokenizer.py]"]
  node_lookahead["Capitalization Look-ahead<br/>[tokenizer.py]"]
end

subgraph group_engine["Markov Engine"]
  node_model["Chain Data Builder<br/>[chain.py]"]
  node_starters["Starter Frequencies<br/>[chain.py]"]
  node_transitions[("Transition Counts<br/>[chain.py]")]
  node_weighted["Weighted Selection<br/>[chain.py]"]
  node_generation["Text Generation<br/>[chain.py]"]
  node_stream["Lazy Generation<br/>[chain.py]"]
end

subgraph group_search["Graph Search"]
  node_reachable["Reachability DFS<br/>[chain.py]"]
  node_dfs["Backtracking DFS<br/>[chain.py]"]
  node_bfs["Shortest-Path BFS<br/>[chain.py]"]
  node_pathbuilder["Path Reconstruction<br/>[chain.py]"]
end

subgraph group_demo["Demo and Output"]
  node_demo["Demo Orchestrator<br/>[main.py]"]
end

node_user(("User"))
node_corpus["Sample Corpus"]
node_terminal(("Terminal"))
node_log["Historical Log"]

node_user -->|"runs"| node_demo
node_demo -->|"samples"| node_corpus
node_demo -->|"tokenizes"| node_tokenizer
node_tokenizer -->|"checks casing"| node_lookahead
node_demo -->|"builds data"| node_model
node_model -->|"counts starts"| node_starters
node_model -->|"counts transitions"| node_transitions
node_demo -->|"generates text"| node_generation
node_generation -->|"selects tokens"| node_weighted
node_weighted -->|"weights start"| node_starters
node_weighted -->|"weights follower"| node_transitions
node_demo -->|"requests stream"| node_stream
node_stream -->|"selects tokens"| node_weighted
node_demo -->|"finds reachable words"| node_reachable
node_reachable -->|"traverses edges"| node_transitions
node_demo -->|"finds route"| node_dfs
node_dfs -->|"traverses edges"| node_transitions
node_demo -->|"finds shortest route"| node_bfs
node_bfs -->|"traverses edges"| node_transitions
node_bfs -->|"reconstructs route"| node_pathbuilder
node_demo -->|"prints results"| node_terminal
node_demo -->|"appends run"| node_log

click node_tokenizer "https://github.com/tharana-dev/markov-chain-generator/blob/main/tokenizer.py"
click node_lookahead "https://github.com/tharana-dev/markov-chain-generator/blob/main/tokenizer.py"
click node_demo "https://github.com/tharana-dev/markov-chain-generator/blob/main/main.py"
click node_model "https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py"
click node_starters "https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py"
click node_transitions "https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py"
click node_weighted "https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py"
click node_generation "https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py"
click node_stream "https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py"
click node_reachable "https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py"
click node_dfs "https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py"
click node_bfs "https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py"
click node_pathbuilder "https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.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_tokenizer,node_lookahead,node_user toneBlue
class node_model,node_starters,node_transitions,node_weighted,node_generation,node_stream toneAmber
class node_reachable,node_dfs,node_bfs,node_pathbuilder toneMint
class node_demo toneRose
class node_corpus,node_terminal,node_log toneIndigo
```

## Components

### Text Processing

- [Sentence Tokenizer](https://github.com/tharana-dev/markov-chain-generator/blob/main/tokenizer.py): `tokenizer.py`
- [Capitalization Look-ahead](https://github.com/tharana-dev/markov-chain-generator/blob/main/tokenizer.py): `tokenizer.py`

### Markov Engine

- [Chain Data Builder](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py): `chain.py`
- [Starter Frequencies](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py): `chain.py`
- [Transition Counts](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py): `chain.py`
- [Weighted Selection](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py): `chain.py`
- [Text Generation](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py): `chain.py`
- [Lazy Generation](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py): `chain.py`

### Graph Search

- [Reachability DFS](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py): `chain.py`
- [Backtracking DFS](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py): `chain.py`
- [Shortest-Path BFS](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py): `chain.py`
- [Path Reconstruction](https://github.com/tharana-dev/markov-chain-generator/blob/main/chain.py): `chain.py`

### Demo and Output

- [Demo Orchestrator](https://github.com/tharana-dev/markov-chain-generator/blob/main/main.py): `main.py`

### Other components

- **User**
- **Sample Corpus**
- **Terminal**
- **Historical Log**

## Connections

- User → Demo Orchestrator: runs (evidence: `readme.md`)
- Demo Orchestrator → Sample Corpus: samples (evidence: `main.py`)
- Demo Orchestrator → Sentence Tokenizer: tokenizes (evidence: `main.py`)
- Sentence Tokenizer → Capitalization Look-ahead: checks casing (evidence: `tokenizer.py`)
- Demo Orchestrator → Chain Data Builder: builds data (evidence: `main.py`)
- Chain Data Builder → Starter Frequencies: counts starts (evidence: `chain.py`)
- Chain Data Builder → Transition Counts: counts transitions (evidence: `chain.py`)
- Demo Orchestrator → Text Generation: generates text (evidence: `main.py`)
- Text Generation → Weighted Selection: selects tokens (evidence: `chain.py`)
- Weighted Selection → Starter Frequencies: weights start (evidence: `chain.py`)
- Weighted Selection → Transition Counts: weights follower (evidence: `chain.py`)
- Demo Orchestrator → Lazy Generation: requests stream (evidence: `main.py`)
- Lazy Generation → Weighted Selection: selects tokens (evidence: `chain.py`)
- Demo Orchestrator → Reachability DFS: finds reachable words (evidence: `main.py`)
- Reachability DFS → Transition Counts: traverses edges (evidence: `chain.py`)
- Demo Orchestrator → Backtracking DFS: finds route (evidence: `main.py`)
- Backtracking DFS → Transition Counts: traverses edges (evidence: `chain.py`)
- Demo Orchestrator → Shortest-Path BFS: finds shortest route (evidence: `main.py`)
- Shortest-Path BFS → Transition Counts: traverses edges (evidence: `chain.py`)
- Shortest-Path BFS → Path Reconstruction: reconstructs route (evidence: `chain.py`)
- Demo Orchestrator → Terminal: prints results (evidence: `main.py`)
- Demo Orchestrator → Historical Log: appends run (evidence: `main.py`)
