# sanishpoudel/binary-search-trees architecture

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

- Interactive diagram: https://gitdiagram.com/sanishpoudel/binary-search-trees
- Repository: https://github.com/sanishpoudel/binary-search-trees

## Overview

This repository is a small JavaScript binary-search-tree implementation. Its core workflow builds a tree from values, supports ordered lookup and mutation, and exposes traversals and structural queries; rebalancing rebuilds from a traversal. The only source file also contains a pretty-printer and a small top-level demonstration. No separate application, persistence layer, or external integration is documented.

Main entry points: [`bst.js`](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js) (Rebalance tree)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_tree_core["Tree operations"]
  node_tree["Binary search tree<br/>[bst.js]"]
  node_node["Tree node<br/>[bst.js]"]
  node_build["Build tree<br/>[bst.js]"]
  node_search["Search values<br/>[bst.js]"]
  node_mutate["Insert and delete<br/>[bst.js]"]
  node_balance["Balance checks<br/>[bst.js]"]
  node_rebalance["Rebalance tree<br/>[bst.js]"]
end

subgraph group_tree_views["Traversal and display"]
  node_traverse["Tree traversals<br/>[bst.js]"]
  node_metrics["Height and depth<br/>[bst.js]"]
  node_pretty["Pretty printer<br/>[bst.js]"]
end

node_developer(("Library user"))
node_callback(("Traversal callback"))

node_developer -->|"provides values"| node_build
node_build -->|"creates nodes"| node_node
node_developer -->|"queries values"| node_search
node_developer -->|"changes values"| node_mutate
node_developer -->|"checks balance"| node_balance
node_developer -->|"requests rebuild"| node_rebalance
node_rebalance -->|"collects values"| node_traverse
node_rebalance -->|"rebuilds tree"| node_build
node_developer -->|"requests traversal"| node_traverse
node_traverse -->|"invokes callback"| node_callback
node_developer -->|"requests metrics"| node_metrics
node_developer -->|"prints tree"| node_pretty
node_pretty -->|"reads children"| node_node

click node_tree "https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js"
click node_node "https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js"
click node_build "https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js"
click node_search "https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js"
click node_mutate "https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js"
click node_balance "https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js"
click node_rebalance "https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js"
click node_traverse "https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js"
click node_metrics "https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js"
click node_pretty "https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js"

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_tree,node_node,node_build,node_search,node_mutate,node_balance,node_rebalance,node_developer toneBlue
class node_traverse,node_metrics,node_pretty toneAmber
class node_callback toneIndigo
```

## Components

### Tree operations

- [Binary search tree](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js): `bst.js`
- [Tree node](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js): `bst.js`
- [Build tree](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js): `bst.js`
- [Search values](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js): `bst.js`
- [Insert and delete](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js): `bst.js`
- [Balance checks](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js): `bst.js`
- [Rebalance tree](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js): `bst.js`

### Traversal and display

- [Tree traversals](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js): `bst.js`
- [Height and depth](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js): `bst.js`
- [Pretty printer](https://github.com/sanishpoudel/binary-search-trees/blob/main/bst.js): `bst.js`

### Other components

- **Library user**
- **Traversal callback**

## Connections

- Library user → Build tree: provides values (evidence: `bst.js`)
- Build tree → Tree node: creates nodes (evidence: `bst.js`)
- Library user → Search values: queries values (evidence: `bst.js`)
- Library user → Insert and delete: changes values (evidence: `bst.js`)
- Library user → Balance checks: checks balance (evidence: `bst.js`)
- Library user → Rebalance tree: requests rebuild (evidence: `bst.js`)
- Rebalance tree → Tree traversals: collects values (evidence: `bst.js`)
- Rebalance tree → Build tree: rebuilds tree (evidence: `bst.js`)
- Library user → Tree traversals: requests traversal (evidence: `bst.js`)
- Tree traversals → Traversal callback: invokes callback (evidence: `bst.js`)
- Library user → Height and depth: requests metrics (evidence: `bst.js`)
- Library user → Pretty printer: prints tree (evidence: `bst.js`)
- Pretty printer → Tree node: reads children (evidence: `bst.js`)
