# ahmadnajikam/push_swap architecture

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

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

## Overview

Push_Swap is a command-line sorter: it validates integer arguments, builds two linked-list stacks, selects a requested or adaptive strategy, then emits allowed stack operations for an external checker to execute. The documented strategies are selection sort, chunk sort, and radix sort; adaptive behavior and benchmarking are also represented. Source excerpts establish the main routing, validation, operations, and strategy calls. The adaptive and benchmark internals are unsampled, so their detailed links are omitted.

Main entry points: [`utils/parsing.c`](https://github.com/ahmadnajikam/push_swap/blob/main/utils/parsing.c) (Stack initialization), [`operations/push_swap_ops.c`](https://github.com/ahmadnajikam/push_swap/blob/main/operations/push_swap_ops.c) (Stack operations), [`main.c`](https://github.com/ahmadnajikam/push_swap/blob/main/main.c) (Program entry), [`operations/rotate_ops.c`](https://github.com/ahmadnajikam/push_swap/blob/main/operations/rotate_ops.c) (Rotation operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and validation"]
  node_main["Program entry<br/>[main.c]"]
  node_validation["Argument validation<br/>[check_errors.c]"]
  node_mode["Mode selection<br/>[mode_handling.c]"]
  node_number_utils["Number parsing<br/>[handle_numbers.c]"]
end

subgraph group_runtime["Sorting runtime"]
  node_parser["Stack initialization<br/>[parsing.c]"]
  node_stack["Linked-list stacks<br/>[stack_utils.c]"]
  node_indices["Index preparation<br/>[general_utils.c]"]
  node_operations["Stack operations<br/>[push_swap_ops.c]"]
  node_rotations["Rotation operations<br/>[rotate_ops.c]"]
end

subgraph group_strategies["Sorting strategies"]
  node_simple["Selection strategy<br/>[simple.c]"]
  node_medium["Chunk strategy<br/>[medium.c]"]
  node_complex["Radix strategy<br/>[complex.c]"]
  node_adaptive["Adaptive strategy<br/>[adaptive.c]"]
end

subgraph group_support["Output and metrics"]
  node_metrics["Benchmark metrics<br/>[bench.c]"]
  node_diagnostics["Formatted output<br/>[ft_dprintf.c]"]
end

node_user(("CLI user"))
node_checker(("External checker"))

node_user -->|"runs"| node_main
node_main -->|"validates"| node_validation
node_validation -->|"checks flags"| node_mode
node_validation -->|"checks numbers"| node_number_utils
node_main -->|"parses arguments"| node_parser
node_parser -->|"builds stacks"| node_stack
node_parser -->|"fills indices"| node_indices
node_parser -->|"selects mode"| node_mode
node_parser -->|"dispatches"| node_simple
node_parser -->|"dispatches"| node_medium
node_parser -->|"dispatches"| node_complex
node_parser -->|"dispatches"| node_adaptive
node_simple -->|"pushes/swaps"| node_operations
node_simple -->|"rotates"| node_rotations
node_medium -->|"pushes"| node_operations
node_medium -->|"rotates"| node_rotations
node_complex -->|"pushes"| node_operations
node_complex -->|"rotates"| node_rotations
node_operations -->|"prints moves"| node_diagnostics
node_rotations -->|"prints moves"| node_diagnostics
node_parser -.->|"records benchmark"| node_metrics
node_operations -->|"emits operations"| node_checker
node_main -->|"reports errors"| node_diagnostics

click node_main "https://github.com/ahmadnajikam/push_swap/blob/main/main.c"
click node_validation "https://github.com/ahmadnajikam/push_swap/blob/main/error_handling/check_errors.c"
click node_mode "https://github.com/ahmadnajikam/push_swap/blob/main/mode/mode_handling.c"
click node_parser "https://github.com/ahmadnajikam/push_swap/blob/main/utils/parsing.c"
click node_stack "https://github.com/ahmadnajikam/push_swap/blob/main/utils/stack_utils.c"
click node_indices "https://github.com/ahmadnajikam/push_swap/blob/main/algorithms/general_utils.c"
click node_simple "https://github.com/ahmadnajikam/push_swap/blob/main/algorithms/simple/simple.c"
click node_medium "https://github.com/ahmadnajikam/push_swap/blob/main/algorithms/medium/medium.c"
click node_complex "https://github.com/ahmadnajikam/push_swap/blob/main/algorithms/complex/complex.c"
click node_adaptive "https://github.com/ahmadnajikam/push_swap/blob/main/algorithms/adaptive/adaptive.c"
click node_operations "https://github.com/ahmadnajikam/push_swap/blob/main/operations/push_swap_ops.c"
click node_rotations "https://github.com/ahmadnajikam/push_swap/blob/main/operations/rotate_ops.c"
click node_metrics "https://github.com/ahmadnajikam/push_swap/blob/main/bench/bench.c"
click node_diagnostics "https://github.com/ahmadnajikam/push_swap/blob/main/utils/ft_dprintf/ft_dprintf.c"
click node_number_utils "https://github.com/ahmadnajikam/push_swap/blob/main/utils/handle_numbers.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_main,node_validation,node_mode,node_number_utils,node_user toneBlue
class node_parser,node_stack,node_indices,node_operations,node_rotations toneAmber
class node_simple,node_medium,node_complex,node_adaptive toneMint
class node_metrics,node_diagnostics toneRose
class node_checker toneIndigo
```

## Components

### Input and validation

- [Program entry](https://github.com/ahmadnajikam/push_swap/blob/main/main.c): `main.c`
- [Argument validation](https://github.com/ahmadnajikam/push_swap/blob/main/error_handling/check_errors.c): `error_handling/check_errors.c`
- [Mode selection](https://github.com/ahmadnajikam/push_swap/blob/main/mode/mode_handling.c): `mode/mode_handling.c`
- [Number parsing](https://github.com/ahmadnajikam/push_swap/blob/main/utils/handle_numbers.c): `utils/handle_numbers.c`

### Sorting runtime

- [Stack initialization](https://github.com/ahmadnajikam/push_swap/blob/main/utils/parsing.c): `utils/parsing.c`
- [Linked-list stacks](https://github.com/ahmadnajikam/push_swap/blob/main/utils/stack_utils.c): `utils/stack_utils.c`
- [Index preparation](https://github.com/ahmadnajikam/push_swap/blob/main/algorithms/general_utils.c): `algorithms/general_utils.c`
- [Stack operations](https://github.com/ahmadnajikam/push_swap/blob/main/operations/push_swap_ops.c): `operations/push_swap_ops.c`
- [Rotation operations](https://github.com/ahmadnajikam/push_swap/blob/main/operations/rotate_ops.c): `operations/rotate_ops.c`

### Sorting strategies

- [Selection strategy](https://github.com/ahmadnajikam/push_swap/blob/main/algorithms/simple/simple.c): `algorithms/simple/simple.c`
- [Chunk strategy](https://github.com/ahmadnajikam/push_swap/blob/main/algorithms/medium/medium.c): `algorithms/medium/medium.c`
- [Radix strategy](https://github.com/ahmadnajikam/push_swap/blob/main/algorithms/complex/complex.c): `algorithms/complex/complex.c`
- [Adaptive strategy](https://github.com/ahmadnajikam/push_swap/blob/main/algorithms/adaptive/adaptive.c): `algorithms/adaptive/adaptive.c`

### Output and metrics

- [Benchmark metrics](https://github.com/ahmadnajikam/push_swap/blob/main/bench/bench.c): `bench/bench.c`
- [Formatted output](https://github.com/ahmadnajikam/push_swap/blob/main/utils/ft_dprintf/ft_dprintf.c): `utils/ft_dprintf/ft_dprintf.c`

### Other components

- **CLI user**
- **External checker**

## Connections

- CLI user → Program entry: runs (evidence: `README.md`)
- Program entry → Argument validation: validates (evidence: `main.c`)
- Argument validation → Mode selection: checks flags (evidence: `error_handling/check_errors.c`)
- Argument validation → Number parsing: checks numbers (evidence: `error_handling/check_errors.c`)
- Program entry → Stack initialization: parses arguments (evidence: `main.c`)
- Stack initialization → Linked-list stacks: builds stacks (evidence: `utils/parsing.c`)
- Stack initialization → Index preparation: fills indices (evidence: `utils/parsing.c`)
- Stack initialization → Mode selection: selects mode (evidence: `utils/parsing.c`)
- Stack initialization → Selection strategy: dispatches (evidence: `utils/parsing.c`)
- Stack initialization → Chunk strategy: dispatches (evidence: `utils/parsing.c`)
- Stack initialization → Radix strategy: dispatches (evidence: `utils/parsing.c`)
- Stack initialization → Adaptive strategy: dispatches (evidence: `utils/parsing.c`)
- Selection strategy → Stack operations: pushes/swaps (evidence: `algorithms/simple/simple.c`)
- Selection strategy → Rotation operations: rotates (evidence: `algorithms/simple/simple.c`)
- Chunk strategy → Stack operations: pushes (evidence: `algorithms/medium/medium.c`)
- Chunk strategy → Rotation operations: rotates (evidence: `algorithms/medium/medium.c`)
- Radix strategy → Stack operations: pushes (evidence: `algorithms/complex/complex.c`)
- Radix strategy → Rotation operations: rotates (evidence: `algorithms/complex/complex.c`)
- Stack operations → Formatted output: prints moves (evidence: `operations/push_swap_ops.c`)
- Rotation operations → Formatted output: prints moves (evidence: `operations/rotate_ops.c`)
- Stack initialization → Benchmark metrics: records benchmark
- Stack operations → External checker: emits operations (evidence: `README.md`)
- Program entry → Formatted output: reports errors (evidence: `main.c`)
