# oliveiradsmatheus/kd_tree architecture

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

- Interactive diagram: https://gitdiagram.com/oliveiradsmatheus/kd_tree
- Repository: https://github.com/oliveiradsmatheus/kd_tree

## Overview

This is a terminal-based coordinate search demo using a KD-tree. Its user-to-result workflow generates points and a query, builds and displays the tree, draws a coordinate plane, searches for points within the query radius, and displays matches. The implementation separates KD-tree operations and visualization, sparse-matrix screen tracking, frame drawing, and two stack helpers. The README documents random point generation, radius search, sparse-matrix overlap control, and a Conio2-style interface. Edges reflect calls shown in the excerpts; unsampled behavior is not inferred.

Main entry points: [`BuscaCoordenadas.c`](https://github.com/oliveiradsmatheus/kd_tree/blob/main/BuscaCoordenadas.c) (Workflow driver), [`Headers/KDTree.h`](https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/KDTree.h) (KD-tree operations), [`Headers/Moldura.h`](https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/Moldura.h) (Frame drawing), [`Headers/conio_linux.h`](https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/conio_linux.h) (Terminal compatibility)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Search workflow"]
  node_app["Workflow driver<br/>[BuscaCoordenadas.c]"]
  node_kd["KD-tree operations<br/>[KDTree.h]"]
end

subgraph group_display["Terminal display"]
  node_frame["Frame drawing<br/>[Moldura.h]"]
  node_conio["Terminal compatibility<br/>[conio_linux.h]"]
end

subgraph group_support["Data structures"]
  node_sparse["Sparse screen matrix<br/>[MatEsp.h]"]
  node_node_stack["Node stack<br/>[Pilha.h]"]
  node_int_stack["Integer stack<br/>[PilhaInt.h]"]
end

node_user(("User"))

node_user -->|"starts"| node_app
node_app -->|"generates, builds, searches"| node_kd
node_app -->|"uses"| node_node_stack
node_app -->|"uses"| node_int_stack
node_app -->|"draws interface"| node_frame
node_app -->|"initializes terminal"| node_conio
node_kd -->|"tracks screen overlaps"| node_sparse
node_kd -->|"draws frames"| node_frame
node_kd -->|"renders coordinates"| node_conio

click node_app "https://github.com/oliveiradsmatheus/kd_tree/blob/main/BuscaCoordenadas.c"
click node_kd "https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/KDTree.h"
click node_sparse "https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/MatEsp.h"
click node_frame "https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/Moldura.h"
click node_conio "https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/conio_linux.h"
click node_node_stack "https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/Pilha.h"
click node_int_stack "https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/PilhaInt.h"

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_app,node_kd,node_user toneBlue
class node_frame,node_conio toneAmber
class node_sparse,node_node_stack,node_int_stack toneMint
```

## Components

### Search workflow

- [Workflow driver](https://github.com/oliveiradsmatheus/kd_tree/blob/main/BuscaCoordenadas.c): `BuscaCoordenadas.c`
- [KD-tree operations](https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/KDTree.h): `Headers/KDTree.h`

### Terminal display

- [Frame drawing](https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/Moldura.h): `Headers/Moldura.h`
- [Terminal compatibility](https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/conio_linux.h): `Headers/conio_linux.h`

### Data structures

- [Sparse screen matrix](https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/MatEsp.h): `Headers/MatEsp.h`
- [Node stack](https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/Pilha.h): `Headers/Pilha.h`
- [Integer stack](https://github.com/oliveiradsmatheus/kd_tree/blob/main/Headers/PilhaInt.h): `Headers/PilhaInt.h`

### Other components

- **User**

## Connections

- User → Workflow driver: starts (evidence: `README.md`)
- Workflow driver → KD-tree operations: generates, builds, searches (evidence: `BuscaCoordenadas.c`)
- Workflow driver → Node stack: uses (evidence: `BuscaCoordenadas.c`)
- Workflow driver → Integer stack: uses (evidence: `BuscaCoordenadas.c`)
- Workflow driver → Frame drawing: draws interface (evidence: `BuscaCoordenadas.c`)
- Workflow driver → Terminal compatibility: initializes terminal (evidence: `BuscaCoordenadas.c`)
- KD-tree operations → Sparse screen matrix: tracks screen overlaps (evidence: `Headers/KDTree.h`)
- KD-tree operations → Frame drawing: draws frames (evidence: `Headers/KDTree.h`)
- KD-tree operations → Terminal compatibility: renders coordinates (evidence: `Headers/KDTree.h`)
