# ajordn/ft_printf architecture

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

- Interactive diagram: https://gitdiagram.com/ajordn/ft_printf
- Repository: https://github.com/ajordn/ft_printf

## Overview

1. **Project type and scope**
   - This repository is a C library implementation of a simplified `printf`, intended for the 42 school project.
   - It is not an application; the main runtime boundary is a library API that other C programs call.

2. **Top-level layout**
   - The repo is split into three architectural areas:
     - `include/` for public headers.
     - `src/` for the `ft_printf` implementation.
     - `libft/` for a bundled utility library used as a dependency.
   - The root `Makefile` builds the deliverable by combining `src` with `libft`.

3. **Public API boundary**
   - `include/ft_printf.h` is the primary external interface for consumers.
   - `include/libft.h` exposes the helper library that `ft_printf` depends on internally.
   - This means the exported surface is intentionally small, while most implementation detail stays inside `src/` and `libft/`.

4. **Core formatting engine**
   - `src/ft_printf.c` is the central dispatcher.
   - It likely parses the format string, identifies conversion specifiers, and routes each placeholder to the appropriate formatter.
   - `src/ft_printf_utils.c` holds shared helpers for parsing, state management, or conversion support.

5. **Format-specific subsystems**
   - The implementation is split by output type:
     - `ft_print_hex.c` for hexadecimal conversions.
     - `ft_print_ptr.c` for pointer formatting.
     - `ft_print_unsigned.c` for unsigned integer formatting.
   - This decomposition suggests a modular formatter design where each specifier has its own output path.

6. **Variadic argument flow**
   - The project’s key mechanism is variadic argument handling, as noted in the README.
   - Data flow is: caller passes a format string plus variable arguments → `ft_printf` extracts arguments one by one → each formatter converts and prints its value.
   - The architecture is centered around translation from typed arguments into textual output.

7. **Dependency on `libft`**
   - `libft/` is a self-contained support library with classic C utility functions: memory, strings, character checks, list helpers, and output helpers.
   - `ft_printf` depends on it for low-level operations such as string manipulation, numeric conversion, and writing to file descriptors.
   - This creates an internal dependency boundary: `ft_printf` is the product, `libft` is the reusable foundation.

8. **Output mechanism**
   - The library appears to emit text through low-level write helpers rather than higher-level I/O abstractions.
   - `libft/src/ft_put/*` contains `ft_putchar_fd`, `ft_putstr_fd`, `ft_putnbr_fd`, and `ft_putendl_fd`, which are natural building blocks for formatted output.
   - This keeps the implementation close to standard C and independent of higher-level frameworks.

9. **Build and packaging**
   - The project uses `make` as its primary build tool.
   - There is a root-level `Makefile` plus a separate `libft/Makefile`, indicating a two-stage or nested build where the support library is compiled as part of the final artifact.
   - The repository is therefore organized as a library package, not a service or executable.

10. **Technology constraints**
   - The implementation is plain C and targets a standard GCC-based environment, per the README.
   - No external runtime services, databases, or network components are part of the architecture.
   - The main portability concern is compatibility with standard C tooling and the expected `printf` behavior.

11. **Testing boundary**
   - The README references `Tripouille/printfTester` as an external validation tool.
   - This suggests testing is done against behavioral conformance rather than integration with other subsystems.
   - In an architecture diagram, this should appear as an external QA harness around the library, not as part of the product runtime.

12. **Diagramming takeaway**
   - The cleanest diagram is: consumer code calls `ft_printf` through `ft_printf.h`; `ft_printf` parses the format string, delegates specifiers to specialized printer modules, and uses `libft` helpers to perform conversions and output.
   - `libft` sits below `ft_printf` as an internal utility layer, while `make` and the external tester sit outside the runtime boundary.

Main entry points: [`src/ft_printf.c`](https://github.com/ajordn/ft_printf/blob/main/src/ft_printf.c) (ft_printf), [`libft/src/ft_put`](https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_put) (ft_put), [`libft/src/ft_to`](https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_to) (ft_to), [`Makefile`](https://github.com/ajordn/ft_printf/tree/main/Makefile) (Makefile)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_public["Public API"]
  node_node_include_ft_printf_h["ft_printf.h<br/>public header<br/>[ft_printf.h]"]
  node_node_include_libft_h["libft.h<br/>support header<br/>[libft.h]"]
end

subgraph group_group_core["ft_printf core"]
  node_node_src_ft_printf_c["ft_printf<br/>dispatcher<br/>[ft_printf.c]"]
  node_node_src_ft_printf_utils_c["printf utils<br/>helper core<br/>[ft_printf_utils.c]"]
  node_node_src_ft_print_hex_c["hex print<br/>hex formatter<br/>[ft_print_hex.c]"]
  node_node_src_ft_print_ptr_c["ptr print<br/>pointer formatter<br/>[ft_print_ptr.c]"]
  node_node_src_ft_print_unsigned_c["unsigned print<br/>unsigned formatter"]
end

subgraph group_group_support["libft support"]
  node_node_libft_put["ft_put<br/>fd output"]
  node_node_libft_str["ft_str<br/>string utils"]
  node_node_libft_to["ft_to<br/>conversion utils"]
  node_node_libft_mem["ft_mem<br/>memory utils"]
  node_node_libft_is["ft_is<br/>char checks"]
  node_node_libft_lst["ft_lst<br/>list utils"]
end

subgraph group_group_build["Build"]
  node_node_makefile_root["Makefile<br/>build config"]
end

subgraph group_group_external["External"]
  node_node_readme_tester(("printfTester<br/>external qa"))
end

node_node_makefile_root -->|"builds"| node_node_src_ft_printf_c
node_node_makefile_root -->|"links"| node_node_libft_put
node_node_makefile_root -->|"publishes"| node_node_include_ft_printf_h
node_node_include_ft_printf_h -.->|"declares"| node_node_src_ft_printf_c
node_node_include_libft_h -.->|"declares"| node_node_libft_put
node_node_src_ft_printf_c -->|"uses"| node_node_src_ft_printf_utils_c
node_node_src_ft_printf_c -->|"delegates"| node_node_src_ft_print_hex_c
node_node_src_ft_printf_c -->|"delegates"| node_node_src_ft_print_ptr_c
node_node_src_ft_printf_c -->|"delegates"| node_node_src_ft_print_unsigned_c
node_node_src_ft_printf_c -->|"writes via"| node_node_libft_put
node_node_src_ft_printf_c -->|"parses with"| node_node_libft_str
node_node_src_ft_printf_c -->|"converts with"| node_node_libft_to
node_node_src_ft_printf_c -->|"checks with"| node_node_libft_is
node_node_src_ft_print_hex_c -->|"converts with"| node_node_libft_to
node_node_src_ft_print_ptr_c -->|"converts with"| node_node_libft_to
node_node_src_ft_print_unsigned_c -->|"converts with"| node_node_libft_to
node_node_src_ft_printf_utils_c -->|"uses"| node_node_libft_mem
node_node_src_ft_printf_utils_c -->|"uses"| node_node_libft_str
node_node_libft_put -.->|"depends on"| node_node_libft_mem
node_node_readme_tester -.->|"validates"| node_node_src_ft_printf_c

click node_node_include_ft_printf_h "https://github.com/ajordn/ft_printf/blob/main/include/ft_printf.h"
click node_node_include_libft_h "https://github.com/ajordn/ft_printf/blob/main/include/libft.h"
click node_node_makefile_root "https://github.com/ajordn/ft_printf/tree/main/Makefile"
click node_node_src_ft_printf_c "https://github.com/ajordn/ft_printf/blob/main/src/ft_printf.c"
click node_node_src_ft_printf_utils_c "https://github.com/ajordn/ft_printf/blob/main/src/ft_printf_utils.c"
click node_node_src_ft_print_hex_c "https://github.com/ajordn/ft_printf/blob/main/src/ft_print_hex.c"
click node_node_src_ft_print_ptr_c "https://github.com/ajordn/ft_printf/blob/main/src/ft_print_ptr.c"
click node_node_src_ft_print_unsigned_c "https://github.com/ajordn/ft_printf/blob/main/src/ft_print_unsigned.c"
click node_node_libft_put "https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_put"
click node_node_libft_str "https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_str"
click node_node_libft_to "https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_to"
click node_node_libft_mem "https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_mem"
click node_node_libft_is "https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_is"
click node_node_libft_lst "https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_lst"

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_node_include_ft_printf_h,node_node_include_libft_h toneBlue
class node_node_src_ft_printf_c,node_node_src_ft_printf_utils_c,node_node_src_ft_print_hex_c,node_node_src_ft_print_ptr_c,node_node_src_ft_print_unsigned_c toneAmber
class node_node_libft_put,node_node_libft_str,node_node_libft_to,node_node_libft_mem,node_node_libft_is,node_node_libft_lst toneMint
class node_node_makefile_root toneRose
class node_node_readme_tester toneIndigo
```

## Components

### Public API

Headers that define the library surface for consumers.

- [ft_printf.h](https://github.com/ajordn/ft_printf/blob/main/include/ft_printf.h): public header · Primary API for consumers calling the formatter. · `include/ft_printf.h`
- [libft.h](https://github.com/ajordn/ft_printf/blob/main/include/libft.h): support header · Exports the bundled helper library interface used internally. · `include/libft.h`

### ft_printf core

Format parsing and conversion dispatch inside the library.

- [ft_printf](https://github.com/ajordn/ft_printf/blob/main/src/ft_printf.c): dispatcher · Central variadic formatter that parses the format string and routes specifiers. · `src/ft_printf.c`
- [printf utils](https://github.com/ajordn/ft_printf/blob/main/src/ft_printf_utils.c): helper core · Shared parsing and state helpers for the formatter. · `src/ft_printf_utils.c`
- [hex print](https://github.com/ajordn/ft_printf/blob/main/src/ft_print_hex.c): hex formatter · Formats hexadecimal conversions. · `src/ft_print_hex.c`
- [ptr print](https://github.com/ajordn/ft_printf/blob/main/src/ft_print_ptr.c): pointer formatter · Formats pointer values. · `src/ft_print_ptr.c`
- [unsigned print](https://github.com/ajordn/ft_printf/blob/main/src/ft_print_unsigned.c): unsigned formatter · Formats unsigned integer values. · `src/ft_print_unsigned.c`

### libft support

Bundled utility layer reused by ft_printf internals.

- [ft_put](https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_put): fd output · Low-level file-descriptor output helpers used to emit formatted text. · `libft/src/ft_put`
- [ft_str](https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_str): string utils · String manipulation helpers used for parsing and conversion support. · `libft/src/ft_str`
- [ft_to](https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_to): conversion utils · Numeric and character conversion helpers. · `libft/src/ft_to`
- [ft_mem](https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_mem): memory utils · Memory primitives used by the formatter and support code. · `libft/src/ft_mem`
- [ft_is](https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_is): char checks · Character classification helpers used during parsing. · `libft/src/ft_is`
- [ft_lst](https://github.com/ajordn/ft_printf/tree/main/libft/src/ft_lst): list utils · General-purpose list helpers bundled with libft. · `libft/src/ft_lst`

### Build

Make-based packaging and assembly of the library.

- [Makefile](https://github.com/ajordn/ft_printf/tree/main/Makefile): build config · Top-level build entrypoint that assembles ft_printf with libft. · `Makefile`

### External

Outside tools used to validate or consume the library.

- **printfTester**: external qa · External behavior-conformance test harness referenced by the project.

## Connections

- Makefile → ft_printf: builds · Compiles the formatter implementation into the library artifact.
- Makefile → ft_put: links · Includes bundled libft objects in the final build.
- Makefile → ft_printf.h: publishes · Installs or exposes the public API header.
- ft_printf.h → ft_printf: declares · Defines the consumer-facing function contract implemented by ft_printf.
- libft.h → ft_put: declares · Exposes helper routines used by the formatter internals.
- ft_printf → printf utils: uses · Shares parsing and state helpers.
- ft_printf → hex print: delegates · Routes hexadecimal specifiers to the dedicated formatter.
- ft_printf → ptr print: delegates · Routes pointer specifiers to the dedicated formatter.
- ft_printf → unsigned print: delegates · Routes unsigned integer specifiers to the dedicated formatter.
- ft_printf → ft_put: writes via · Emits output through low-level fd helpers.
- ft_printf → ft_str: parses with · Relies on string helpers for format-string handling.
- ft_printf → ft_to: converts with · Uses conversion helpers for numeric/text representation.
- ft_printf → ft_is: checks with · Uses character classification during format parsing.
- hex print → ft_to: converts with · Formats numbers using conversion helpers.
- ptr print → ft_to: converts with · Converts pointer values to text.
- unsigned print → ft_to: converts with · Converts unsigned integers to text.
- printf utils → ft_mem: uses · May use memory utilities for temporary state or buffers.
- printf utils → ft_str: uses · May use string helpers for shared parsing logic.
- ft_put → ft_mem: depends on · Output helpers may use memory primitives internally.
- printfTester → ft_printf: validates · External tester exercises the formatter behavior.
