# zerrikhalid/push_swap architecture

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

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

## Overview

##### Project type and purpose
- Push_swap is a command-line, algorithmic sorting tool written in C.
- It actually consists of two programs:
- push_swap: computes and prints a minimal sequence of stack instructions to sort a list of integers.
- checker: reads a sequence of stack instructions from standard input, applies them to its own copy of the stacks, and reports OK/KO.

##### File structure
- Top-level files and directories:
- Makefile, README.md, push_swap.h (project config and header)
- algo/ — sorting-algorithm implementations (algo1.c, algo2.c, etc.)
- get_next_line/ — minimal I/O helper for checker reading instructions
- instruction/ — implementations of the primitive stack operations (sa, sb, pa, pb, …)
- parsing/ & parsing_bonus/ — argument parsing, validation, indexing, string utilities
- lst_*.c — singly linked-list utilities (add, last, size)
- main.c & mainC.c — entry points for push_swap and checker
- Patterns: functional decomposition by concern (parsing, data structures, algorithm, I/O, instructions).

##### README for additional insights
- Describes the two executables, their roles, and constraints (allowed functions, compile flags).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Executables"
        PS["push_swap CLI"]:::frontend
        CK["checker CLI"]:::frontend
    end

    ParserStd["Argument Parser (parsing/)"]:::parser
    ParserBonus["Argument Parser Bonus (parsing_bonus/)"]:::parser
    DataModel["Stack Data Model (lst_*.c)"]:::datamodel
    AlgEngine["Algorithm Engine (algo/)"]:::algorithm
    InstrExec["Instruction Executor (instruction/)"]:::instruction
    IOModule["I/O Module (get_next_line/)"]:::io
    Compare["Result Comparator"]:::algorithm
    Stdout["stdout (print operations/result)"]:::io
    Config["Config & Header (Makefile, README.md, push_swap.h)"]:::config

    PS -->|parse args| ParserStd
    CK -->|parse args| ParserStd

    ParserStd -->|init stacks| DataModel

    PS -->|generate flow| DataModel
    DataModel -->|provide stacks| AlgEngine
    AlgEngine -->|generate instructions| InstrExec
    InstrExec -->|exec on stacks| Stdout

    CK -->|validation flow| DataModel
    IOModule -->|read instructions| InstrExec
    InstrExec -->|apply ops| DataModel
    DataModel -->|check sorted| Compare
    Compare -->|OK/KO| Stdout

    Config --> ParserStd
    Config --> ParserBonus
    Config --> DataModel
    Config --> AlgEngine
    Config --> InstrExec
    Config --> IOModule

    click PS "https://github.com/zerrikhalid/push_swap/blob/master/main.c"
    click CK "https://github.com/zerrikhalid/push_swap/blob/master/mainC.c"
    click ParserStd "https://github.com/zerrikhalid/push_swap/tree/master/parsing/"
    click ParserBonus "https://github.com/zerrikhalid/push_swap/tree/master/parsing_bonus/"
    click DataModel "https://github.com/zerrikhalid/push_swap/blob/master/lst_add_back.c"
    click AlgEngine "https://github.com/zerrikhalid/push_swap/tree/master/algo/"
    click InstrExec "https://github.com/zerrikhalid/push_swap/tree/master/instruction/"
    click IOModule "https://github.com/zerrikhalid/push_swap/tree/master/get_next_line/"
    click Config "https://github.com/zerrikhalid/push_swap/blob/master/push_swap.h"

    classDef frontend fill:#ffe0b3,stroke:#333,stroke-width:1px
    classDef parser fill:#b3d9ff,stroke:#333,stroke-width:1px
    classDef algorithm fill:#b3ffb3,stroke:#333,stroke-width:1px
    classDef datamodel fill:#ffcc80,stroke:#333,stroke-width:1px
    classDef instruction fill:#ffff80,stroke:#333,stroke-width:1px
    classDef io fill:#c2f0c2,stroke:#333,stroke-width:1px
    classDef config fill:#e0e0e0,stroke:#333,stroke-width:1px
```
