# wllfaria/glyph architecture

> Architecture diagram of the GitHub repository wllfaria/glyph, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wllfaria/glyph
- Repository: https://github.com/wllfaria/glyph

## Overview

##### Project Type and Purpose
- Glyph is a terminal-based text editor inspired by Neovim.
- Its purpose is to provide a lightweight, terminal UI text editor with an emphasis on performance, configurability (using Lua for runtime configuration), and text handling.
- The project is modularized into several Rust crates, each with distinct responsibilities.

##### File Structure
- Top-Level Directories and Files:
- Several project-level configuration files (e.g., .editorconfig, rustfmt.toml) guide coding style and build processes.
- The “.github” directory contains CI/CD workflows, indicating automated testing and coverage measures.
- Crate Breakdown:
- glyph-core:
- Contains core logic for the editor including configuration, managing the document model, rendering logic, and handling editor commands.
- glyph-runtime:
- Provides an API layer (found in its “api” and “config” directories) which likely bridges the core editor functionality with a scriptable runtime (Lua-based configuration).
- Contains error handling and public interfaces.
- glyph-term:
- Serves as the terminal interface backend, handling terminal I/O, rendering, and UI components (e.g., line number display and graphics).
- Files in “backend”, “layers”, “ui”, and “renderer” clearly indicate separation of terminal-specific responsibilities.
- glyph-trie:
- Contains a library for trie data structures, which might be used for efficient text search, command auto-completion, or syntax analysis.
- glyph (the main binary):
- Acts as the entry point for launching the editor, loading configurations, and initializing the various components.
- Additional Directories:
- languages/queries:
- Contains tree-sitter queries or syntax highlighting schemes for multiple languages (e.g., C, Rust, Lua). This indicates that the editor supports contextual syntax highlighting and parsing.
- runtime:
- Holds Lua files for API definitions and defaults (commands, keymaps, themes), indicating a separation between compile-time core logic and runtime-configurable behaviors.

a. Main Components:
- Glyph Binary (Main Entrypoint): Initiates the editor, orchestrates the startup process.
- Glyph Core: Provides the primary text editing functionality, handling documents, buffers, configuration, and internal APIs.
- Glyph Runtime: Offers a scripting layer and Lua APIs for plugin support, user configuration, and runtime modifications.
- Glyph Terminal (glyph-term): Manages terminal I/O, rendering of editor UI, manages user input, and terminal display capabilities.
- Glyph Trie (glyph-trie): Implements trie data structures to support features like search, autocomplete, or fast text analysis.
- Language Support (languages/queries): Contains language-specific queries for syntax highlighting and parsing (likely integrated with tree-sitter or another parsing tool).
- Configuration and Plugin System (runtime): Provides default configurations and plugin support via Lua scripts and runtime initialization.

b. Relationships and Interactions:
- The Glyph binary will initiate and load the Glyph Core, which in turn interacts with both the Glyph Runtime (for Lua-based configurations, API exposure, and plugins) and Glyph Terminal for the UI.
- User input is captured by the Glyph Terminal backend, which sends key events to the core editor logic.
- The core editing functionality processes commands (perhaps through glyph-core’s command modules) and updates the document state.
- The Glyph Runtime layer exposes APIs (via the runtime/api and related modules) to allow dynamic configuration and plugin execution.
- The Glyph Trie may be used by the core for efficient searching or auto-completion, connecting with command processing.
- The languages/queries directory supports syntax highlighting by providing language definitions and tree-sitter queries.

c. Architectural Patterns and Design Principles:
- Layered Architecture: There is a separation between core functionality, runtime behavior, and terminal UI rendering.
- Modularity: The system separates concerns into multiple crates (e.g., core, runtime, term, trie), each with a clear focus.
- Plugin/Extensibility: The use of Lua in the runtime directory indicates a design for user customization and extensibility through scripts.
- Separation of Concerns: Dedicated directories for API, configuration, and language-specific files highlight intentional component separation.

d. Relevant Technologies and Frameworks:
- Rust is the primary language, ensuring memory safety and performance.
- Lua is used for runtime API and configuration, enabling dynamic behavior and scripting.
- Associated build and testing tools (Cargo, Justfile) and GitHub workflows for CI indicate modern development practices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Layer
    subgraph "Entry Layer"
        A["Glyph (Main Binary)"]:::main
    end

    %% Core Layer
    subgraph "Core Layer"
        B["Core Editor (glyph-core)"]:::core
        E["Trie Support (glyph-trie)"]:::trie
        F["Language Queries (languages/queries)"]:::language
    end

    %% Terminal Layer
    subgraph "Terminal Layer"
        C["Terminal I/O & Renderer (glyph-term)"]:::terminal
    end

    %% Runtime Layer
    subgraph "Runtime Layer"
        D["Runtime API & Config (glyph-runtime)"]:::runtime
        G["Runtime Plugin System (runtime)"]:::plugin
    end

    %% Connections
    A -->|"init"| B
    C -->|"user_input"| B
    B -->|"config"| D
    D -->|"update"| B
    B -->|"autocomplete"| E
    B -->|"syntax"| F
    D -->|"plugin_config"| G
    G -->|"extension"| B

    %% Click Events
    click A "https://github.com/wllfaria/glyph/blob/main/glyph/src/main.rs"
    click B "https://github.com/wllfaria/glyph/blob/main/glyph-core/src/lib.rs"
    click D "https://github.com/wllfaria/glyph/tree/main/glyph-runtime/src/api"
    click C "https://github.com/wllfaria/glyph/tree/main/glyph-term/src/backend"
    click E "https://github.com/wllfaria/glyph/blob/main/glyph-trie/src/lib.rs"
    click F "https://github.com/wllfaria/glyph/tree/main/languages/queries"
    click G "https://github.com/wllfaria/glyph/tree/main/runtime"

    %% Styles
    classDef main fill:#f0f9ff,stroke:#333,stroke-width:2px;
    classDef core fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef runtime fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef terminal fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef trie fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef language fill:#e2e3e5,stroke:#333,stroke-width:2px;
    classDef plugin fill:#ead1dc,stroke:#333,stroke-width:2px;
```
