# uncodem/sorters architecture

> Architecture diagram of the GitHub repository uncodem/sorters, 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/uncodem/sorters
- Repository: https://github.com/uncodem/sorters

## Overview

Sorters is a C++/SFML sorting visualizer. A command-line user supplies the algorithm, element count, update speed, and sort direction; the application creates the array and window, runs the selected sort on a worker thread, and displays sorting operations as animated bars. The array reports mutations and comparisons through an observer interface; the window queues these events and applies them while rendering. The README is brief, so algorithm and display capabilities are grounded in the sampled source; no other product branches are documented.

Main entry points: [`src/main.cpp`](https://github.com/uncodem/sorters/blob/master/src/main.cpp) (CLI and runner), [`src/window.cpp`](https://github.com/uncodem/sorters/blob/master/src/window.cpp) (SFML visualizer), [`src/array.cpp`](https://github.com/uncodem/sorters/blob/master/src/array.cpp) (Sortable array), [`src/sorters.cpp`](https://github.com/uncodem/sorters/blob/master/src/sorters.cpp) (Sorting algorithms)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_main["CLI and runner<br/>[main.cpp]"]
  node_interrupt["Sort interrupt<br/>[closer.hpp]"]
end

subgraph group_sort["Sorting"]
  node_array["Sortable array<br/>[array.cpp]"]
  node_sorters["Sorting algorithms<br/>[sorters.cpp]"]
  node_sorter_api["Sorter interface<br/>[sorter.hpp]"]
end

subgraph group_visual["Visualization"]
  node_observer_api["Observer interface<br/>[observer.hpp]"]
  node_window["SFML visualizer<br/>[window.cpp]"]
  node_default_observer["Console observer"]
end

node_user(("CLI user"))
node_sfml["SFML graphics"]

node_user -->|"provides arguments"| node_main
node_main -->|"selects algorithm"| node_sorters
node_main -->|"creates data"| node_array
node_main -->|"creates window"| node_window
node_main -->|"registers observer"| node_array
node_main -->|"starts sorting"| node_sorters
node_sorters -->|"compares and mutates"| node_array
node_array -->|"dispatches events"| node_observer_api
node_window -->|"implements callbacks"| node_observer_api
node_default_observer -->|"implements callbacks"| node_observer_api
node_window -->|"copies initial data"| node_array
node_window -->|"renders bars"| node_sfml
node_window -->|"throws on exit"| node_interrupt
node_main -->|"catches interruption"| node_interrupt

click node_main "https://github.com/uncodem/sorters/blob/master/src/main.cpp"
click node_interrupt "https://github.com/uncodem/sorters/blob/master/src/closer.hpp"
click node_array "https://github.com/uncodem/sorters/blob/master/src/array.cpp"
click node_sorters "https://github.com/uncodem/sorters/blob/master/src/sorters.cpp"
click node_sorter_api "https://github.com/uncodem/sorters/blob/master/src/sorter.hpp"
click node_observer_api "https://github.com/uncodem/sorters/blob/master/src/observer.hpp"
click node_window "https://github.com/uncodem/sorters/blob/master/src/window.cpp"
click node_default_observer "https://github.com/uncodem/sorters/blob/master/src/default_observer.cpp"

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_main,node_interrupt,node_user toneBlue
class node_array,node_sorters,node_sorter_api toneAmber
class node_observer_api,node_window,node_default_observer toneMint
class node_sfml toneIndigo
```

## Components

### Application

- [CLI and runner](https://github.com/uncodem/sorters/blob/master/src/main.cpp): `src/main.cpp`
- [Sort interrupt](https://github.com/uncodem/sorters/blob/master/src/closer.hpp): `src/closer.hpp`

### Sorting

- [Sortable array](https://github.com/uncodem/sorters/blob/master/src/array.cpp): `src/array.cpp`
- [Sorting algorithms](https://github.com/uncodem/sorters/blob/master/src/sorters.cpp): `src/sorters.cpp`
- [Sorter interface](https://github.com/uncodem/sorters/blob/master/src/sorter.hpp): `src/sorter.hpp`

### Visualization

- [Observer interface](https://github.com/uncodem/sorters/blob/master/src/observer.hpp): `src/observer.hpp`
- [SFML visualizer](https://github.com/uncodem/sorters/blob/master/src/window.cpp): `src/window.cpp`
- [Console observer](https://github.com/uncodem/sorters/blob/master/src/default_observer.cpp): `src/default_observer.cpp`

### Other components

- **CLI user**
- **SFML graphics**

## Connections

- CLI user → CLI and runner: provides arguments (evidence: `src/main.cpp`)
- CLI and runner → Sorting algorithms: selects algorithm (evidence: `src/main.cpp`)
- CLI and runner → Sortable array: creates data (evidence: `src/main.cpp`)
- CLI and runner → SFML visualizer: creates window (evidence: `src/main.cpp`)
- CLI and runner → Sortable array: registers observer (evidence: `src/main.cpp`)
- CLI and runner → Sorting algorithms: starts sorting (evidence: `src/main.cpp`)
- Sorting algorithms → Sortable array: compares and mutates (evidence: `src/sorters.cpp`)
- Sortable array → Observer interface: dispatches events (evidence: `src/array.cpp`)
- SFML visualizer → Observer interface: implements callbacks
- Console observer → Observer interface: implements callbacks
- SFML visualizer → Sortable array: copies initial data (evidence: `src/window.cpp`)
- SFML visualizer → SFML graphics: renders bars (evidence: `src/window.cpp`)
- SFML visualizer → Sort interrupt: throws on exit (evidence: `src/window.cpp`)
- CLI and runner → Sort interrupt: catches interruption (evidence: `src/main.cpp`)
