# krzyzanowskim/sttextview architecture

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

- Interactive diagram: https://gitdiagram.com/krzyzanowskim/sttextview
- Repository: https://github.com/krzyzanowskim/sttextview

## Overview

STTextView is a reusable TextKit 2 editor for macOS and iOS, with SwiftUI wrappers and a demo app. The main workflow is an app or SwiftUI binding supplying editable text and options to the platform editor, which manages text content/layout and presents editing, selection, gutter, and optional completion/plugin capabilities. Shared text-system components underpin separate AppKit and UIKit implementations. Some feature links are documented in the README; unsampled implementation details are not inferred beyond those documented capabilities.

Main entry points: [`Sources/STTextViewAppKit/STTextView.swift`](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STTextView.swift) (AppKit editor), [`Sources/STTextViewUIKit/STTextView.swift`](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewUIKit/STTextView.swift) (UIKit editor), [`Sources/STTextViewSwiftUIUIKit/TextView.swift`](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewSwiftUIUIKit/TextView.swift) (SwiftUI iOS wrapper), [`Sources/STTextViewCommon/STTextLayoutManager.swift`](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/STTextLayoutManager.swift) (Text layout manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["App Interfaces"]
  node_swiftui_mac["SwiftUI macOS wrapper<br/>[TextView.swift]"]
  node_swiftui_ios["SwiftUI iOS wrapper<br/>[TextView.swift]"]
  node_options["View options"]
end

subgraph group_editor["Platform Editors"]
  node_mac_editor["AppKit editor<br/>[STTextView.swift]"]
  node_ios_editor["UIKit editor<br/>[STTextView.swift]"]
end

subgraph group_textsystem["Text System"]
  node_shared_contract["Shared editor contract"]
  node_content_storage[("Text content storage")]
  node_text_element["Attributed text element"]
  node_layout_manager["Text layout manager"]
  node_mac_render["AppKit fragment rendering"]
  node_ios_render["UIKit fragment rendering"]
end

subgraph group_capabilities["Editor Capabilities"]
  node_mac_gutter["AppKit gutter<br/>[STGutterView.swift]"]
  node_ios_gutter["UIKit gutter<br/>[STGutterView.swift]"]
  node_mac_completion["Completion controller"]
  node_completion_window["Completion window"]
  node_plugin_api["Plugin integration"]
  node_mac_editing["Editing services"]
  node_undo["Undo management"]
end

subgraph group_demo["Demo Applications"]
  node_mac_demo["macOS editor demo"]
  node_ios_demo["SwiftUI editor demo<br/>[ContentView.swift]"]
end

node_app_user(("App developer"))
node_swiftui_app(("SwiftUI app"))

node_app_user -->|"configures"| node_mac_editor
node_swiftui_app -->|"binds text"| node_swiftui_mac
node_swiftui_app -->|"binds text"| node_swiftui_ios
node_swiftui_mac -->|"wraps"| node_mac_editor
node_swiftui_ios -->|"creates and updates"| node_ios_editor
node_swiftui_mac -->|"uses options"| node_options
node_swiftui_ios -->|"uses options"| node_options
node_mac_editor -.->|"implements"| node_shared_contract
node_ios_editor -.->|"implements"| node_shared_contract
node_mac_editor -->|"manages text"| node_content_storage
node_ios_editor -->|"manages text"| node_content_storage
node_content_storage -->|"replaces from"| node_text_element
node_mac_editor -->|"uses for layout"| node_layout_manager
node_ios_editor -->|"uses for layout"| node_layout_manager
node_layout_manager -->|"renders fragments"| node_mac_render
node_layout_manager -->|"renders fragments"| node_ios_render
node_mac_editor -->|"offers line numbers"| node_mac_gutter
node_ios_editor -->|"offers line numbers"| node_ios_gutter
node_mac_editor -->|"offers completion"| node_mac_completion
node_mac_completion -->|"hosts in window"| node_completion_window
node_mac_editor -->|"supports plugins"| node_plugin_api
node_mac_editor -->|"provides find and replace"| node_mac_editing
node_mac_editor -->|"supports undo"| node_undo
node_mac_demo -->|"creates"| node_mac_editor
node_mac_demo -->|"supplies completions"| node_mac_completion
node_ios_demo -->|"presents"| node_swiftui_ios

click node_swiftui_mac "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewSwiftUIAppKit/TextView.swift"
click node_swiftui_ios "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewSwiftUIUIKit/TextView.swift"
click node_options "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewSwiftUICommon/TextViewOptions.swift"
click node_mac_editor "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STTextView.swift"
click node_ios_editor "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewUIKit/STTextView.swift"
click node_shared_contract "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/STTextViewProtocol.swift"
click node_content_storage "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/STTextContentStorage.swift"
click node_text_element "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/STAttributedTextElement.swift"
click node_layout_manager "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/STTextLayoutManager.swift"
click node_mac_render "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STTextLayoutFragment.swift"
click node_ios_render "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewUIKit/STTextLayoutFragment.swift"
click node_mac_gutter "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/Gutter/STGutterView.swift"
click node_ios_gutter "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewUIKit/Gutter/STGutterView.swift"
click node_mac_completion "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STCompletion/STCompletionViewController.swift"
click node_completion_window "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STCompletion/Window/STCompletionWindowController.swift"
click node_plugin_api "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/Plugin/STPluginContext.swift"
click node_mac_editing "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STTextView%2BFind.swift"
click node_undo "https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/CoalescingUndoManager.swift"
click node_mac_demo "https://github.com/krzyzanowskim/sttextview/blob/main/TextEdit/Mac/PrimaryTextEditViewController.swift"
click node_ios_demo "https://github.com/krzyzanowskim/sttextview/blob/main/TextEdit.SwiftUI/ContentView.swift"

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_swiftui_mac,node_swiftui_ios,node_options,node_swiftui_app toneBlue
class node_mac_editor,node_ios_editor toneAmber
class node_shared_contract,node_content_storage,node_text_element,node_layout_manager,node_mac_render,node_ios_render toneMint
class node_mac_gutter,node_ios_gutter,node_mac_completion,node_completion_window,node_plugin_api,node_mac_editing,node_undo toneRose
class node_mac_demo,node_ios_demo,node_app_user toneIndigo
```

## Components

### App Interfaces

- [SwiftUI macOS wrapper](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewSwiftUIAppKit/TextView.swift): `Sources/STTextViewSwiftUIAppKit/TextView.swift`
- [SwiftUI iOS wrapper](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewSwiftUIUIKit/TextView.swift): `Sources/STTextViewSwiftUIUIKit/TextView.swift`
- [View options](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewSwiftUICommon/TextViewOptions.swift): `Sources/STTextViewSwiftUICommon/TextViewOptions.swift`

### Platform Editors

- [AppKit editor](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STTextView.swift): `Sources/STTextViewAppKit/STTextView.swift`
- [UIKit editor](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewUIKit/STTextView.swift): `Sources/STTextViewUIKit/STTextView.swift`

### Text System

- [Shared editor contract](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/STTextViewProtocol.swift): `Sources/STTextViewCommon/STTextViewProtocol.swift`
- [Text content storage](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/STTextContentStorage.swift): `Sources/STTextViewCommon/STTextContentStorage.swift`
- [Attributed text element](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/STAttributedTextElement.swift): `Sources/STTextViewCommon/STAttributedTextElement.swift`
- [Text layout manager](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/STTextLayoutManager.swift): `Sources/STTextViewCommon/STTextLayoutManager.swift`
- [AppKit fragment rendering](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STTextLayoutFragment.swift): `Sources/STTextViewAppKit/STTextLayoutFragment.swift`
- [UIKit fragment rendering](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewUIKit/STTextLayoutFragment.swift): `Sources/STTextViewUIKit/STTextLayoutFragment.swift`

### Editor Capabilities

- [AppKit gutter](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/Gutter/STGutterView.swift): `Sources/STTextViewAppKit/Gutter/STGutterView.swift`
- [UIKit gutter](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewUIKit/Gutter/STGutterView.swift): `Sources/STTextViewUIKit/Gutter/STGutterView.swift`
- [Completion controller](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STCompletion/STCompletionViewController.swift): `Sources/STTextViewAppKit/STCompletion/STCompletionViewController.swift`
- [Completion window](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STCompletion/Window/STCompletionWindowController.swift): `Sources/STTextViewAppKit/STCompletion/Window/STCompletionWindowController.swift`
- [Plugin integration](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/Plugin/STPluginContext.swift): `Sources/STTextViewAppKit/Plugin/STPluginContext.swift`
- [Editing services](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewAppKit/STTextView%2BFind.swift): `Sources/STTextViewAppKit/STTextView+Find.swift`
- [Undo management](https://github.com/krzyzanowskim/sttextview/blob/main/Sources/STTextViewCommon/CoalescingUndoManager.swift): `Sources/STTextViewCommon/CoalescingUndoManager.swift`

### Demo Applications

- [macOS editor demo](https://github.com/krzyzanowskim/sttextview/blob/main/TextEdit/Mac/PrimaryTextEditViewController.swift): `TextEdit/Mac/PrimaryTextEditViewController.swift`
- [SwiftUI editor demo](https://github.com/krzyzanowskim/sttextview/blob/main/TextEdit.SwiftUI/ContentView.swift): `TextEdit.SwiftUI/ContentView.swift`

### Other components

- **App developer**
- **SwiftUI app**

## Connections

- App developer → AppKit editor: configures
- SwiftUI app → SwiftUI macOS wrapper: binds text
- SwiftUI app → SwiftUI iOS wrapper: binds text
- SwiftUI macOS wrapper → AppKit editor: wraps (evidence: `Sources/STTextViewSwiftUIAppKit/TextView.swift`)
- SwiftUI iOS wrapper → UIKit editor: creates and updates (evidence: `Sources/STTextViewSwiftUIUIKit/TextView.swift`)
- SwiftUI macOS wrapper → View options: uses options (evidence: `Sources/STTextViewSwiftUIAppKit/TextView.swift`)
- SwiftUI iOS wrapper → View options: uses options (evidence: `Sources/STTextViewSwiftUIUIKit/TextView.swift`)
- AppKit editor → Shared editor contract: implements
- UIKit editor → Shared editor contract: implements
- AppKit editor → Text content storage: manages text
- UIKit editor → Text content storage: manages text
- Text content storage → Attributed text element: replaces from (evidence: `Sources/STTextViewCommon/STTextContentStorage.swift`)
- AppKit editor → Text layout manager: uses for layout
- UIKit editor → Text layout manager: uses for layout
- Text layout manager → AppKit fragment rendering: renders fragments
- Text layout manager → UIKit fragment rendering: renders fragments
- AppKit editor → AppKit gutter: offers line numbers
- UIKit editor → UIKit gutter: offers line numbers
- AppKit editor → Completion controller: offers completion
- Completion controller → Completion window: hosts in window (evidence: `Sources/STTextViewAppKit/STCompletion/Window/STCompletionWindowController.swift`)
- AppKit editor → Plugin integration: supports plugins
- AppKit editor → Editing services: provides find and replace
- AppKit editor → Undo management: supports undo
- macOS editor demo → AppKit editor: creates (evidence: `TextEdit/Mac/PrimaryTextEditViewController.swift`)
- macOS editor demo → Completion controller: supplies completions (evidence: `TextEdit/Mac/PrimaryTextEditViewController.swift`)
- SwiftUI editor demo → SwiftUI iOS wrapper: presents (evidence: `TextEdit.SwiftUI/ContentView.swift`)
