# biostumpf/42_common_core architecture

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

- Interactive diagram: https://gitdiagram.com/biostumpf/42_common_core
- Repository: https://github.com/biostumpf/42_common_core

## Overview

1. This repository is a 42 Common Core monorepo, but it is not one integrated application. It contains several independent C projects, each with its own `Makefile`, entry point, and build artifacts. For architecture purposes, treat each top-level project directory as a separate executable or library boundary.

2. The shared foundation is `libft` (and in some projects, local copies of it). This is a custom utility library providing string, memory, list, and conversion helpers, plus some project-specific extras such as `printf` and `get_next_line` variants in certain subfolders. It is a supporting layer rather than a central runtime service.

3. `get_next_line` is a standalone file-reading module/library. Its core data flow is: file descriptor input → buffered chunk reads → line extraction → returned lines. It is used as an educational primitive for stream processing and appears both as its own project and as embedded source in other folders.

4. `printf` is another standalone library project that reimplements formatted output. Its architecture is split into parsing, string handling, and number formatting helpers feeding a `printf`-style dispatcher. It is primarily a library boundary, not an application with business logic.

5. `pipex` is a Unix process-pipeline executor. Its flow is: command-line arguments and environment parsing → path resolution → process creation (`fork`) → pipe wiring → command execution (`exec`). The bonus variant adds heredoc handling and additional pipeline behavior. This project is centered on IPC and process orchestration.

6. `push_swap` is a two-stack sorting engine. The main flow is: parse and validate integer arguments → build stack state → choose a sorting strategy → emit stack operations. The code is split into parsing, stack operations, small-sort logic, quicksort-like helpers, and operation-printing modules. Output is not a sorted array but a sequence of allowed commands.

7. `philo` is a concurrent simulation of the dining philosophers problem. Its architecture revolves around timing, worker threads, and shared simulation state: initialize philosophers → run eat/sleep/think cycles → detect starvation or completion. The split into `eat.c`, `think_sleep.c`, `simulation.c`, and `time.c` reflects the separation between behavior, orchestration, and timing control.

8. `fdf` is the graphical project and the most pipeline-like in terms of data transformation. The flow is: parse a `.fdf` map file → build a grid representation → apply scaling/rotation/projection transforms → draw line segments via MiniLibX → react to keyboard and mouse events. Supporting modules handle color interpolation, cleanup, parsing helpers, and rendering.

9. `fdf` also contains a clear boundary between data preparation and presentation. Parsing files and linked-list/grid utilities build the model, while `rendering.c`, `draw_lines.c`, `rotations.c`, `scale_transform.c`, and event handlers form the view/controller side. This makes it the best candidate for a diagram with separate input, transform, render, and interaction layers.

10. The repository includes multiple sample input sets and test assets, especially for `fdf` maps and `push_swap` scripts. These are not runtime dependencies but validation fixtures used to exercise the algorithms and visual output.

11. A recurring architectural pattern across the repo is “single-purpose CLI or library per folder.” Each project owns its own headers, helper modules, and build configuration, with little cross-project reuse beyond conceptually similar `libft` code copied into each project’s local workspace.

12. External/runtime dependencies matter only in a few places: MiniLibX for `fdf` graphics, POSIX process and pipe primitives for `pipex`, and pthread-based concurrency for `philo`. Everything else is mostly self-contained ANSI C plus local utility libraries.

Main entry points: [`libft`](https://github.com/biostumpf/42_common_core/tree/main/libft) (libft), [`pipex`](https://github.com/biostumpf/42_common_core/tree/main/pipex) (Exec flow), [`fdf`](https://github.com/biostumpf/42_common_core/tree/main/fdf) (fdf), [`push_swap`](https://github.com/biostumpf/42_common_core/tree/main/push_swap) (push_swap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shared["Shared foundation"]
  node_libft["libft<br/>utility lib"]
  node_get_next_line["GNL<br/>file reader"]
  node_printf["printf<br/>format lib"]
end

subgraph group_apps["Projects"]
  node_fdf["fdf<br/>graphics app"]
  node_fdf_parse["Parse map<br/>input prep"]
  node_fdf_transform{{"Transform<br/>math pipeline"}}
  node_fdf_render["Render UI<br/>mlx view"]
  node_pipex["pipex<br/>ipc runner"]
  node_pipex_setup["Setup<br/>arg path"]
  node_pipex_exec{{"Exec flow<br/>process pipeline"}}
  node_pipex_heredoc["Heredoc<br/>bonus input"]
  node_push_swap["push_swap<br/>sorting engine"]
  node_ps_parse["Parse ints<br/>input validate"]
  node_ps_strategy{{"Strategy<br/>sorting logic"}}
  node_ps_ops["Ops emit<br/>command output"]
  node_philo["philo<br/>concurrency sim"]
  node_philo_core{{"State timing<br/>sim state"}}
  node_philo_cycle["Worker cycle<br/>behavior loop"]
end

subgraph group_fixtures["Fixtures"]
  node_maps["Maps<br/>fixtures"]
  node_scripts["Scripts<br/>fixtures"]
end

node_fdf -->|"starts with"| node_fdf_parse
node_fdf_parse -->|"feeds"| node_fdf_transform
node_fdf_transform -->|"draws into"| node_fdf_render
node_fdf_render -->|"uses"| node_libft
node_fdf_parse -->|"reads via"| node_get_next_line
node_fdf -.->|"validated by"| node_maps
node_pipex -->|"begins with"| node_pipex_setup
node_pipex_setup -->|"drives"| node_pipex_exec
node_pipex_exec -.->|"bonus path"| node_pipex_heredoc
node_pipex_exec -->|"uses"| node_libft
node_pipex_exec -.->|"uses"| node_get_next_line
node_push_swap -->|"starts with"| node_ps_parse
node_ps_parse -->|"feeds"| node_ps_strategy
node_ps_strategy -->|"emits"| node_ps_ops
node_ps_strategy -->|"uses"| node_libft
node_push_swap -.->|"validated by"| node_scripts
node_philo -->|"orchestrates"| node_philo_core
node_philo_core -->|"runs"| node_philo_cycle
node_philo_cycle -->|"updates"| node_philo_core
node_philo -->|"uses"| node_libft
node_printf -->|"builds on"| node_libft
node_get_next_line -->|"builds on"| node_libft
node_fdf -.->|"embeds copy of"| node_libft
node_pipex -.->|"embeds copy of"| node_libft
node_push_swap -.->|"embeds copy of"| node_libft

click node_libft "https://github.com/biostumpf/42_common_core/tree/main/libft"
click node_get_next_line "https://github.com/biostumpf/42_common_core/tree/main/get_next_line"
click node_printf "https://github.com/biostumpf/42_common_core/tree/main/printf"
click node_fdf "https://github.com/biostumpf/42_common_core/tree/main/fdf"
click node_fdf_parse "https://github.com/biostumpf/42_common_core/tree/main/fdf"
click node_fdf_transform "https://github.com/biostumpf/42_common_core/tree/main/fdf"
click node_fdf_render "https://github.com/biostumpf/42_common_core/tree/main/fdf"
click node_pipex "https://github.com/biostumpf/42_common_core/tree/main/pipex"
click node_pipex_setup "https://github.com/biostumpf/42_common_core/tree/main/pipex"
click node_pipex_exec "https://github.com/biostumpf/42_common_core/tree/main/pipex"
click node_pipex_heredoc "https://github.com/biostumpf/42_common_core/tree/main/pipex"
click node_push_swap "https://github.com/biostumpf/42_common_core/tree/main/push_swap"
click node_ps_parse "https://github.com/biostumpf/42_common_core/tree/main/push_swap"
click node_ps_strategy "https://github.com/biostumpf/42_common_core/tree/main/push_swap"
click node_ps_ops "https://github.com/biostumpf/42_common_core/tree/main/push_swap"
click node_philo "https://github.com/biostumpf/42_common_core/tree/main/philo"
click node_philo_core "https://github.com/biostumpf/42_common_core/tree/main/philo"
click node_philo_cycle "https://github.com/biostumpf/42_common_core/tree/main/philo"
click node_maps "https://github.com/biostumpf/42_common_core/tree/main/fdf/maps"
click node_scripts "https://github.com/biostumpf/42_common_core/tree/main/push_swap"

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_libft,node_get_next_line,node_printf toneBlue
class node_fdf,node_fdf_parse,node_fdf_transform,node_fdf_render,node_pipex,node_pipex_setup,node_pipex_exec,node_pipex_heredoc,node_push_swap,node_ps_parse,node_ps_strategy,node_ps_ops,node_philo,node_philo_core,node_philo_cycle toneAmber
class node_maps,node_scripts toneMint
```

## Components

### Shared foundation

Reusable utility and standalone library boundaries

- [libft](https://github.com/biostumpf/42_common_core/tree/main/libft): utility lib · Core string, memory, list, and conversion helpers reused across projects · `libft`
- [GNL](https://github.com/biostumpf/42_common_core/tree/main/get_next_line): file reader · Standalone buffered line-reading module · `get_next_line`
- [printf](https://github.com/biostumpf/42_common_core/tree/main/printf): format lib · Standalone formatted output library · `printf`

### Projects

Independent 42 Common Core executables and libraries

- [fdf](https://github.com/biostumpf/42_common_core/tree/main/fdf): graphics app · Map renderer built on MiniLibX · `fdf`
- [Parse map](https://github.com/biostumpf/42_common_core/tree/main/fdf): input prep · Reads .fdf data and builds the grid/model representation · `fdf`
- [Transform](https://github.com/biostumpf/42_common_core/tree/main/fdf): math pipeline · Scaling, rotation, projection, and color interpolation · `fdf`
- [Render UI](https://github.com/biostumpf/42_common_core/tree/main/fdf): mlx view · Line drawing and event-driven presentation layer · `fdf`
- [pipex](https://github.com/biostumpf/42_common_core/tree/main/pipex): ipc runner · Unix pipeline executor with command and pipe orchestration · `pipex`
- [Setup](https://github.com/biostumpf/42_common_core/tree/main/pipex): arg path · Argument parsing and environment/path resolution · `pipex`
- [Exec flow](https://github.com/biostumpf/42_common_core/tree/main/pipex): process pipeline · Forks, wires pipes, and launches commands · `pipex`
- [Heredoc](https://github.com/biostumpf/42_common_core/tree/main/pipex): bonus input · Bonus input handling and extended pipeline behavior · `pipex`
- [push_swap](https://github.com/biostumpf/42_common_core/tree/main/push_swap): sorting engine · Two-stack sorter that emits allowed operations · `push_swap`
- [Parse ints](https://github.com/biostumpf/42_common_core/tree/main/push_swap): input validate · Converts and validates command-line integers into stack state · `push_swap`
- [Strategy](https://github.com/biostumpf/42_common_core/tree/main/push_swap): sorting logic · Chooses small-sort or quicksort-like strategy · `push_swap`
- [Ops emit](https://github.com/biostumpf/42_common_core/tree/main/push_swap): command output · Stack operations and printed move sequences · `push_swap`
- [philo](https://github.com/biostumpf/42_common_core/tree/main/philo): concurrency sim · Dining philosophers simulation built around threads and timing · `philo`
- [State timing](https://github.com/biostumpf/42_common_core/tree/main/philo): sim state · Shared simulation state, timekeeping, and lifecycle control · `philo`
- [Worker cycle](https://github.com/biostumpf/42_common_core/tree/main/philo): behavior loop · Eat, sleep, and think transitions for each philosopher · `philo`

### Fixtures

Sample inputs and validation assets

- [Maps](https://github.com/biostumpf/42_common_core/tree/main/fdf/maps): fixtures · Sample .fdf inputs used to exercise rendering and parsing · `fdf/maps`
- [Scripts](https://github.com/biostumpf/42_common_core/tree/main/push_swap): fixtures · push_swap test scripts and checker assets · `push_swap`

## Connections

- fdf → Parse map: starts with · Loads map data before any rendering
- Parse map → Transform: feeds · Parsed grid becomes drawable geometry
- Transform → Render UI: draws into · Projection and coloring feed line rendering
- Render UI → libft: uses · Relies on local utility helpers
- Parse map → GNL: reads via · Uses buffered line input for map files
- fdf → Maps: validated by · Sample inputs exercise parsing and projection
- pipex → Setup: begins with · Parses argv and resolves execution paths
- Setup → Exec flow: drives · Prepared commands flow into process orchestration
- Exec flow → Heredoc: bonus path · Optional heredoc handling extends the pipeline
- Exec flow → libft: uses · Depends on local string and list helpers
- Exec flow → GNL: uses · Embedded reader support for input-related behavior
- push_swap → Parse ints: starts with · Validates and normalizes integer arguments
- Parse ints → Strategy: feeds · Parsed stack state selects a sorting plan
- Strategy → Ops emit: emits · Strategy is expressed as allowed stack commands
- Strategy → libft: uses · Reuses local utilities and list helpers
- push_swap → Scripts: validated by · Shell scripts and checker assets exercise behavior
- philo → State timing: orchestrates · Sets up global state and timing constraints
- State timing → Worker cycle: runs · Worker lifecycle loops execute simulation behavior
- Worker cycle → State timing: updates · Cycles consult shared state and starvation rules
- philo → libft: uses · Relies on local input and utility helpers
- printf → libft: builds on · Formatted output library depends on utility routines
- GNL → libft: builds on · Line reader uses basic memory and string helpers
- fdf → libft: embeds copy of · Project carries its own local utility workspace
- pipex → libft: embeds copy of · Project carries its own local utility workspace
- push_swap → libft: embeds copy of · Project carries its own local utility workspace
