# alexhiguera/push_swap architecture

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

## Overview

##### Project Type and Purpose
- This isn’t a web application or a multi-tier full stack system—instead, it’s an algorithmic challenge with a clear focus on data manipulation using stacks.
- The core goal is to calculate and output a sequence of operations (like push, swap, rotate, and reverse rotate) that sort the provided list of integers.
- It depends on an external personal library (Libft_2.0) for basic functions, so be sure to include external dependency links.

##### Main Components
a. Main Executable (push_swap):
– The main entry point (src/push_swap.c) that takes the command line arguments and orchestrates the process.
– A node labeled “Input Parsing & Validation” for handling and verifying the input numbers.

b. Stack Manipulation Modules:
– Illustrate two primary logical entities: “Stack A” and “Stack B”. These should be noted as the two main data containers.
- Swap operations (implemented in swap.c)
- Push operations (push.c)
- Rotate and Reverse Rotate operations (rotate.c, reverse_rotate.c)

c. Sorting Algorithm:
– Identify the sorting module (sort.c, moves.c, move_cost.c) that contains the algorithm logic to decide which operations to perform.
– Represent how this module interacts with the stack operations.

d. Helper and Utility Functions:
– Include a module for utilities (utils.c), which likely contains common helper functions.
– Also add “position.c”, “moves.c”, “start.c”, and “stack.c” as parts that maintain and modify the internal state of the stacks.

e. External Dependency:

f. Testing Framework:
– Include a section for testing (from the tests directory). Indicate:
- The tester scripts and executables for both Mac and Linux.
- The “checker” executables (checker_Mac and checker_linux) which are used to verify the correctness of the output.
- Makefile rules (test, exec, normi) as part of the build and verification process.

##### Relationships and Data Flow
- That the “Main Executable” invokes functions from both the “Sorting Algorithm” and the “Stack Manipulation” modules.

##### Architectural Patterns and Design Principles
- Single responsibility of each source file: each file (swap, push, rotate, etc.) deals with a specific operation.
- The design shows modularity even within a procedural paradigm by isolating the algorithm logic from low-level operations.

##### Elements
– Main Executable / Input Handling (push_swap.c)
– Sorting Algorithm (sort.c, moves.c, move_cost.c)
– Stack Operations (swap.c, push.c, rotate.c, reverse_rotate.c)
– Utility Functions (utils.c, position.c, start.c, stack.c)
– Dependencies (Libft_2.0)
– Testing Components (tests/checker_Mac, tests/checker_linux, test scripts)
– The flow of control and data from input through algorithm to the stack modifications.
– The interaction between the Main Executable and Libft.
– The verification loop via the testing scripts.
- Annotations or labels that clarify:
– The role of each module.
– How the stacks (Stack A and Stack B) are managed.
– The limited set of operations as defined by the rules.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Execution
    MainExec["Main Executable & Input Handling\n(src/push_swap.c)"]:::algorithm

    %% Sorting Algorithm
    SortAlg["Sorting Algorithm\n(sort.c, moves.c, move_cost.c)"]:::algorithm

    %% Helper & Utility Functions
    Utils["Helper & Utility Functions\n(utils.c, position.c, start.c, stack.c)"]:::utility

    %% Stack Operations Subgraph
    subgraph "Stack Operations"
        direction TB
        SwapOp["Swap Operations\n(swap.c)"]:::operation
        PushOp["Push Operations\n(push.c)"]:::operation
        RotateOp["Rotate Operations\n(rotate.c)"]:::operation
        RevRotateOp["Reverse Rotate Operations\n(reverse_rotate.c)"]:::operation
    end

    %% Stacks Subgraph
    subgraph "Stacks"
        direction TB
        StackA["Stack A"]:::stack
        StackB["Stack B"]:::stack
    end

    %% External Dependency
    Libft["Libft_2.0"]:::dependency

    %% Testing Framework
    Testing["Testing Framework\n(checker_Mac, checker_linux, test scripts)"]:::testing

    %% Connections
    MainExec -->|"initiates"| SortAlg
    MainExec -->|"utilizes"| Utils
    MainExec -->|"depends_on"| Libft
    MainExec -->|"verified_by"| Testing

    SortAlg -->|"executes"| SwapOp
    SortAlg -->|"executes"| PushOp
    SortAlg -->|"executes"| RotateOp
    SortAlg -->|"executes"| RevRotateOp

    Utils -->|"uses"| Libft

    SwapOp -->|"operates_on"| StackA
    SwapOp -->|"operates_on"| StackB

    PushOp -->|"operates_on"| StackA
    PushOp -->|"operates_on"| StackB

    RotateOp -->|"operates_on"| StackA
    RotateOp -->|"operates_on"| StackB

    RevRotateOp -->|"operates_on"| StackA
    RevRotateOp -->|"operates_on"| StackB

    %% Click Events
    click MainExec "https://github.com/alexhiguera/push_swap/blob/main/src/push_swap.c"
    
    click SortAlg "https://github.com/alexhiguera/push_swap/blob/main/src/sort.c"
    click SortAlg "https://github.com/alexhiguera/push_swap/blob/main/src/moves.c"
    click SortAlg "https://github.com/alexhiguera/push_swap/blob/main/src/move_cost.c"
    
    click Utils "https://github.com/alexhiguera/push_swap/blob/main/src/utils.c"
    click Utils "https://github.com/alexhiguera/push_swap/blob/main/src/position.c"
    click Utils "https://github.com/alexhiguera/push_swap/blob/main/src/start.c"
    click Utils "https://github.com/alexhiguera/push_swap/blob/main/src/stack.c"
    
    click SwapOp "https://github.com/alexhiguera/push_swap/blob/main/src/swap.c"
    click PushOp "https://github.com/alexhiguera/push_swap/blob/main/src/push.c"
    click RotateOp "https://github.com/alexhiguera/push_swap/blob/main/src/rotate.c"
    click RevRotateOp "https://github.com/alexhiguera/push_swap/blob/main/src/reverse_rotate.c"
    
    click Libft "https://github.com/alexhiguera/push_swap/blob/main/Libft_2.0"
    
    click Testing "https://github.com/alexhiguera/push_swap/tree/main/tests"
    click Testing "https://github.com/alexhiguera/push_swap/tree/main/tests/checker_Mac"
    click Testing "https://github.com/alexhiguera/push_swap/tree/main/tests/checker_linux"
    click Testing "https://github.com/alexhiguera/push_swap/blob/main/tests/push_swap_test.sh"
    click Testing "https://github.com/alexhiguera/push_swap/blob/main/tests/tester.sh"

    %% Styles
    classDef algorithm fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef operation fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef utility fill:#D8BFD8,stroke:#000,stroke-width:2px;
    classDef dependency fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef testing fill:#FFDEAD,stroke:#000,stroke-width:2px;
    classDef stack fill:#F5F5F5,stroke:#000,stroke-width:2px;
```
