# notphrog/dumbgpt architecture

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

- Interactive diagram: https://gitdiagram.com/notphrog/dumbgpt
- Repository: https://github.com/notphrog/dumbgpt

## Overview

dumbGPT is a terminal-based text generator: users choose an n-gram size, load a registered template or provide text files, then prompt the trained engine and view generated text. Its documented runtime includes template reuse, custom training data, Katz backoff, weighted token selection, and punctuation-aware output. The implementation is a single C++ file; the source excerpt omits some template-loading and output-handling details, so those links are limited to documented behavior.

Main entry points: [`ai_markov.cpp`](https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp) (Interactive CLI), [`template_registry.txt`](https://github.com/notphrog/dumbgpt/blob/main/template_registry.txt) (Template registry), [`templates`](https://github.com/notphrog/dumbgpt/tree/main/templates) (Template manifests), [`training_data`](https://github.com/notphrog/dumbgpt/tree/main/training_data) (Training corpora)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Terminal workflow"]
  node_cli["Interactive CLI<br/>[ai_markov.cpp]"]
  node_console["Generated text"]
end

subgraph group_data["Training data"]
  node_registry["Template registry"]
  node_templates["Template manifests"]
  node_training["Training corpora"]
end

subgraph group_engine["Generation engine"]
  node_loader["File trainer<br/>[ai_markov.cpp]"]
  node_tokenizer["Text tokenizer<br/>[ai_markov.cpp]"]
  node_model[("N-gram map<br/>[ai_markov.cpp]")]
  node_sampler["Backoff sampler<br/>[ai_markov.cpp]"]
  node_generator["Text generator<br/>[ai_markov.cpp]"]
  node_formatter["Output formatting<br/>[ai_markov.cpp]"]
end

node_user(("User"))
node_custom_files["Custom text files"]

node_user -->|"chooses settings"| node_cli
node_cli -->|"reads index"| node_registry
node_cli -->|"loads manifest"| node_templates
node_cli -->|"accepts paths"| node_custom_files
node_cli -->|"trains on files"| node_loader
node_training -->|"provides text"| node_loader
node_custom_files -->|"provides text"| node_loader
node_loader -->|"tokenizes text"| node_tokenizer
node_tokenizer -->|"adds transitions"| node_model
node_cli -->|"submits prompt"| node_generator
node_generator -->|"tokenizes prompt"| node_tokenizer
node_generator -->|"requests next token"| node_sampler
node_sampler -->|"looks up contexts"| node_model
node_sampler -->|"returns token"| node_generator
node_generator -->|"formats sequence"| node_formatter
node_cli -->|"displays result"| node_console
node_formatter -->|"produces text"| node_console
node_cli -->|"saves manifests"| node_templates
node_cli -->|"registers template"| node_registry

click node_cli "https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp"
click node_registry "https://github.com/notphrog/dumbgpt/blob/main/template_registry.txt"
click node_templates "https://github.com/notphrog/dumbgpt/tree/main/templates"
click node_training "https://github.com/notphrog/dumbgpt/tree/main/training_data"
click node_loader "https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp"
click node_tokenizer "https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp"
click node_model "https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp"
click node_sampler "https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp"
click node_generator "https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp"
click node_formatter "https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp"

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_cli,node_console,node_user toneBlue
class node_registry,node_templates,node_training toneAmber
class node_loader,node_tokenizer,node_model,node_sampler,node_generator,node_formatter toneMint
class node_custom_files toneIndigo
```

## Components

### Terminal workflow

- [Interactive CLI](https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp): `ai_markov.cpp`
- **Generated text**

### Training data

- [Template registry](https://github.com/notphrog/dumbgpt/blob/main/template_registry.txt): `template_registry.txt`
- [Template manifests](https://github.com/notphrog/dumbgpt/tree/main/templates): `templates`
- [Training corpora](https://github.com/notphrog/dumbgpt/tree/main/training_data): `training_data`

### Generation engine

- [File trainer](https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp): `ai_markov.cpp`
- [Text tokenizer](https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp): `ai_markov.cpp`
- [N-gram map](https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp): `ai_markov.cpp`
- [Backoff sampler](https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp): `ai_markov.cpp`
- [Text generator](https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp): `ai_markov.cpp`
- [Output formatting](https://github.com/notphrog/dumbgpt/blob/main/ai_markov.cpp): `ai_markov.cpp`

### Other components

- **User**
- **Custom text files**

## Connections

- User → Interactive CLI: chooses settings
- Interactive CLI → Template registry: reads index
- Interactive CLI → Template manifests: loads manifest
- Interactive CLI → Custom text files: accepts paths
- Interactive CLI → File trainer: trains on files
- Training corpora → File trainer: provides text
- Custom text files → File trainer: provides text
- File trainer → Text tokenizer: tokenizes text
- Text tokenizer → N-gram map: adds transitions
- Interactive CLI → Text generator: submits prompt
- Text generator → Text tokenizer: tokenizes prompt
- Text generator → Backoff sampler: requests next token
- Backoff sampler → N-gram map: looks up contexts
- Backoff sampler → Text generator: returns token
- Text generator → Output formatting: formats sequence
- Interactive CLI → Generated text: displays result
- Output formatting → Generated text: produces text
- Interactive CLI → Template manifests: saves manifests
- Interactive CLI → Template registry: registers template
