# edden27/dog architecture

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

- Interactive diagram: https://gitdiagram.com/edden27/dog
- Repository: https://github.com/edden27/dog

## Overview

dog is a Swift terminal file highlighter: it detects or accepts a language, parses source with tree-sitter, and renders themed output with terminal-aware presentation. The repository also contains tree-sitter’s native engine, WebAssembly binding, and bundled language grammars. The README documents the principal capabilities; where sampled source does not show the dog command’s wiring, those links are marked unverified rather than asserted as direct calls.

Main entry points: [`Sources/dog/Dog.swift`](https://github.com/edden27/dog/blob/main/Sources/dog/Dog.swift) (dog commands), [`Sources/dog/Parsing/SyntaxParser.swift`](https://github.com/edden27/dog/blob/main/Sources/dog/Parsing/SyntaxParser.swift) (Syntax parser), [`LocalPackages/tree-sitter/lib/include/tree_sitter/api.h`](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/include/tree_sitter/api.h) (Tree-sitter API), [`LocalPackages/tree-sitter/lib/binding_web/src/parser.ts`](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/parser.ts) (Web parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["dog CLI"]
  node_dog["dog commands<br/>[Dog.swift]"]
  node_detect["Language detection"]
  node_langmap["Language map<br/>[LanguageMap.swift]"]
end

subgraph group_highlight["Highlighting"]
  node_registry["Language registry"]
  node_syntax["Syntax parser<br/>[SyntaxParser.swift]"]
  node_render["Terminal renderer"]
  node_theme["Theme styling<br/>[Style.swift]"]
  node_pager["Pager output<br/>[Pager.swift]"]
end

subgraph group_engine["Tree-sitter engine"]
  node_engineapi["Tree-sitter API<br/>[api.h]"]
  node_engineparser["Native parser<br/>[parser.c]"]
  node_enginequery["Query engine<br/>[query.c]"]
  node_grammars["Language grammars<br/>[parser.c]"]
end

subgraph group_web["Web binding"]
  node_webparser["Web parser<br/>[parser.ts]"]
  node_weblanguage["Web languages<br/>[language.ts]"]
  node_webquery["Web queries<br/>[query.ts]"]
  node_webnodes["Web syntax tree<br/>[node.ts]"]
  node_marshal["WASM marshalling<br/>[marshal.ts]"]
end

node_user(("CLI user"))

node_user -.->|"invokes"| node_dog
node_dog -.->|"selects language"| node_detect
node_detect -.->|"looks up"| node_langmap
node_dog -.->|"requests parsing"| node_syntax
node_syntax -->|"resolves language"| node_registry
node_syntax -.->|"parses AST"| node_engineapi
node_dog -.->|"prints output"| node_render
node_render -.->|"applies styles"| node_theme
node_dog -.->|"pages output"| node_pager
node_engineapi -.->|"exposes parsing"| node_engineparser
node_engineapi -.->|"exposes queries"| node_enginequery
node_engineparser -.->|"uses grammar"| node_grammars
node_webparser -->|"sets language"| node_weblanguage
node_weblanguage -->|"creates queries"| node_webquery
node_webquery -->|"queries nodes"| node_webnodes
node_webparser -->|"marshals ranges"| node_marshal
node_webnodes -->|"marshals nodes"| node_marshal

click node_dog "https://github.com/edden27/dog/blob/main/Sources/dog/Dog.swift"
click node_detect "https://github.com/edden27/dog/blob/main/Sources/dog/Detection/LanguageDetector.swift"
click node_langmap "https://github.com/edden27/dog/blob/main/Sources/dog/Detection/LanguageMap.swift"
click node_registry "https://github.com/edden27/dog/blob/main/Sources/dog/Parsing/Languages/LanguageRegistry.swift"
click node_syntax "https://github.com/edden27/dog/blob/main/Sources/dog/Parsing/SyntaxParser.swift"
click node_render "https://github.com/edden27/dog/blob/main/Sources/dog/Commands/PrintCommand%2BRender.swift"
click node_theme "https://github.com/edden27/dog/blob/main/Sources/dog/Output/Style.swift"
click node_pager "https://github.com/edden27/dog/blob/main/Sources/dog/Output/Pager.swift"
click node_engineapi "https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/include/tree_sitter/api.h"
click node_engineparser "https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/src/parser.c"
click node_enginequery "https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/src/query.c"
click node_grammars "https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter-css/src/parser.c"
click node_webparser "https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/parser.ts"
click node_weblanguage "https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/language.ts"
click node_webquery "https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/query.ts"
click node_webnodes "https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/node.ts"
click node_marshal "https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/marshal.ts"

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_dog,node_detect,node_langmap,node_user toneBlue
class node_registry,node_syntax,node_render,node_theme,node_pager toneAmber
class node_engineapi,node_engineparser,node_enginequery,node_grammars toneMint
class node_webparser,node_weblanguage,node_webquery,node_webnodes,node_marshal toneRose
```

## Components

### dog CLI

- [dog commands](https://github.com/edden27/dog/blob/main/Sources/dog/Dog.swift): `Sources/dog/Dog.swift`
- [Language detection](https://github.com/edden27/dog/blob/main/Sources/dog/Detection/LanguageDetector.swift): `Sources/dog/Detection/LanguageDetector.swift`
- [Language map](https://github.com/edden27/dog/blob/main/Sources/dog/Detection/LanguageMap.swift): `Sources/dog/Detection/LanguageMap.swift`

### Highlighting

- [Language registry](https://github.com/edden27/dog/blob/main/Sources/dog/Parsing/Languages/LanguageRegistry.swift): `Sources/dog/Parsing/Languages/LanguageRegistry.swift`
- [Syntax parser](https://github.com/edden27/dog/blob/main/Sources/dog/Parsing/SyntaxParser.swift): `Sources/dog/Parsing/SyntaxParser.swift`
- [Terminal renderer](https://github.com/edden27/dog/blob/main/Sources/dog/Commands/PrintCommand%2BRender.swift): `Sources/dog/Commands/PrintCommand+Render.swift`
- [Theme styling](https://github.com/edden27/dog/blob/main/Sources/dog/Output/Style.swift): `Sources/dog/Output/Style.swift`
- [Pager output](https://github.com/edden27/dog/blob/main/Sources/dog/Output/Pager.swift): `Sources/dog/Output/Pager.swift`

### Tree-sitter engine

- [Tree-sitter API](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/include/tree_sitter/api.h): `LocalPackages/tree-sitter/lib/include/tree_sitter/api.h`
- [Native parser](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/src/parser.c): `LocalPackages/tree-sitter/lib/src/parser.c`
- [Query engine](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/src/query.c): `LocalPackages/tree-sitter/lib/src/query.c`
- [Language grammars](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter-css/src/parser.c): `LocalPackages/tree-sitter-css/src/parser.c`

### Web binding

- [Web parser](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/parser.ts): `LocalPackages/tree-sitter/lib/binding_web/src/parser.ts`
- [Web languages](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/language.ts): `LocalPackages/tree-sitter/lib/binding_web/src/language.ts`
- [Web queries](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/query.ts): `LocalPackages/tree-sitter/lib/binding_web/src/query.ts`
- [Web syntax tree](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/node.ts): `LocalPackages/tree-sitter/lib/binding_web/src/node.ts`
- [WASM marshalling](https://github.com/edden27/dog/blob/main/LocalPackages/tree-sitter/lib/binding_web/src/marshal.ts): `LocalPackages/tree-sitter/lib/binding_web/src/marshal.ts`

### Other components

- **CLI user**

## Connections

- CLI user → dog commands: invokes
- dog commands → Language detection: selects language
- Language detection → Language map: looks up
- dog commands → Syntax parser: requests parsing
- Syntax parser → Language registry: resolves language (evidence: `Sources/dog/Parsing/SyntaxParser.swift`)
- Syntax parser → Tree-sitter API: parses AST (evidence: `README.md`)
- dog commands → Terminal renderer: prints output
- Terminal renderer → Theme styling: applies styles
- dog commands → Pager output: pages output (evidence: `README.md`)
- Tree-sitter API → Native parser: exposes parsing
- Tree-sitter API → Query engine: exposes queries (evidence: `LocalPackages/tree-sitter/lib/src/query.c`)
- Native parser → Language grammars: uses grammar
- Web parser → Web languages: sets language (evidence: `LocalPackages/tree-sitter/lib/binding_web/src/parser.ts`)
- Web languages → Web queries: creates queries (evidence: `LocalPackages/tree-sitter/lib/binding_web/src/language.ts`)
- Web queries → Web syntax tree: queries nodes (evidence: `LocalPackages/tree-sitter/lib/binding_web/src/query.ts`)
- Web parser → WASM marshalling: marshals ranges (evidence: `LocalPackages/tree-sitter/lib/binding_web/src/parser.ts`)
- Web syntax tree → WASM marshalling: marshals nodes (evidence: `LocalPackages/tree-sitter/lib/binding_web/src/node.ts`)
