# mechamobau/edithor architecture

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

- Interactive diagram: https://gitdiagram.com/mechamobau/edithor
- Repository: https://github.com/mechamobau/edithor

## Overview

##### Project Type and Purpose
- Edithor is a terminal‐based text editor (open-source tool), written in Rust.
- It provides Vim-inspired modal editing, LSP integration, plugin support, and high performance.

##### File Structure
- src/main.rs: program entrypoint, argument parsing, initialization
- src/editor.rs: core editor logic (buffer management, key mappings, rendering loop)
- Cargo.toml / Cargo.lock: dependency declarations (e.g., crossterm, tower-lsp)
- Repo metadata (README, CONTRIBUTING, LICENSE, etc.)

##### README for Additional Insights
- Key features: Vim keybindings, LSP for syntax highlighting, plugin architecture, configurability
- Usage model: CLI (“edithor <filename>”), modes (insert, normal), commands

##### Main Components
a. CLI / Launcher
– Parses command-line args, locates config file, and passes entry file to the Editor Core.
b. Configuration Loader
– Reads user config (keybindings, theme, plugin list) on startup.
c. Editor Core (Editor Module)
– Buffer Manager: holds text, tracks cursor, undo/redo.
– Keybinding / Command Handler: maps keystrokes to actions (insert, delete, save).
d. File I/O
– Reads/writes the document from disk, signals Editor Core on saves/loads.
e. LSP Client Integration
– Runs an LSP client over stdin/stdout or TCP, forwards buffer contents to the language server, receives syntax highlights, diagnostics.
f. Plugin Manager
– Loads and communicates with plugins (via dynamic libraries or external processes), extends commands or language supports.
g. External Services
– Language Servers (e.g., rust-analyzer) over LSP protocol.

##### Relationships & Data Flows
– User Input → Keybinding Handler → Editor Core
– Editor Core → Buffer Manager & Command Executor → Rendering Engine → Terminal
– Editor Core ↔ LSP Client → Language Server
– Editor Core ↔ File I/O → Disk
– Startup: CLI → Configuration Loader → Plugin Manager → Editor Core

##### Architectural Patterns & Principles
– Separation of Concerns: distinct modules for input, state, rendering, external comms
– Plugin Architecture: clearly defined extension points
– Event-driven Loop: editor loop processes input events and redraws
– Client-Server for LSP: standard protocol over IPC

##### Final Checklist
– All major modules from src/ (main.rs, editor.rs).
– Config loader and plugin manager.
– File I/O and disk interactions.
– LSP Client ↔ Language Server.
– Callouts for key crates or protocols (Rust, LSP).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clusters
    subgraph "CLI & Configuration"
        direction TB
        CLI["CLI / Launcher"]:::internal
        ConfigLoader["Configuration Loader"]:::internal
        Dependencies["Dependency Declarations<br/>(Cargo.toml)"]:::internal
    end

    subgraph "Editor Core"
        direction TB
        EditorCore["Editor Core"]:::internal
        Buffer["Buffer Manager"]:::internal
        KeyHandler["Keybinding / Command Handler"]:::internal
        Renderer["Rendering Engine<br/>(crossterm)"]:::internal
        FileIO["File I/O"]:::filesystem
    end

    subgraph "Integration"
        direction TB
        LSPClient["LSP Client<br/>(tower-lsp)"]:::internal
        PluginMgr["Plugin Manager"]:::plugin
    end

    subgraph "External Services"
        direction TB
        LLServer["Language Server<br/>(e.g., rust-analyzer)"]:::external
        Disk["Disk"]:::filesystem
    end

    UserInput["User Input"]:::external

    %% Relationships
    UserInput -->|"key event"| KeyHandler
    CLI -->|"startup"| ConfigLoader
    ConfigLoader -->|"load config & plugins"| PluginMgr
    PluginMgr -->|"initialize"| EditorCore
    KeyHandler -->|"execute command"| EditorCore
    EditorCore --> Buffer
    Buffer --> Renderer
    Renderer -->|"render frame"| EditorCore
    EditorCore --> FileIO
    FileIO -->|"read/write"| Disk
    EditorCore <-->|"LSP messages"| LSPClient
    LSPClient <-->|"LSP protocol"| LLServer

    %% Click Events
    click CLI "https://github.com/mechamobau/edithor/blob/main/src/main.rs"
    click ConfigLoader "https://github.com/mechamobau/edithor/blob/main/src/main.rs"
    click EditorCore "https://github.com/mechamobau/edithor/blob/main/src/editor.rs"
    click LSPClient "https://github.com/mechamobau/edithor/blob/main/src/editor.rs"
    click Dependencies "https://github.com/mechamobau/edithor/blob/main/Cargo.toml"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef external fill:#90EE90,stroke:#000,stroke-width:1px
    classDef filesystem fill:#FFFFE0,stroke:#000,stroke-width:1px
    classDef plugin fill:#DDA0DD,stroke:#000,stroke-width:1px
```
