# p4ymak/egui_code_editor architecture

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

- Interactive diagram: https://gitdiagram.com/p4ymak/egui_code_editor
- Repository: https://github.com/p4ymak/egui_code_editor

## Overview

Egui Code Editor is a Rust widget library and standalone lexer. Its primary workflow takes user-edited text and a language syntax, tokenizes and highlights it, then renders it through an egui editor with optional line numbers, clickable links, themes, and completion. The graph groups syntax definitions, tokenization, editor rendering and interaction, completion, and themes. README documents the lexer-only mode and optional user-word completion; sampled sources show core calls, while unsampled language definitions and themes are represented by their exact files without speculative links.

Main entry points: [`src/syntax/mod.rs`](https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/mod.rs) (Syntax Rules), [`src/lib.rs`](https://github.com/p4ymak/egui_code_editor/blob/main/src/lib.rs) (Code Editor), [`src/themes/mod.rs`](https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/mod.rs) (Theme Palette), [`src/completer/mod.rs`](https://github.com/p4ymak/egui_code_editor/blob/main/src/completer/mod.rs) (Completion UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_syntax["Syntax Definitions"]
  node_syntax_api["Syntax Rules<br/>[mod.rs]"]
  node_asm["Assembly Rules<br/>[asm.rs]"]
  node_lua["Lua Rules<br/>[lua.rs]"]
  node_python["Python Rules<br/>[python.rs]"]
  node_rust["Rust Rules<br/>[rust.rs]"]
  node_shell["Shell Rules<br/>[shell.rs]"]
  node_sql["SQL Rules<br/>[sql.rs]"]
end

subgraph group_lexer["Tokenization"]
  node_tokenizer["Token Lexer<br/>[highlighting.rs]"]
end

subgraph group_editor["Editor UI"]
  node_editor_widget["Code Editor<br/>[lib.rs]"]
  node_link_handler["Clickable Links<br/>[hyperlinks.rs]"]
end

subgraph group_completion["Completion"]
  node_completion_ui["Completion UI<br/>[mod.rs]"]
  node_trie["Word Trie<br/>[trie.rs]"]
end

subgraph group_themes["Theme Catalog"]
  node_theme_api["Theme Palette<br/>[mod.rs]"]
  node_ayu["Ayu Themes<br/>[ayu.rs]"]
  node_github["GitHub Themes<br/>[github.rs]"]
  node_gruvbox["Gruvbox Themes<br/>[gruvbox.rs]"]
  node_sonokai["Sonokai Theme<br/>[sonokai.rs]"]
end

node_user(("Editor User"))
node_egui["egui UI"]
node_url_service["URL Opener"]

node_user -->|"edits text"| node_editor_widget
node_editor_widget -->|"highlights text"| node_tokenizer
node_tokenizer -->|"checks rules"| node_syntax_api
node_syntax_api -->|"defines rules"| node_asm
node_syntax_api -->|"defines rules"| node_lua
node_syntax_api -->|"defines rules"| node_python
node_syntax_api -->|"defines rules"| node_rust
node_syntax_api -->|"defines rules"| node_shell
node_syntax_api -->|"defines rules"| node_sql
node_editor_widget -->|"renders widget"| node_egui
node_editor_widget -->|"formats tokens"| node_theme_api
node_editor_widget -->|"handles links"| node_link_handler
node_link_handler -->|"opens targets"| node_url_service
node_editor_widget -->|"shows completion"| node_completion_ui
node_completion_ui -->|"queries words"| node_trie
node_completion_ui -->|"collects user words"| node_tokenizer
node_theme_api -->|"exports palette"| node_ayu
node_theme_api -->|"exports palette"| node_github
node_theme_api -->|"exports palette"| node_gruvbox
node_theme_api -->|"exports palette"| node_sonokai
node_egui -->|"provides UI"| node_editor_widget

click node_syntax_api "https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/mod.rs"
click node_asm "https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/asm.rs"
click node_lua "https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/lua.rs"
click node_python "https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/python.rs"
click node_rust "https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/rust.rs"
click node_shell "https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/shell.rs"
click node_sql "https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/sql.rs"
click node_tokenizer "https://github.com/p4ymak/egui_code_editor/blob/main/src/highlighting.rs"
click node_editor_widget "https://github.com/p4ymak/egui_code_editor/blob/main/src/lib.rs"
click node_link_handler "https://github.com/p4ymak/egui_code_editor/blob/main/src/hyperlinks.rs"
click node_completion_ui "https://github.com/p4ymak/egui_code_editor/blob/main/src/completer/mod.rs"
click node_trie "https://github.com/p4ymak/egui_code_editor/blob/main/src/completer/trie.rs"
click node_theme_api "https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/mod.rs"
click node_ayu "https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/ayu.rs"
click node_github "https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/github.rs"
click node_gruvbox "https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/gruvbox.rs"
click node_sonokai "https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/sonokai.rs"

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_syntax_api,node_asm,node_lua,node_python,node_rust,node_shell,node_sql,node_user,node_egui toneBlue
class node_tokenizer toneAmber
class node_editor_widget,node_link_handler toneMint
class node_completion_ui,node_trie toneRose
class node_theme_api,node_ayu,node_github,node_gruvbox,node_sonokai,node_url_service toneIndigo
```

## Components

### Syntax Definitions

- [Syntax Rules](https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/mod.rs): `src/syntax/mod.rs`
- [Assembly Rules](https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/asm.rs): `src/syntax/asm.rs`
- [Lua Rules](https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/lua.rs): `src/syntax/lua.rs`
- [Python Rules](https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/python.rs): `src/syntax/python.rs`
- [Rust Rules](https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/rust.rs): `src/syntax/rust.rs`
- [Shell Rules](https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/shell.rs): `src/syntax/shell.rs`
- [SQL Rules](https://github.com/p4ymak/egui_code_editor/blob/main/src/syntax/sql.rs): `src/syntax/sql.rs`

### Tokenization

- [Token Lexer](https://github.com/p4ymak/egui_code_editor/blob/main/src/highlighting.rs): `src/highlighting.rs`

### Editor UI

- [Code Editor](https://github.com/p4ymak/egui_code_editor/blob/main/src/lib.rs): `src/lib.rs`
- [Clickable Links](https://github.com/p4ymak/egui_code_editor/blob/main/src/hyperlinks.rs): `src/hyperlinks.rs`

### Completion

- [Completion UI](https://github.com/p4ymak/egui_code_editor/blob/main/src/completer/mod.rs): `src/completer/mod.rs`
- [Word Trie](https://github.com/p4ymak/egui_code_editor/blob/main/src/completer/trie.rs): `src/completer/trie.rs`

### Theme Catalog

- [Theme Palette](https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/mod.rs): `src/themes/mod.rs`
- [Ayu Themes](https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/ayu.rs): `src/themes/ayu.rs`
- [GitHub Themes](https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/github.rs): `src/themes/github.rs`
- [Gruvbox Themes](https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/gruvbox.rs): `src/themes/gruvbox.rs`
- [Sonokai Theme](https://github.com/p4ymak/egui_code_editor/blob/main/src/themes/sonokai.rs): `src/themes/sonokai.rs`

### Other components

- **Editor User**
- **egui UI**
- **URL Opener**

## Connections

- Editor User → Code Editor: edits text (evidence: `README.md`)
- Code Editor → Token Lexer: highlights text (evidence: `src/lib.rs`)
- Token Lexer → Syntax Rules: checks rules (evidence: `src/highlighting.rs`)
- Syntax Rules → Assembly Rules: defines rules (evidence: `src/syntax/mod.rs`)
- Syntax Rules → Lua Rules: defines rules (evidence: `src/syntax/mod.rs`)
- Syntax Rules → Python Rules: defines rules (evidence: `src/syntax/mod.rs`)
- Syntax Rules → Rust Rules: defines rules (evidence: `src/syntax/mod.rs`)
- Syntax Rules → Shell Rules: defines rules (evidence: `src/syntax/mod.rs`)
- Syntax Rules → SQL Rules: defines rules (evidence: `src/syntax/mod.rs`)
- Code Editor → egui UI: renders widget (evidence: `src/lib.rs`)
- Code Editor → Theme Palette: formats tokens (evidence: `src/lib.rs`)
- Code Editor → Clickable Links: handles links (evidence: `src/lib.rs`)
- Clickable Links → URL Opener: opens targets (evidence: `src/hyperlinks.rs`)
- Code Editor → Completion UI: shows completion (evidence: `README.md`)
- Completion UI → Word Trie: queries words (evidence: `src/completer/mod.rs`)
- Completion UI → Token Lexer: collects user words (evidence: `src/completer/mod.rs`)
- Theme Palette → Ayu Themes: exports palette (evidence: `src/themes/mod.rs`)
- Theme Palette → GitHub Themes: exports palette (evidence: `src/themes/mod.rs`)
- Theme Palette → Gruvbox Themes: exports palette (evidence: `src/themes/mod.rs`)
- Theme Palette → Sonokai Theme: exports palette (evidence: `src/themes/mod.rs`)
- egui UI → Code Editor: provides UI
