# jabb4man/42-rushbsq architecture

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

- Interactive diagram: https://gitdiagram.com/jabb4man/42-rushbsq
- Repository: https://github.com/jabb4man/42-rushbsq

## Overview

BSQ is a command-line solver that reads one or more maps from files or standard input, validates and loads each map, finds the largest empty square, and prints the map with that square marked. Its distinctive algorithm updates per-column heights for each row, scans them with a monotonic stack, and resolves equal-size candidates top-then-left. The sampled sources show the principal flow and output helpers; the README documents multi-map operation and the algorithm. The shared header is included in the graph as the program’s type and function contract.

Main entry points: [`srcs/main.c`](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/main.c) (Map processing), [`srcs/solver.c`](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/solver.c) (Tie-breaking), [`srcs/utils.c`](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/utils.c) (Output and cleanup), [`bsq.h`](https://github.com/jabb4man/42-rushbsq/blob/main/bsq.h) (Shared declarations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Input interface"]
  node_entry["Map processing<br/>[main.c]"]
  node_contract["Shared declarations<br/>[bsq.h]"]
end

subgraph group_parsing["Map parsing"]
  node_header["Header validation<br/>[parser.c]"]
  node_grid["Map loading<br/>[parser.c]"]
end

subgraph group_solving["Square solving"]
  node_heights["Row histograms<br/>[solver.c]"]
  node_stack["Monotonic stack<br/>[solver.c]"]
  node_best["Tie-breaking<br/>[solver.c]"]
end

subgraph group_output["Output"]
  node_renderer["Square rendering<br/>[output.c]"]
  node_helpers["Output and cleanup<br/>[utils.c]"]
end

node_user(("CLI user"))
node_stdout(("Standard output"))

node_user -->|"provides maps"| node_entry
node_entry -->|"validates header"| node_header
node_entry -->|"loads map"| node_grid
node_entry -->|"solves map"| node_best
node_entry -->|"reports errors"| node_helpers
node_entry -->|"frees map"| node_helpers
node_grid -->|"frees partial map"| node_helpers
node_best -->|"updates heights"| node_heights
node_best -->|"scans histogram"| node_stack
node_stack -->|"updates candidate"| node_best
node_best -->|"prints result"| node_renderer
node_renderer -->|"writes characters"| node_helpers
node_helpers -->|"writes output"| node_stdout
node_entry -->|"includes declarations"| node_contract
node_header -->|"includes declarations"| node_contract
node_best -->|"includes declarations"| node_contract
node_renderer -->|"includes declarations"| node_contract
node_helpers -->|"includes declarations"| node_contract

click node_entry "https://github.com/jabb4man/42-rushbsq/blob/main/srcs/main.c"
click node_contract "https://github.com/jabb4man/42-rushbsq/blob/main/bsq.h"
click node_header "https://github.com/jabb4man/42-rushbsq/blob/main/srcs/parser.c"
click node_grid "https://github.com/jabb4man/42-rushbsq/blob/main/srcs/parser.c"
click node_heights "https://github.com/jabb4man/42-rushbsq/blob/main/srcs/solver.c"
click node_stack "https://github.com/jabb4man/42-rushbsq/blob/main/srcs/solver.c"
click node_best "https://github.com/jabb4man/42-rushbsq/blob/main/srcs/solver.c"
click node_renderer "https://github.com/jabb4man/42-rushbsq/blob/main/srcs/output.c"
click node_helpers "https://github.com/jabb4man/42-rushbsq/blob/main/srcs/utils.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_entry,node_contract,node_user toneBlue
class node_header,node_grid toneAmber
class node_heights,node_stack,node_best toneMint
class node_renderer,node_helpers toneRose
class node_stdout toneIndigo
```

## Components

### Input interface

- [Map processing](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/main.c): `srcs/main.c`
- [Shared declarations](https://github.com/jabb4man/42-rushbsq/blob/main/bsq.h): `bsq.h`

### Map parsing

- [Header validation](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/parser.c): `srcs/parser.c`
- [Map loading](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/parser.c): `srcs/parser.c`

### Square solving

- [Row histograms](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/solver.c): `srcs/solver.c`
- [Monotonic stack](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/solver.c): `srcs/solver.c`
- [Tie-breaking](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/solver.c): `srcs/solver.c`

### Output

- [Square rendering](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/output.c): `srcs/output.c`
- [Output and cleanup](https://github.com/jabb4man/42-rushbsq/blob/main/srcs/utils.c): `srcs/utils.c`

### Other components

- **CLI user**
- **Standard output**

## Connections

- CLI user → Map processing: provides maps (evidence: `README.md`)
- Map processing → Header validation: validates header (evidence: `srcs/main.c`)
- Map processing → Map loading: loads map (evidence: `srcs/main.c`)
- Map processing → Tie-breaking: solves map (evidence: `srcs/main.c`)
- Map processing → Output and cleanup: reports errors (evidence: `srcs/main.c`)
- Map processing → Output and cleanup: frees map (evidence: `srcs/main.c`)
- Map loading → Output and cleanup: frees partial map (evidence: `srcs/parser.c`)
- Tie-breaking → Row histograms: updates heights (evidence: `srcs/solver.c`)
- Tie-breaking → Monotonic stack: scans histogram (evidence: `srcs/solver.c`)
- Monotonic stack → Tie-breaking: updates candidate (evidence: `srcs/solver.c`)
- Tie-breaking → Square rendering: prints result (evidence: `srcs/solver.c`)
- Square rendering → Output and cleanup: writes characters (evidence: `srcs/output.c`)
- Output and cleanup → Standard output: writes output (evidence: `srcs/utils.c`)
- Map processing → Shared declarations: includes declarations (evidence: `srcs/main.c`)
- Header validation → Shared declarations: includes declarations (evidence: `srcs/parser.c`)
- Tie-breaking → Shared declarations: includes declarations (evidence: `srcs/solver.c`)
- Square rendering → Shared declarations: includes declarations (evidence: `srcs/output.c`)
- Output and cleanup → Shared declarations: includes declarations (evidence: `srcs/utils.c`)
