# mushishi78/box_packer architecture

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

- Interactive diagram: https://gitdiagram.com/mushishi78/box_packer
- Repository: https://github.com/mushishi78/box_packer

## Overview

BoxPacker is a small Ruby library that applies a first-fit 3D bin-packing heuristic with a weight limit. A caller supplies a container and ordered items to `BoxPacker.pack`; the routine checks weight, attempts existing packings, creates a new packing when needed, and returns packings with placements and weights. `place` handles orientation and fit, while `break_up_space` creates remaining candidate spaces. These responsibilities share one source file. The graph reflects the excerpted implementation and README; there are no separate service or storage layers.

Main entry points: [`box_packer.rb`](https://github.com/mushishi78/box_packer/blob/master/box_packer.rb) (First-fit packing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_packing["Packing algorithm"]
  node_pack["First-fit packing<br/>[box_packer.rb]"]
  node_result["Packings result<br/>[box_packer.rb]"]
end

subgraph group_geometry["Placement geometry"]
  node_place["Orientation fit<br/>[box_packer.rb]"]
  node_spaces["Free-space splitting<br/>[box_packer.rb]"]
end

node_caller(("Library caller"))

node_caller -->|"calls"| node_pack
node_pack -->|"tries placement"| node_place
node_pack -->|"splits spaces"| node_spaces
node_pack -->|"returns"| node_result

click node_pack "https://github.com/mushishi78/box_packer/blob/master/box_packer.rb"
click node_place "https://github.com/mushishi78/box_packer/blob/master/box_packer.rb"
click node_spaces "https://github.com/mushishi78/box_packer/blob/master/box_packer.rb"
click node_result "https://github.com/mushishi78/box_packer/blob/master/box_packer.rb"

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_pack,node_result toneBlue
class node_place,node_spaces toneAmber
class node_caller toneIndigo
```

## Components

### Packing algorithm

- [First-fit packing](https://github.com/mushishi78/box_packer/blob/master/box_packer.rb): `box_packer.rb`
- [Packings result](https://github.com/mushishi78/box_packer/blob/master/box_packer.rb): `box_packer.rb`

### Placement geometry

- [Orientation fit](https://github.com/mushishi78/box_packer/blob/master/box_packer.rb): `box_packer.rb`
- [Free-space splitting](https://github.com/mushishi78/box_packer/blob/master/box_packer.rb): `box_packer.rb`

### Other components

- **Library caller**

## Connections

- Library caller → First-fit packing: calls (evidence: `README.md`)
- First-fit packing → Orientation fit: tries placement (evidence: `box_packer.rb`)
- First-fit packing → Free-space splitting: splits spaces (evidence: `box_packer.rb`)
- First-fit packing → Packings result: returns (evidence: `box_packer.rb`)
