# rgrmra/push_swap architecture

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

- Interactive diagram: https://gitdiagram.com/rgrmra/push_swap
- Repository: https://github.com/rgrmra/push_swap

## Overview

This repository implements push_swap: it reads integer arguments, represents them in two linked-list stacks, emits limited stack operations to sort them, and provides a bonus checker that applies supplied operations and reports whether the result is sorted. The README describes a recursive pivot-based strategy, while the sampled handler shows partitioning and recursive small-range handling. The bonus entry point and operation dispatch are visible in excerpts; several mandatory setup and utility implementations are only indexed, so their internal call relationships are omitted or rely on README-level workflow evidence.

Main entry points: [`srcs/handler.c`](https://github.com/rgrmra/push_swap/blob/master/srcs/handler.c) (Recursive handlers), [`srcs/handler_three_a.c`](https://github.com/rgrmra/push_swap/blob/master/srcs/handler_three_a.c) (Three-item A), [`srcs/handler_three_b.c`](https://github.com/rgrmra/push_swap/blob/master/srcs/handler_three_b.c) (Three-item B), [`srcs/bonus/push_swap_bonus.c`](https://github.com/rgrmra/push_swap/blob/master/srcs/bonus/push_swap_bonus.c) (Checker entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and state"]
  node_mandatory_main["Sorter entry<br/>[push_swap.c]"]
  node_mandatory_utils["Input utilities<br/>[push_swap_utils.c]"]
  node_mandatory_errors["Error handling<br/>[error.c]"]
  node_stack_state["Stack state<br/>[nodes.c]"]
end

subgraph group_sorting["Sorting strategy"]
  node_large_sort["Pivot partitioning<br/>[stack_a.c]"]
  node_small_sort["Recursive handlers<br/>[handler.c]"]
  node_three_a["Three-item A<br/>[handler_three_a.c]"]
  node_three_b["Three-item B<br/>[handler_three_b.c]"]
  node_fixed_sort["Small-stack sorts<br/>[sorting.c]"]
end

subgraph group_operations["Stack operations"]
  node_op_swap["Swap operations<br/>[swap.c]"]
  node_op_push["Push operations<br/>[push.c]"]
  node_op_rotate["Rotate operations<br/>[rotate.c]"]
  node_op_reverse["Reverse rotations<br/>[reverse.c]"]
end

subgraph group_checker["Bonus checker"]
  node_bonus_main["Checker entry<br/>[push_swap_bonus.c]"]
  node_bonus_dispatch["Move dispatcher<br/>[sorting_bonus.c]"]
  node_bonus_ops["Checker operations"]
  node_bonus_errors["Checker errors<br/>[error_bonus.c]"]
  node_bonus_utils["Checker utilities"]
end

node_user(("CLI user"))

node_user -->|"provides numbers"| node_mandatory_main
node_mandatory_main -.->|"sorts stacks"| node_large_sort
node_mandatory_main -.->|"uses setup"| node_mandatory_utils
node_large_sort -->|"handles small ranges"| node_small_sort
node_small_sort -->|"handles A triples"| node_three_a
node_small_sort -->|"handles B triples"| node_three_b
node_small_sort -->|"swaps"| node_op_swap
node_small_sort -->|"pushes"| node_op_push
node_small_sort -->|"rotates"| node_op_rotate
node_small_sort -->|"reverses"| node_op_reverse
node_three_a -->|"sorts triples"| node_fixed_sort
node_three_a -->|"swaps"| node_op_swap
node_three_a -->|"rotates"| node_op_rotate
node_three_a -->|"reverses"| node_op_reverse
node_three_b -->|"pushes to A"| node_op_push
node_three_b -->|"swaps"| node_op_swap
node_three_b -->|"rotates"| node_op_rotate
node_three_b -->|"reverses"| node_op_reverse
node_user -->|"provides numbers and moves"| node_bonus_main
node_bonus_main -->|"dispatches moves"| node_bonus_dispatch
node_bonus_dispatch -->|"applies operations"| node_bonus_ops
node_bonus_main -->|"rejects invalid input"| node_bonus_errors
node_bonus_main -->|"reads moves"| node_bonus_utils
node_bonus_dispatch -->|"reports sorted status"| node_user

click node_mandatory_main "https://github.com/rgrmra/push_swap/blob/master/srcs/push_swap.c"
click node_mandatory_utils "https://github.com/rgrmra/push_swap/blob/master/srcs/push_swap_utils.c"
click node_mandatory_errors "https://github.com/rgrmra/push_swap/blob/master/srcs/error.c"
click node_stack_state "https://github.com/rgrmra/push_swap/blob/master/srcs/nodes.c"
click node_large_sort "https://github.com/rgrmra/push_swap/blob/master/srcs/stack_a.c"
click node_small_sort "https://github.com/rgrmra/push_swap/blob/master/srcs/handler.c"
click node_three_a "https://github.com/rgrmra/push_swap/blob/master/srcs/handler_three_a.c"
click node_three_b "https://github.com/rgrmra/push_swap/blob/master/srcs/handler_three_b.c"
click node_fixed_sort "https://github.com/rgrmra/push_swap/blob/master/srcs/sorting.c"
click node_op_swap "https://github.com/rgrmra/push_swap/blob/master/srcs/swap.c"
click node_op_push "https://github.com/rgrmra/push_swap/blob/master/srcs/push.c"
click node_op_rotate "https://github.com/rgrmra/push_swap/blob/master/srcs/rotate.c"
click node_op_reverse "https://github.com/rgrmra/push_swap/blob/master/srcs/reverse.c"
click node_bonus_main "https://github.com/rgrmra/push_swap/blob/master/srcs/bonus/push_swap_bonus.c"
click node_bonus_dispatch "https://github.com/rgrmra/push_swap/blob/master/srcs/bonus/sorting_bonus.c"
click node_bonus_ops "https://github.com/rgrmra/push_swap/tree/master/srcs/bonus"
click node_bonus_errors "https://github.com/rgrmra/push_swap/blob/master/srcs/bonus/error_bonus.c"
click node_bonus_utils "https://github.com/rgrmra/push_swap/blob/master/srcs/bonus/push_swap_utils_bonus.c"

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_mandatory_main,node_mandatory_utils,node_mandatory_errors,node_stack_state,node_user toneBlue
class node_large_sort,node_small_sort,node_three_a,node_three_b,node_fixed_sort toneAmber
class node_op_swap,node_op_push,node_op_rotate,node_op_reverse toneMint
class node_bonus_main,node_bonus_dispatch,node_bonus_ops,node_bonus_errors,node_bonus_utils toneRose
```

## Components

### Input and state

- [Sorter entry](https://github.com/rgrmra/push_swap/blob/master/srcs/push_swap.c): `srcs/push_swap.c`
- [Input utilities](https://github.com/rgrmra/push_swap/blob/master/srcs/push_swap_utils.c): `srcs/push_swap_utils.c`
- [Error handling](https://github.com/rgrmra/push_swap/blob/master/srcs/error.c): `srcs/error.c`
- [Stack state](https://github.com/rgrmra/push_swap/blob/master/srcs/nodes.c): `srcs/nodes.c`

### Sorting strategy

- [Pivot partitioning](https://github.com/rgrmra/push_swap/blob/master/srcs/stack_a.c): `srcs/stack_a.c`
- [Recursive handlers](https://github.com/rgrmra/push_swap/blob/master/srcs/handler.c): `srcs/handler.c`
- [Three-item A](https://github.com/rgrmra/push_swap/blob/master/srcs/handler_three_a.c): `srcs/handler_three_a.c`
- [Three-item B](https://github.com/rgrmra/push_swap/blob/master/srcs/handler_three_b.c): `srcs/handler_three_b.c`
- [Small-stack sorts](https://github.com/rgrmra/push_swap/blob/master/srcs/sorting.c): `srcs/sorting.c`

### Stack operations

- [Swap operations](https://github.com/rgrmra/push_swap/blob/master/srcs/swap.c): `srcs/swap.c`
- [Push operations](https://github.com/rgrmra/push_swap/blob/master/srcs/push.c): `srcs/push.c`
- [Rotate operations](https://github.com/rgrmra/push_swap/blob/master/srcs/rotate.c): `srcs/rotate.c`
- [Reverse rotations](https://github.com/rgrmra/push_swap/blob/master/srcs/reverse.c): `srcs/reverse.c`

### Bonus checker

- [Checker entry](https://github.com/rgrmra/push_swap/blob/master/srcs/bonus/push_swap_bonus.c): `srcs/bonus/push_swap_bonus.c`
- [Move dispatcher](https://github.com/rgrmra/push_swap/blob/master/srcs/bonus/sorting_bonus.c): `srcs/bonus/sorting_bonus.c`
- [Checker operations](https://github.com/rgrmra/push_swap/tree/master/srcs/bonus): `srcs/bonus`
- [Checker errors](https://github.com/rgrmra/push_swap/blob/master/srcs/bonus/error_bonus.c): `srcs/bonus/error_bonus.c`
- [Checker utilities](https://github.com/rgrmra/push_swap/blob/master/srcs/bonus/push_swap_utils_bonus.c): `srcs/bonus/push_swap_utils_bonus.c`

### Other components

- **CLI user**

## Connections

- CLI user → Sorter entry: provides numbers (evidence: `README.md`)
- Sorter entry → Pivot partitioning: sorts stacks
- Sorter entry → Input utilities: uses setup
- Pivot partitioning → Recursive handlers: handles small ranges (evidence: `srcs/stack_a.c`)
- Recursive handlers → Three-item A: handles A triples (evidence: `srcs/handler.c`)
- Recursive handlers → Three-item B: handles B triples (evidence: `srcs/handler.c`)
- Recursive handlers → Swap operations: swaps (evidence: `srcs/handler.c`)
- Recursive handlers → Push operations: pushes (evidence: `srcs/handler.c`)
- Recursive handlers → Rotate operations: rotates (evidence: `srcs/handler.c`)
- Recursive handlers → Reverse rotations: reverses (evidence: `srcs/handler.c`)
- Three-item A → Small-stack sorts: sorts triples (evidence: `srcs/handler_three_a.c`)
- Three-item A → Swap operations: swaps (evidence: `srcs/handler_three_a.c`)
- Three-item A → Rotate operations: rotates (evidence: `srcs/handler_three_a.c`)
- Three-item A → Reverse rotations: reverses (evidence: `srcs/handler_three_a.c`)
- Three-item B → Push operations: pushes to A (evidence: `srcs/handler_three_b.c`)
- Three-item B → Swap operations: swaps (evidence: `srcs/handler_three_b.c`)
- Three-item B → Rotate operations: rotates (evidence: `srcs/handler_three_b.c`)
- Three-item B → Reverse rotations: reverses (evidence: `srcs/handler_three_b.c`)
- CLI user → Checker entry: provides numbers and moves (evidence: `README.md`)
- Checker entry → Move dispatcher: dispatches moves (evidence: `srcs/bonus/push_swap_bonus.c`)
- Move dispatcher → Checker operations: applies operations (evidence: `srcs/bonus/sorting_bonus.c`)
- Checker entry → Checker errors: rejects invalid input (evidence: `srcs/bonus/push_swap_bonus.c`)
- Checker entry → Checker utilities: reads moves (evidence: `srcs/bonus/push_swap_bonus.c`)
- Move dispatcher → CLI user: reports sorted status (evidence: `srcs/bonus/sorting_bonus.c`)
