Bento Spaces documentation
Bento Shelf — Build Spec
Historical brief. This was the original M1 specification. The living documents are
docs/00-index.mdand its siblings; where this file disagrees with them, the newer docs win. Kept for context on how the shelf engine was designed.
Status: M1 implemented and verified. Superseded by the webtop plan. Date: 2026-11-24 Project folder: /Users/renaldcamilleri/Desktop/Axe/Projects/bento (not yet a git repo) Machine: macOS (arm64), .NET SDK 10.0.301, sqlite3 3.54.0 (Node/npm are not used, D13)
0. How to use this document
This is the single source of truth for the project. It was written from a planning conversation and contains every decision made, including the ones that were rejected.
This document is already in place at bento/docs/SPEC.md, and bento/README.md carries the one-page summary.
Setup status (2026-11-24): git init done; solution scaffolded (Bento.slnx); src/web served by .NET with no build step; dotnet publish -o htdocs verified. Section 12 is answered. Remaining: milestone M1 (section 9).
Stack as built (supersedes the front-end rows in section 6): HTML + CSS + modern JavaScript (ES modules) + .NET 10. No npm, no bundler, no UI framework, no third-party packages. See D13.
Do not re-litigate locked decisions in section 2 without asking the user.
1. What this is
A desktop-style web app for composing bento layouts on a single horizontal " shelf" that sits centered in the viewport and grows sideways as you add pieces.
The mental model the user started from:
- A square is a 4×4 grid = 16 small boxes.
- A square can be filled by a variation/pattern: one big square, four squares,
- one wide rectangle with two squares underneath, and the other combinations.
- You can add another square to the left or right of an existing one, and the
- shelf keeps growing.
- Empty slots are drawn as 3px dashed outlines; each slot later hosts content
- that adapts to its size.
The result should feel like a physical shelf of bento tiles: centered, calm, dense, scrollable, and always consistent in its gaps and radii.
Non-goals
- Not a freeform infinite canvas.
- Not a multi-row dashboard builder.
- Not a page/website builder (until the export milestone).
- Not mobile-first. Desktop viewport ≥ 1024px is the target.
2. Locked decisions
| # | Decision | Rationale | Locked by |
|---|---|---|---|
| D1 | One horizontal shelf only. Fixed shelf height, grows rightward without limit. No wrapping, no second row. | Explicit user choice. Removes 2D collision/reflow entirely. | User |
| D2 | Shelf height = 4 boxes (one square tall) for the whole shelf. A pattern may not exceed it. | Matches "a square is 16 boxes". Keeps patterns uniform. | Assumption — confirm |
| D3 | Coordinates are stored in whole boxes (not pixels). Half boxes are gone: blocks snap to 1 box and are at least 1×1, so every block can host content later. | Revised 2026-11-24 by the user. Resolution independent; a 0.5-wide sliver could never be populated. | User |
| D4 | The 4×4 "square" is a visual guide, not a constraint. Blocks may cross square boundaries (guide line every 4 boxes). | Reference-image patterns need wide rects that straddle squares. | Planner |
| D5 | No nesting. Shelf → blocks → (later) widgets. Two levels, ever. | Nesting squares inside squares has ambiguous drag semantics and infinite edge cases. | Planner |
| D6 | Free placement, no auto-packing. Gaps/holes are allowed and intentional. Collisions are rejected during drag. | Bento layouts rely on deliberate whitespace; auto-pack fights the designer. | Planner |
| D7 | Add-left / add-right is the primary insertion gesture. Inserting shifts every block at or after the insertion point by the inserted width. | Literal user requirement; single-axis means a trivial reflow rule. | User |
| D8 | Patterns are rect templates inserted as an atomic group (group id). Not CSS templates. | Patterns become pure data — testable, exportable, filterable by fit. | Planner |
| D9 | Front end is plain JS. .NET 10 is the host + persistence + export layer only. | User: "everything where possible is js based, storage is json". Blazor rejected. | User |
| D10 | Layout document is versioned JSON, stored as a single column/row. Blocks are never normalised into DB tables. | Layouts are documents. Undo/redo = snapshot stack. Migrations live in JSON. | Planner |
| D11 | Undo/redo from M1, snapshot-based. | One small JSON doc; adding it later means retrofitting every mutation. | Planner |
| D12 | Pattern picker filters by fit. Only templates that fit the shelf height and remaining space are shown. | "Always show all variations" explodes the UI. | Planner |
| D13 | No third-party dependencies. Plain HTML/CSS/ES-module JS; hand-written CSS tokens; ~40-line vanilla store; crypto.randomUUID() for ids; inline SVG icons. No npm, no bundler, no React, no Tailwind. The .NET side uses the framework only; any NuGet package must be requested first. | User: "use html, css, js, .net — don't use third party stuff if really not needed". | User |
| D14 | htdocs/ is the release folder. dotnet publish -c Release -o htdocs produces the deployable output there; it is gitignored except .gitkeep. | User instruction. Matches the existing hosting layout. | User |
| D15 | Empty space is a first-class box. Every maximal gap ≥1×1 is drawn as a dashed box with a +; clicking it opens a popup of fills that fit that box (neighbour copies, splits, patterns). Add buttons live only at the shelf's two ends, never per block. | User: "pluses should be in beginning and end of everything… the box near it can add a duplicate… resize and make a box in the empty space". | User |
3. Geometry model
SQUARE = 4 boxes (one square = 16 boxes total)
SNAP = 1 box (finest allowed step — no half boxes)
MIN = 1×1 boxes (a block must be able to host content later)
SHELF_H = 4 boxes (D2)
Every block:
type Block = {
id: string; // crypto.randomUUID()
x: number; // boxes from shelf origin, whole boxes
y: number; // boxes from shelf top, whole boxes
w: number; // boxes, >= 1
h: number; // boxes, >= 1
group?: string; // pattern instance id; blocks sharing it move together
widget?: WidgetRef; // null/absent in M1
};
type LayoutDoc = {
schemaVersion: 1;
shelfUnits: 4; // D2
gap: number; // px token
unit: number; // px per box, default 80
blocks: Block[];
};
Invariants (validate on every mutation and on the server)
x >= 0,y >= 0.x,w,y,hare whole numbers of boxes.w >= 1,h >= 1.y + h <= shelfUnits.- No two blocks overlap: for all pairs, not
(a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h).- No duplicate ids.
unit > 0,gap >= 0.
Total shelf width in boxes = max(x + w) over blocks, or 4 when empty.
Pixel math (absolute positioning — recommended)
Put blocks in a position: relative container:
const px = (boxes: number) => boxes * (unit + gap); // start offset
const size = (boxes: number) => boxes * unit + (boxes - 1) * gap;
style = {
left: px(b.x),
top: px(b.y),
width: size(b.w),
height: size(b.h),
};
containerWidth = blocks.length ? size(totalBoxes) : size(4);
containerHeight = size(shelfUnits);
Absolute positioning is chosen over CSS grid because:
- drag math is deterministic (no track rounding),
transition: left/top/width/heightgives free shifting animation,- the container width is known exactly for scroll anchoring.
4. Pattern catalog (v1)
Each template is defined inside a 4×4 box and imports a full shelf height, so any template can be dropped anywhere on the shelf.
| id | name | slots |
|---|---|---|
single | One square | 1 |
quad | Four squares | 4 |
hero-top | Wide top + two below | 3 |
hero-left | Tall left + two stacked right | 3 |
bands | Wide / tall / two small | 4 |
six | Six mixed | 6 |
mosaic | Seven mixed (closest to reference art) | 7 |
focus | Big + four small + wide base | 6 |
// rects are [x, y, w, h] in boxes, relative to the template origin
single: [[0,0,4,4]]
quad: [[0,0,2,2],[2,0,2,2],[0,2,2,2],[2,2,2,2]]
hero-top: [[0,0,4,2],[0,2,2,2],[2,2,2,2]]
hero-left: [[0,0,2,4],[2,0,2,2],[2,2,2,2]]
bands: [[0,0,4,1],[0,1,4,2],[0,3,2,1],[2,3,2,1]]
six: [[0,0,2,2],[2,0,1,2],[3,0,1,2],[0,2,1,2],[1,2,1,2],[2,2,2,2]]
mosaic: [[0,0,2,1],[2,0,2,1],[0,1,1,2],[1,1,1,2],[2,1,2,2],[0,3,2,1],[2,3,2,1]]
focus: [[0,0,2,2],[2,0,1,1],[3,0,1,1],[2,1,1,1],[3,1,1,1],[0,2,4,2]]
All eight sum exactly to 16 boxes and only use whole boxes, which is now the only granularity (D3).
Patterns live in src/web/src/model/patterns.js as a plain constant array. The server may consume the same list later for export; do not duplicate it there in M1.
5. Interaction spec
5.1 Selection and affordances
- Add buttons live at the two ends of the shelf only — one
+before the first - block, one after the last. They are always visible once the shelf has content.
- Empty space is itself a box (D15): each maximal gap ≥1×1 gets a dashed outline and
- a centred
+. Clicking it opens "Fill this space", a grouped popup listing only - fills that fit that box — never a shape larger than the gap:
- From next door — a copy of a neighbouring size, preferred adjacency first.
- Fill it all — one box, rows, columns, all cells, and half + quarters.
- Leave one empty — a band plus a single cell, in four orientations.
- Half — one band, or two cells, leaving the rest empty.
- One cell — a single
1×1per corner. - Patterns — the catalog, only when the gap is a full-height seam.
- Partial fills are allowed: whatever is left over becomes a new empty box with its
- own
+. - Hovering a block shows a 3px dashed outline (using
outline, neverborder). - Empty shelf shows one ghost square with
+in the middle. - Selected block shows a solid 2px accent outline, a size badge (
2×2), and resize - handles on the right edge, bottom edge, and bottom-right corner.
5.2 Pattern picker
Anchored popover (never a centred modal — it must point at the insertion seam):
- Header:
Add to the left/Add to the right, plusAt the end. - Thumbnails rendered from the same rect data as the canvas (one renderer, no images).
- Filter by fit:
h <= shelfUnitsandw <= (viewportBoxes - insertionX). If nothing - fits, show a single "grow here anyway" entry. Minimum
wis 1. - Keyboard:
←/→to move,Enterto insert,Escto close. Type-ahead filter input. - Choosing inserts the group and selects its first block.
5.3 Insertion (D7)
function insertGroup(doc, groupRects, atX) {
const width = Math.max(...groupRects.map(r => r[0] + r[2]));
const shifted = doc.blocks.map(b =>
b.x >= atX ? { ...b, x: b.x + width } : b);
const created = groupRects.map(([x, y, w, h]) => ({
id: uuid(), x: atX + x, y, w, h, group: uuid(),
}));
return { ...doc, blocks: [...shifted, ...created] };
}
Two distinct group ids are needed: one for the new pattern instance, and the insertion must not merge with adjacent groups.
5.4 Drag (x-axis, plus optional y within the shelf)
pointerdownon a block body (not on a handle) →setPointerCapture.- Track
startX,startY,origX,origY. Move the dragged element with transform: translate(dx, dy)— no reflow, no layout thrash.- On
pointermove, compute the candidate position snapped to whole boxes and render a - ghost outline at the target: accent when valid, red when colliding or
- out of bounds.
- Dragging a block whose
groupis set moves the whole group rigidly. pointerup: commit if valid, otherwise animate back (transition+ reset- transform). One history entry per drag.
Escduring drag cancels.- Axis lock: hold
Shiftto constrain to horizontal.
5.5 Resize
- Right handle changes
w; bottom handle changesh; corner changes both. - Snap to whole boxes, enforce
w >= 1,h >= 1,y + h <= 4. - Space vacated by a resize becomes a fillable box (D15), not dead pixels.
- Resizing a block with a
groupis allowed and converts the group toundefined - (the pattern "breaks"), with a one-time toast: "Pattern unlinked".
- Same ghost/validity treatment as drag. One history entry per resize.
5.6 Delete
Delete/Backspaceremoves selection; multi-select viaShift+click or- marquee (marquee optional in M1).
- Deleting is not followed by a leftward pull (D6); it leaves a gap. Provide
Close gapin the block context menu.
5.7 Scroll anchoring (easy to miss, obvious when wrong)
.viewport { overflow-x: auto; overflow-y: hidden; }
.shelf { width: max-content; margin-inline: auto; min-width: 100%; }
- Appending / inserting to the right →
block.scrollIntoView({ inline: 'nearest', behavior: 'smooth' }). - Inserting to the left of the current scroll position → after commit,
viewport.scrollLeft += insertedWidthPxso the view does not jump.- Never re-centre programmatically;
margin-inline: autoalready handles both states - (centred while it fits, scrollable once it grows).
5.8 Undo / redo
history: LayoutDoc[],index: number, cap 100 entries.- Commit points only: insert, delete, drag commit, resize commit, property change.
- Never per
pointermove. Cmd/Ctrl+Z,Shift+Cmd/Ctrl+Z. Show toast with the action name.
6. Stack
Front end
| Concern | Choice |
|---|---|
| Delivery | Static files in src/web, served directly by .NET — no build step |
| Language | Modern JavaScript, ES modules, JSDoc type comments |
| Framework | None. Small render functions + full re-render on commit |
| Styling | Hand-written CSS + custom properties for tokens |
| State | Vanilla store module (doc, history, selection) with a subscribe() |
| Drag | Hand-rolled pointer events in useShelfDrag.js |
| Animation | CSS transitions on left/top/width/height |
| Icons | Inline SVG in the markup |
| Ids | crypto.randomUUID() |
| Unit tests | Deferred; geometry.js stays pure so it can be tested by node --test when wanted |
Rejected: React, Vite, Tailwind, Zustand, react-grid-layout, Gridstack.js, @dnd-kit, lodash, and any dependency a browser already provides (D13). The geometry is ~250 lines of pointer logic; a 2D grid library would fight it.
Back end
| Concern | Choice |
|---|---|
| Runtime | ASP.NET Core .NET 10, minimal APIs |
| Storage | SQLite. Provider chosen at M2 — Microsoft.Data.Sqlite is preferred over EF Core because it is one small NuGet package (D13 requires asking first) |
| API docs | Built-in Microsoft.AspNetCore.OpenApi (MapOpenApi) — deferred until M2 |
| Validation | C# DTOs + explicit invariant checks (section 3), 422 on failure |
| SPA hosting | UseDefaultFiles + UseStaticFiles + explicit fallback to index.html (/api/* stays 404) |
| Tests | dotnet new xunit at M2 — the first NuGet download in the project |
.NET 10 minimal API has AddOpenApi/MapOpenApi built in; no Swashbuckle.
M1 ships with zero packages. Bento.Api.csproj has no PackageReference; only the shared framework is used.
What .NET honestly earns here: hosting, JSON persistence, server-side invariant validation, schema-version migration, static-HTML export, and auth later. If it ends up as a static file server with a PUT, that is a smell — put the geometry validator and the exporter in C# so both sides enforce and both sides are tested.
7. Repository layout
bento/
Bento.slnx ← .NET 10 creates .slnx by default
README.md
docs/SPEC.md ← this document
htdocs/ ← `dotnet publish` output (gitignored, D14)
src/
Bento.Api/
Program.cs ← hosting, /api/health, SPA fallback
appsettings.json
Properties/launchSettings.json
Data/ ← M2: LayoutEntity, AppDb
Features/Layouts/ ← M2: endpoints + validation
wwwroot/ ← generated from src/web (gitignored)
Bento.Api.csproj ← MSBuild target copies src/web → wwwroot
web/ ← served as-is; no build, no npm
index.html
styles/
tokens.css ← section 10 tokens
app.css
src/
main.js ← entry
model/types.js ← LayoutDoc, Block (JSDoc typedefs)
model/patterns.js ← pattern catalog
model/geometry.js ← PURE: insert/shift/snap/collide/validate
model/history.js
store/layoutStore.js
features/shelf/Shelf.js
features/shelf/BlockView.js
features/shelf/useShelfDrag.js
features/shelf/useShelfResize.js
features/picker/PatternPicker.js
features/picker/PatternThumb.js
lib/api.js ← the only module that talks HTTP
lib/persist.js ← localStorage adapter (M1)
tests/ ← M2: Bento.Api.Tests
geometry.js must contain no DOM and no store access. It is the file that gets the tests and it is the reason this project is easy to keep correct.
Commands
# dev — one process, static files come straight from src/web
cd src/Bento.Api && dotnet run # http://localhost:5080
# release — self-contained folder ready to copy to a server
cd src/Bento.Api && dotnet publish -c Release -o ../../htdocs
There is no web build step: the csproj SyncWebAssets target copies src/web/** into wwwroot/ before build and publish. Editing a .js or .css file needs only a browser refresh in dev; nothing to install, nothing to compile.
8. API contract
GET /api/layouts → LayoutSummary[] (id, name, updatedAt)
POST /api/layouts → LayoutEnvelope body: { name, doc }
GET /api/layouts/{id} → LayoutEnvelope
PUT /api/layouts/{id} → LayoutEnvelope body: { name, doc } (upsert)
DELETE /api/layouts/{id} → 204
GET /api/layouts/{id}/export → text/html (M4)
type LayoutEnvelope = {
id: string;
name: string;
schemaVersion: number;
doc: LayoutDoc;
createdAt: string; // ISO
updatedAt: string; // ISO
};
DB:
public class LayoutEntity
{
public Guid Id { get; set; }
public string Name { get; set; } = "Untitled";
public int SchemaVersion { get; set; } = 1;
public string DocJson { get; set; } = "{}";
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
}
Rules:
- Server validates every invariant in section 3 before writing;
422with { errors: { path, message }[] }on failure.- Server owns
schemaVersion; reject docs newer than it understands (409). - Client debounces autosave 800ms after a commit.
navigator.sendBeaconon unload. - M1 uses
localStoragebehind the samepersist.jsinterface; swapping to HTTP is - a single adapter change.
9. Milestones
M1 — Shelf editor + pattern picker (the only thing to build now)
Scope:
- Shelf renders from a
LayoutDoc, centered,overflow-x: auto. - 3px dashed outlines on empty blocks; toggleable guide overlay (1-box grid, 4-box
- square divider).
- Pattern picker with live thumbnails and fit filtering.
- Add-left / add-right / append with correct shifting.
- Drag with snapping, ghost preview, collision rejection, group-rigid moves.
- Resize width/height with snapping.
- Delete, duplicate block (
Cmd/Ctrl+D), close gap. - Undo/redo.
- Persist to
localStorageand restore on reload.
Acceptance criteria:
- ✓Empty shelf shows a centered ghost square; clicking
+opens the picker. - ✓Inserting
quad, thenhero-leftto its right, yields a continuous shelf with - no overlaps and no gaps at the seams.
- ✓Inserting to the left of the first block shifts every block right by exactly
- the pattern width, and the viewport does not jump.
- ✓Dragging a block snaps to half-boxes; dropping on an occupied area shows red
- and springs back.
- ✓Dragging a block from
quadmoves all four together; resizing one unlinks the - group with a toast.
- ✓Reload restores the exact layout.
- ✓
Cmd/Ctrl+Zundoes an insert, a drag, and a resize, in that order. - ✓The shelf has one
+at each end; the left one inserts at the very start. - ✓Deleting or dragging a block away leaves a dashed empty box; its
+opens a - popup of fills that fit, and choosing one fills the box (copies, splits, patterns).
- ✓
geometry.jshas tests covering insert/shift, snap, overlap, and validation - (
node --test, no dependency).
All eight were verified two ways: node --test tests/web/*.test.js for the pure model, and a headless-Chromium pass that drives real pointer events against the DOM (insert, drag, collision spring-back, group drag, resize/unlink, undo, reload, delete, guide toggle).
M2 — Persistence API
SQLite, endpoints from section 8, server-side validation, autosave, multiple named layouts (/l/:id), duplicate layout. Ask before adding the SQLite NuGet package (D13).
M3 — Widgets
WidgetRef = { type: string, props: Record<string, unknown> }. Registry of widget types, each declaring minW/minH in boxes and a size-class map. Rendering uses CSS @container queries, never media queries. Starter widgets: clock, note, stat, link list, image. Widgets never resize themselves; the block owns geometry.
M4 — Export
GET /api/layouts/{id}/export renders a self-contained static HTML file (inlined CSS, no JS) implemented in C# from the same JSON. This is the feature that makes the app worth using.
M5 — Desktop feel
Command palette (Cmd/Ctrl+K) hand-rolled (no cmdk, D13), context menus, keyboard shortcuts sheet (?), drag-to-reorder patterns, theme switching, sound-free micro-interactions, localStorage session restore, focus rings everywhere.
10. Style tokens
:root {
--unit: 80px; /* px per box; square = 4 units ≈ 320px */
--gap: 12px;
--radius: 14px;
--radius-sm: 10px;
--guide: rgba(255,255,255,0.08);
--guide-square: rgba(255,255,255,0.18);
--dash: 3px dashed rgba(255,255,255,0.28);
--accent: #7c9cff;
--danger: #ff6b6b;
--surface: #111214;
--surface-raised: #1a1c20;
--fg: #e8eaee;
--fg-muted: #8b9099;
}
Dark-first. Rules:
- Uniform
gapandradiuseverywhere — this is what makes a bento look designed. - Dashed outlines via
outline(no layout shift). Useoutline-offset: -1px. - Empty block = dashed outline + centered size badge (
2×2) at 40% opacity. - Hover raises
--surface-raisedby 2% and animatestransition: 120ms ease-out. - No drop shadows on blocks; separation comes from gap + radius only.
- Reduce motion: honour
prefers-reduced-motion.
11. Guardrails for the implementer
- Do not introduce a 2D grid library. See section 6.
- Do not switch patterns to CSS
grid-template-areas. Patterns are data. - Do not add nesting, rows, or freeform canvas.
- Do not store pixels in the model. Boxes only;
unitandgapare render-time. - Do not put geometry logic in UI code. It belongs in
model/geometry.js. - Do not normalise blocks into DB tables.
- Do not use
borderfor guides or outlines. - Do not write to
wwwroot/by hand; it is generated fromsrc/web/. - Do not add any dependency. HTML, CSS, JS and .NET only (D13); ask if a package
- ever seems unavoidable.
- Commit after each green milestone step, with the acceptance criteria quoted.
12. Open questions — answered 2026-11-24
All seven were decided by the user. They are no longer open.
| # | Question | Answer |
|---|---|---|
| 1 | Shelf height | Fixed at 4 boxes for the whole shelf (D2 confirmed). |
| 2 | Theme | Dark-only for now (section 10). Light theme is an M5 item. |
| 3 | Guides | Dashed block outlines always on; the 1-box / 4-box guide overlay is a toggle. |
| 4 | Layouts | One layout in M1. Multiple named layouts arrive in M2. |
| 5 | Block content | Truly empty blocks — dashed outline plus the centered size badge. No Slot 1 labels. |
| 6 | Persistence target | Local-only for now (localStorage in M1); the API leaves room for accounts later. |
| 7 | Export | Static HTML, inlined CSS and no JS (M4). |