Bento Spaces docs

Bento Spaces documentation

Bento Shelf — Build Spec

Historical brief. This was the original M1 specification. The living documents are docs/00-index.md and 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:

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


2. Locked decisions

#DecisionRationaleLocked by
D1One horizontal shelf only. Fixed shelf height, grows rightward without limit. No wrapping, no second row.Explicit user choice. Removes 2D collision/reflow entirely.User
D2Shelf 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
D3Coordinates 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
D4The 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
D5No nesting. Shelf → blocks → (later) widgets. Two levels, ever.Nesting squares inside squares has ambiguous drag semantics and infinite edge cases.Planner
D6Free 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
D7Add-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
D8Patterns are rect templates inserted as an atomic group (group id). Not CSS templates.Patterns become pure data — testable, exportable, filterable by fit.Planner
D9Front 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
D10Layout 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
D11Undo/redo from M1, snapshot-based.One small JSON doc; adding it later means retrofitting every mutation.Planner
D12Pattern picker filters by fit. Only templates that fit the shelf height and remaining space are shown."Always show all variations" explodes the UI.Planner
D13No 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
D14htdocs/ 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
D15Empty 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)

  1. x >= 0, y >= 0.
  2. x, w, y, h are whole numbers of boxes.
  3. w >= 1, h >= 1.
  4. y + h <= shelfUnits.
  5. No two blocks overlap: for all pairs, not
  6. (a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h).
  7. No duplicate ids.
  8. unit > 0, gap >= 0.

Total shelf width in boxes = max(x + w) over blocks, or 4 when empty.

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:


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.

idnameslots
singleOne square1
quadFour squares4
hero-topWide top + two below3
hero-leftTall left + two stacked right3
bandsWide / tall / two small4
sixSix mixed6
mosaicSeven mixed (closest to reference art)7
focusBig + four small + wide base6
// 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

5.2 Pattern picker

Anchored popover (never a centred modal — it must point at the insertion seam):

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)

5.5 Resize

5.6 Delete

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%; }

5.8 Undo / redo


6. Stack

Front end

ConcernChoice
DeliveryStatic files in src/web, served directly by .NET — no build step
LanguageModern JavaScript, ES modules, JSDoc type comments
FrameworkNone. Small render functions + full re-render on commit
StylingHand-written CSS + custom properties for tokens
StateVanilla store module (doc, history, selection) with a subscribe()
DragHand-rolled pointer events in useShelfDrag.js
AnimationCSS transitions on left/top/width/height
IconsInline SVG in the markup
Idscrypto.randomUUID()
Unit testsDeferred; 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

ConcernChoice
RuntimeASP.NET Core .NET 10, minimal APIs
StorageSQLite. Provider chosen at M2 — Microsoft.Data.Sqlite is preferred over EF Core because it is one small NuGet package (D13 requires asking first)
API docsBuilt-in Microsoft.AspNetCore.OpenApi (MapOpenApi) — deferred until M2
ValidationC# DTOs + explicit invariant checks (section 3), 422 on failure
SPA hostingUseDefaultFiles + UseStaticFiles + explicit fallback to index.html (/api/* stays 404)
Testsdotnet 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:


9. Milestones

M1 — Shelf editor + pattern picker (the only thing to build now)

Scope:

  1. Shelf renders from a LayoutDoc, centered, overflow-x: auto.
  2. 3px dashed outlines on empty blocks; toggleable guide overlay (1-box grid, 4-box
  3. square divider).
  4. Pattern picker with live thumbnails and fit filtering.
  5. Add-left / add-right / append with correct shifting.
  6. Drag with snapping, ghost preview, collision rejection, group-rigid moves.
  7. Resize width/height with snapping.
  8. Delete, duplicate block (Cmd/Ctrl+D), close gap.
  9. Undo/redo.
  10. Persist to localStorage and restore on reload.

Acceptance criteria:

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:


11. Guardrails for the implementer

  1. Do not introduce a 2D grid library. See section 6.
  2. Do not switch patterns to CSS grid-template-areas. Patterns are data.
  3. Do not add nesting, rows, or freeform canvas.
  4. Do not store pixels in the model. Boxes only; unit and gap are render-time.
  5. Do not put geometry logic in UI code. It belongs in model/geometry.js.
  6. Do not normalise blocks into DB tables.
  7. Do not use border for guides or outlines.
  8. Do not write to wwwroot/ by hand; it is generated from src/web/.
  9. Do not add any dependency. HTML, CSS, JS and .NET only (D13); ask if a package
  10. ever seems unavoidable.
  11. 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.

#QuestionAnswer
1Shelf heightFixed at 4 boxes for the whole shelf (D2 confirmed).
2ThemeDark-only for now (section 10). Light theme is an M5 item.
3GuidesDashed block outlines always on; the 1-box / 4-box guide overlay is a toggle.
4LayoutsOne layout in M1. Multiple named layouts arrive in M2.
5Block contentTruly empty blocks — dashed outline plus the centered size badge. No Slot 1 labels.
6Persistence targetLocal-only for now (localStorage in M1); the API leaves room for accounts later.
7ExportStatic HTML, inlined CSS and no JS (M4).