# kumar-kanujia/hecto architecture

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

- Interactive diagram: https://gitdiagram.com/kumar-kanujia/hecto
- Repository: https://github.com/kumar-kanujia/hecto

## Overview

##### Project type and purpose
- This is a terminal-based text editor written in Rust as a learning exercise following the Hecto tutorial.
- It implements raw-mode input handling, a core editing loop, buffer/data structures, command handling, and basic UI components all in one binary.

##### File structure
- Cargo.toml / main.rs
– Defines a single executable crate. main.rs launches the editor application.
- src/editor
– Core logic lives here, split into submodules:
· annotatedstring: the internal buffer representation and annotations
· command: the command pattern implementation (edit, move, system commands)
· line: low-level text/character width handling
· terminal: raw-mode input/output abstractions (attributes, cursor movement)
· uicomponents: rendering of status bar, message bar, command bar, and main view panes
– Other shared types: position.rs, size.rs, documentstatus.rs
- No external services or databases—everything runs in local memory and interacts with the terminal.

##### README for additional insights
- Confirms raw mode, editor loop, and low-level terminal handling as core learning goals.
- All design decisions come from the Hecto tutorial, so architecture matches that guide (an MVC-like separation of model, view, controller).

##### Detail
- Command submodules (edit.rs, movecommand.rs, system.rs) feeding into the dispatcher.
- Annotatedstringiterator as part of the model’s internal data traversal.

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Input/Output Layer"
    TerminalIO["Terminal IO\nLayer"]:::io
  end

  subgraph "Controller Layer"
    subgraph "Input Handler / Event Loop"
      MainRS["main.rs"]:::controller
      EditorRS["editor.rs"]:::controller
    end
    subgraph "Command Dispatcher"
      EditCmd["edit.rs"]:::controller
      MoveCmd["movecommand.rs"]:::controller
      SystemCmd["system.rs"]:::controller
      CmdMod["mod.rs"]:::controller
    end
  end

  subgraph "Model Layer"
    subgraph "Buffer Representation"
      ASIter["annotatedstringiterator.rs"]:::model
      ASPart["annotatedstringpart.rs"]:::model
      Annotation["annotation.rs"]:::model
      AnnotationType["annotationtype.rs"]:::model
      ASMod["mod.rs"]:::model
    end
    subgraph "Line & Grapheme Handling"
      Grapheme["graphemewidth.rs"]:::model
      TextFrag["textfragment.rs"]:::model
      LineMod["mod.rs"]:::model
    end
    DocumentStatus["documentstatus.rs"]:::model
    Position["position.rs"]:::model
    Size["size.rs"]:::model
  end

  subgraph "View Layer"
    subgraph "UI Components / View"
      UIBase["uicomponent.rs"]:::view
      UIMod["mod.rs"]:::view
      CmdBar["commandbar.rs"]:::view
      MsgBar["messagebar.rs"]:::view
      StatBar["statusbar.rs"]:::view
      subgraph "View Pane Components"
        BufferView["buffer.rs"]:::view
        FileInfo["fileinfo.rs"]:::view
        Location["location.rs"]:::view
        SearchDir["searchdirection.rs"]:::view
        SearchInfo["searchinfo.rs"]:::view
        ViewMod["mod.rs"]:::view
      end
    end
  end

  subgraph "Output Renderer"
    OutputRenderer["Output Renderer"]:::io
  end

  TerminalIO -->|"reads keystrokes"| MainRS
  TerminalIO -->|"initializes"| EditorRS
  MainRS -->|"dispatches to"| EditCmd
  MainRS -->|"dispatches to"| MoveCmd
  MainRS -->|"dispatches to"| SystemCmd
  EditCmd -->|"mutate buffer"| ASMod
  MoveCmd -->|"mutate buffer"| ASMod
  SystemCmd -->|"update status"| DocumentStatus
  ASIter -->|"iterate segments"| ASMod
  ASMod -->|"provide text"| BufferView
  LineMod -->|"calculate widths"| BufferView
  DocumentStatus -->|"display status"| StatBar
  BufferView --> OutputRenderer
  CmdBar --> OutputRenderer
  MsgBar --> OutputRenderer
  StatBar --> OutputRenderer
  OutputRenderer -->|"writes ANSI"| TerminalIO

  click TerminalIO "https://github.com/kumar-kanujia/hecto/tree/main/src/editor/terminal"
  click MainRS "https://github.com/kumar-kanujia/hecto/blob/main/src/main.rs"
  click EditorRS "https://github.com/kumar-kanujia/hecto/blob/main/src/editor.rs"
  click EditCmd "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/command/edit.rs"
  click MoveCmd "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/command/movecommand.rs"
  click SystemCmd "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/command/system.rs"
  click CmdMod "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/command/mod.rs"
  click ASIter "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/annotatedstring/annotatedstringiterator.rs"
  click ASPart "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/annotatedstring/annotatedstringpart.rs"
  click Annotation "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/annotatedstring/annotation.rs"
  click AnnotationType "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/annotatedstring/annotationtype.rs"
  click ASMod "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/annotatedstring/mod.rs"
  click Grapheme "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/line/graphemewidth.rs"
  click TextFrag "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/line/textfragment.rs"
  click LineMod "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/line/mod.rs"
  click DocumentStatus "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/documentstatus.rs"
  click Position "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/position.rs"
  click Size "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/size.rs"
  click UIBase "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/uicomponent.rs"
  click UIMod "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/mod.rs"
  click CmdBar "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/commandbar.rs"
  click MsgBar "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/messagebar.rs"
  click StatBar "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/statusbar.rs"
  click BufferView "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/view/buffer.rs"
  click FileInfo "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/view/fileinfo.rs"
  click Location "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/view/location.rs"
  click SearchDir "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/view/searchdirection.rs"
  click SearchInfo "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/view/searchinfo.rs"
  click ViewMod "https://github.com/kumar-kanujia/hecto/blob/main/src/editor/uicomponents/view/mod.rs"

  classDef io fill:#ADD8E6,stroke:#333,stroke-width:1px
  classDef controller fill:#90EE90,stroke:#333,stroke-width:1px
  classDef model fill:#FFFFE0,stroke:#333,stroke-width:1px
  classDef view fill:#FFA500,stroke:#333,stroke-width:1px
```
