# nalexn/viewinspector architecture

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

- Interactive diagram: https://gitdiagram.com/nalexn/viewinspector
- Repository: https://github.com/nalexn/viewinspector

## Overview

ViewInspector is a Swift library for unit-testing SwiftUI views by reflecting on their runtime structure. A test starts inspection on a view, then traverses or searches the resulting hierarchy, reads view and modifier state, and can invoke supported callbacks to simulate interactions. The graph highlights the shared reflection and hierarchy machinery plus representative view, modifier, and popup inspection. README capabilities guide the coverage; several subsystem details are inferred from the file tree because their source was not sampled.

Main entry points: [`Sources/ViewInspector/InspectableView.swift`](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/InspectableView.swift) (Inspectable hierarchy), [`Sources/ViewInspector/ViewSearch.swift`](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/ViewSearch.swift) (Find and traverse), [`Sources/ViewInspector/SwiftUI/Text.swift`](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/Text.swift) (Text inspection), [`Sources/ViewInspector/ContentExtraction.swift`](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/ContentExtraction.swift) (Content extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Inspection entry"]
  node_inspect_api["Inspect entry"]
  node_hosting["Inspection context<br/>[ViewHosting.swift]"]
  node_content["Content extraction"]
  node_inspector["Reflection utilities<br/>[Inspector.swift]"]
end

subgraph group_hierarchy["Hierarchy and search"]
  node_view_tree["Inspectable hierarchy"]
  node_view_search["Find and traverse<br/>[ViewSearch.swift]"]
  node_search_index["View type index"]
  node_lazy_group["Child collections<br/>[LazyGroup.swift]"]
end

subgraph group_inspection["View inspection"]
  node_text_inspection["Text inspection<br/>[Text.swift]"]
  node_view_adaptors["SwiftUI view adapters<br/>[AnyView.swift]"]
  node_modifier_inspection["Modifier inspection"]
  node_text_attributes["Text attributes"]
  node_environment["Environment injection"]
  node_popup_inspection["Popup inspection<br/>[Alert.swift]"]
end

subgraph group_interaction["State and interaction"]
  node_gesture_inspection["Gesture callbacks<br/>[Gesture.swift]"]
  node_accessibility["Accessibility actions"]
end

node_test_author(("Test author"))
node_sut["SwiftUI view under test"]

node_test_author -->|"provides view"| node_sut
node_test_author -->|"starts inspection"| node_inspect_api
node_inspect_api -->|"creates context"| node_hosting
node_inspect_api -->|"unwraps view"| node_content
node_content -->|"reflects structure"| node_inspector
node_inspect_api -->|"creates root"| node_view_tree
node_view_tree -->|"reads attributes"| node_inspector
node_view_tree -->|"supports search"| node_view_search
node_view_search -->|"identifies types"| node_search_index
node_view_search -->|"traverses children"| node_lazy_group
node_view_tree -->|"adapts view types"| node_view_adaptors
node_view_tree -->|"reads text"| node_text_inspection
node_text_inspection -->|"reads attributes"| node_text_attributes
node_view_tree -->|"reads modifiers"| node_modifier_inspection
node_view_tree -->|"reads environment"| node_environment
node_view_tree -->|"inspects popup"| node_popup_inspection
node_view_tree -->|"invokes callbacks"| node_gesture_inspection
node_view_tree -->|"invokes actions"| node_accessibility
node_test_author -->|"finds views"| node_view_search
node_test_author -->|"asserts text"| node_text_inspection
node_test_author -->|"simulates gesture"| node_gesture_inspection

click node_inspect_api "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/InspectableView.swift"
click node_hosting "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/ViewHosting.swift"
click node_content "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/ContentExtraction.swift"
click node_inspector "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/Inspector.swift"
click node_view_tree "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/InspectableView.swift"
click node_view_search "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/ViewSearch.swift"
click node_search_index "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/ViewSearchIndex.swift"
click node_lazy_group "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/LazyGroup.swift"
click node_text_inspection "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/Text.swift"
click node_view_adaptors "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/AnyView.swift"
click node_modifier_inspection "https://github.com/nalexn/viewinspector/tree/0.10.5/Sources/ViewInspector/Modifiers"
click node_text_attributes "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/TextAttributes.swift"
click node_environment "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/EnvironmentInjection.swift"
click node_popup_inspection "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/Alert.swift"
click node_gesture_inspection "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/Gesture.swift"
click node_accessibility "https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/Modifiers/AccessibilityModifiers.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_inspect_api,node_hosting,node_content,node_inspector,node_sut toneBlue
class node_view_tree,node_view_search,node_search_index,node_lazy_group toneAmber
class node_text_inspection,node_view_adaptors,node_modifier_inspection,node_text_attributes,node_environment,node_popup_inspection toneMint
class node_gesture_inspection,node_accessibility toneRose
class node_test_author toneIndigo
```

## Components

### Inspection entry

- [Inspect entry](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/InspectableView.swift): `Sources/ViewInspector/InspectableView.swift`
- [Inspection context](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/ViewHosting.swift): `Sources/ViewInspector/ViewHosting.swift`
- [Content extraction](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/ContentExtraction.swift): `Sources/ViewInspector/ContentExtraction.swift`
- [Reflection utilities](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/Inspector.swift): `Sources/ViewInspector/Inspector.swift`

### Hierarchy and search

- [Inspectable hierarchy](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/InspectableView.swift): `Sources/ViewInspector/InspectableView.swift`
- [Find and traverse](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/ViewSearch.swift): `Sources/ViewInspector/ViewSearch.swift`
- [View type index](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/ViewSearchIndex.swift): `Sources/ViewInspector/ViewSearchIndex.swift`
- [Child collections](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/LazyGroup.swift): `Sources/ViewInspector/LazyGroup.swift`

### View inspection

- [Text inspection](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/Text.swift): `Sources/ViewInspector/SwiftUI/Text.swift`
- [SwiftUI view adapters](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/AnyView.swift): `Sources/ViewInspector/SwiftUI/AnyView.swift`
- [Modifier inspection](https://github.com/nalexn/viewinspector/tree/0.10.5/Sources/ViewInspector/Modifiers): `Sources/ViewInspector/Modifiers`
- [Text attributes](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/TextAttributes.swift): `Sources/ViewInspector/SwiftUI/TextAttributes.swift`
- [Environment injection](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/EnvironmentInjection.swift): `Sources/ViewInspector/EnvironmentInjection.swift`
- [Popup inspection](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/Alert.swift): `Sources/ViewInspector/SwiftUI/Alert.swift`

### State and interaction

- [Gesture callbacks](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/SwiftUI/Gesture.swift): `Sources/ViewInspector/SwiftUI/Gesture.swift`
- [Accessibility actions](https://github.com/nalexn/viewinspector/blob/0.10.5/Sources/ViewInspector/Modifiers/AccessibilityModifiers.swift): `Sources/ViewInspector/Modifiers/AccessibilityModifiers.swift`

### Other components

- **Test author**
- **SwiftUI view under test**

## Connections

- Test author → SwiftUI view under test: provides view
- Test author → Inspect entry: starts inspection
- Inspect entry → Inspection context: creates context
- Inspect entry → Content extraction: unwraps view
- Content extraction → Reflection utilities: reflects structure
- Inspect entry → Inspectable hierarchy: creates root
- Inspectable hierarchy → Reflection utilities: reads attributes
- Inspectable hierarchy → Find and traverse: supports search
- Find and traverse → View type index: identifies types
- Find and traverse → Child collections: traverses children
- Inspectable hierarchy → SwiftUI view adapters: adapts view types
- Inspectable hierarchy → Text inspection: reads text
- Text inspection → Text attributes: reads attributes
- Inspectable hierarchy → Modifier inspection: reads modifiers
- Inspectable hierarchy → Environment injection: reads environment
- Inspectable hierarchy → Popup inspection: inspects popup
- Inspectable hierarchy → Gesture callbacks: invokes callbacks
- Inspectable hierarchy → Accessibility actions: invokes actions
- Test author → Find and traverse: finds views
- Test author → Text inspection: asserts text
- Test author → Gesture callbacks: simulates gesture
