# rodcabral/sort architecture

> Architecture diagram of the GitHub repository rodcabral/sort, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rodcabral/sort
- Repository: https://github.com/rodcabral/sort

## Overview

##### Main components
- Main Application: Represented by main.c. This is the entry point and control hub of the program.
- Sorting Module: Implemented in sort.h and src/sort.c. This module contains all the logic for implementing the different sorting algorithms (Merge Sort, Bubble Sort, Selection Sort, and Insertion Sort).
- Visualization Module: Provided by visualizer.h and src/visualizer.c. This module interacts with the SDL2 libraries to render the visualization of the sorting process.
- Assets & Resources: Represented by the assets folder (and fonts folder for font files). These contain images (e.g., the example.png) and other resources needed for the visualization.
- External Dependencies: SDL2 and SDL2_ttf libraries, which are critical for rendering and handling text.

##### Relationships and interactions
- The Main Application initializes the program, sets up the necessary SDL2 components, and orchestrates the flow.
- The Sorting Module encapsulates the logic of the algorithms. The main application calls functions in this module to perform sorting while generating intermediate states or steps.
- The Visualization Module relies on SDL2 for creating windows, rendering text, and displaying graphics. It takes the states provided by the sorting module and visualizes them on the screen.
- The assets (images and fonts) serve as auxiliary resources that the visualizer loads and displays.
- The Makefile and build scripts facilitate compiling the source code and linking with the necessary libraries.

##### Architectural patterns/design principles
- Modularity: The separation between sorting and visualization code encourages a modular structure – each module is focused on a specific responsibility.
- Layering: Think of it as a two-layered approach, where the lower layer contains the sorting computations and the upper layer deals with presentation and user interaction.
- Dependency inversion: The main module coordinates between the independent sorting and visualization modules.
- Abstraction: The use of header (.h) and source files helps encapsulate the functionalities for sorting and visualization, making the code easier to maintain and extend.

- Main Application to the Sorting Module (to trigger and retrieve sorting data).
- Main Application to the Visualization Module (to display the sorting process).
- External Dependencies (SDL2 and SDL2_ttf) in a separate area. Connect these dependencies with a line to the Visualization Module to denote external library usage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Modules
    MainApp["Main Application"]:::core
    Sorting["Sorting Algorithms (Merge,Bubble,Selection,Insertion)"]:::core
    Visualizer["Visualization Module"]:::core

    %% Resources
    Assets["Assets & Resources"]:::resource
    Fonts["Fonts"]:::resource

    %% External Dependencies
    SDL2["SDL2 Library"]:::external
    SDL2TTF["SDL2_ttf Library"]:::external

    %% Interactions
    MainApp -->|"calls"| Sorting
    MainApp -->|"initializes"| Visualizer
    Sorting -->|"providesData"| Visualizer
    Visualizer -->|"loads"| Assets
    Visualizer -->|"loads"| Fonts
    Visualizer -->|"uses"| SDL2
    Visualizer -->|"uses"| SDL2TTF

    %% Click Events for Core Modules
    click MainApp "https://github.com/rodcabral/sort/blob/master/main.c"
    click Sorting "https://github.com/rodcabral/sort/blob/master/include/sort.h"
    click Sorting "https://github.com/rodcabral/sort/blob/master/src/sort.c"
    click Visualizer "https://github.com/rodcabral/sort/blob/master/include/visualizer.h"
    click Visualizer "https://github.com/rodcabral/sort/blob/master/src/visualizer.c"

    %% Click Events for Resources
    click Assets "https://github.com/rodcabral/sort/tree/master/assets"
    click Fonts "https://github.com/rodcabral/sort/blob/master/fonts/montserrat-regular.otf"

    %% Styles
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef resource fill:#ABEBC6,stroke:#196F3D,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
