Nano Store - Ecommerce Docs
Developer ResourcesHome Bento Dynamic

Home Bento Dynamic Feature Guide

The seven-card homepage hero bento driven by placements home_bento_1..7, with the operator runbook, deploy steps, safety guards, and known follow-ups.

Feature Overview

The storefront home page opens with a hero bento of seven cards. Each card is driven by its own banner placement, home_bento_1 to home_bento_7. An operator manages the cards in the admin: create a banner, put it in a live campaign, link the campaign to the placement, assign the banner. Every card records impressions and clicks.

Ashmit's static images (/home/hero-bento/bento-*.png) stay as the per-card fallback. A card is either a served banner or its whole fixture, with one exception: the background colour (see Card fallback rules).

The visual layout did not change. Only the data source did.

This feature does not:

  • Add an endpoint, DTO, error code, event, table or migration. It uses the existing banner serve, tracking and admin surfaces.
  • Cover shop-by-brand, which is a product feed and not banners.
  • Enforce one banner per placement when an assignment is created. Rendering enforces it; the admin shows help text.

Position map

Placement slugCard positionLabel in admin
home_bento_1row1[0]Homepage Bento — Top row, left
home_bento_2row1[1]Homepage Bento — Top row, middle
home_bento_3row1[2]Homepage Bento — Top row, right
home_bento_4row2.wideHomepage Bento — Middle row, wide
home_bento_5row2.narrowHomepage Bento — Middle row, narrow
home_bento_6row3[0]Homepage Bento — Bottom row, left
home_bento_7row3[1]Homepage Bento — Bottom row, right

The map lives in one place in code: HERO_BENTO_PLACEMENTS in the storefront file src/lib/data/hero-bento.ts. The backend seeds the same seven slugs.

Surface Matrix

SurfaceWhereAuth
Storefront home /Seven cards, fed by seven GET banners/serve/:slug callsPublic
Storefront tracking BFF/api/store/banners/events/impression, /clickSame-origin, always 202
Admin Placements/dashboard/placementsPlacements_READ / _CREATE / _UPDATE
Admin Banners and Campaigns/dashboard/banners, /dashboard/campaigns/[publicId]JWT, backend-guarded
Admin Banner Analytics/dashboard/banner-analytics (Stats and Events tabs)BANNER_ANALYTICS_READ
Backend seedpnpm --filter @nano-store/db db:seed:placementsOperator with DB access

Operator Runbook

Sizes cover the widest rendered box across breakpoints at about 2x, not the desktop box alone. The admin shows the same figure as Recommended W×Hpx · ratio in the assign dialog and the placement header.

SlotPositionRecommended W × HRatio
home_bento_1Top row, left1440 × 18004:5
home_bento_2Top row, middle1440 × 18004:5
home_bento_3Top row, right1920 × 24004:5
home_bento_4Middle row, wide2048 × 10242:1
home_bento_5Middle row, narrow2048 × 325029:46
home_bento_6Bottom row, left1440 × 7202:1
home_bento_7Bottom row, right1440 × 7202:1

Copy is baked into the image. Keep text in the centre safe area. The banner form allows a primary image up to 5 MB and an optional mobile crop up to 3 MB.

Put a banner on a card

  1. Create the banner in Banners. Upload an image at the slot's recommended size. Set a headline and a link (ctaUrl) if the card should be clickable. Optionally set a background colour and an alt text.
  2. Create a campaign and activate it. Its dates must bound the current time. Add no device, login, new-visitor or referrer targeting rules (see Targeting).
  3. Link the placement. On the campaign page, add home_bento_n to the campaign.
  4. Assign the banner to that placement.
  5. Wait. The backend serve cache lasts up to 60 seconds. The storefront then re-caches for up to 300 seconds. To skip the storefront wait, purge the banners cache tag through the admin cache revalidate route.

Slot rules

  • One banner per slot. The card shows the banner with the lowest display order, then the highest weight. Other assigned banners stay assigned and are not shown. The storefront uses only the first banner even if an operator raises maxBanners.
  • Fallback assignments live in an always-on campaign. An assignment marked as fallback only fills a card when its campaign is live. Put fallback banners in a campaign that never ends.
  • Do not rename a bento slug. The storefront requests each slug by name. A rename detaches the card, which then shows its fixture. The admin edit dialog shows the slug read-only; the backend PATCH still accepts a rename, so do not do it through the API either.
  • Create slugs with underscores. The admin create dialog keeps _ in a slug and accepts only lowercase letters, numbers, hyphens and underscores.
  • Deactivate the legacy placements. After the seed, set home_hero, home_promo_left and home_promo_right inactive in Placements. The storefront no longer requests them, so they show nowhere. The seed does not remove them because they may hold campaign history.

Targeting rules do not apply

The storefront fetches banners anonymously and shares one cached result between all visitors. Device, login, new-visitor and referrer targeting therefore never match for bento placements. Only time-based scheduling works. Recurrence timezone handling is an existing backend caveat; check scheduled windows after the first activation.

Analytics

  • Events tab shows impressions and clicks the same day, filtered by placement. Event Type is single-select (Impression or Click).
  • Stats tab is compiled daily in UTC. Today's activity appears in Events, and in Stats from the next day.
  • The placement filter applies to both tabs and survives a tab switch and a change of Event Type. If the admin user lacks Placements_READ, the filter offers only "Any" and the page still renders.
  • Counts are unverified signals. Tracking events can be forged by any client (existing behaviour).

Card fallback rules

SituationCard shows
Placement not seeded, inactive, or API error (404, 5xx, timeout, schema failure)Fixture
Placement active, no eligible banner (banners: [])Fixture
Banner's primary image fails the image guardFixture (whole card)
Banner served, link missing or unsafeBanner, rendered without a link; never the fixture's link
Banner served, no bgColorBanner, with the fixture's background colour (the one permitted inheritance)
Banner served, mobile image fails the guardBanner with the primary image only
Maintenance (503 SYSTEM_MAINTENANCE_ACTIVE)Error page, not fixtures

A failed fetch during a cache regeneration leaves that card on its fixture until the next revalidation, up to 300 seconds.

Storefront Safety Guards

The backend stores ctaUrl, bgColor and image URLs as free strings. The storefront is the only place they are validated.

ValueGuard
Link (ctaUrl)Site-relative path (/sale) or absolute https: URL without credentials. Refused: javascript:, data:, mailto:, plain http:, //host, /\host, control characters, user@host tricks. A refused link renders the card unlinked.
ImageAbsolute https: URL on NEXT_PUBLIC_ASSET_ORIGIN or one of the fixed hosts (lh3.googleusercontent.com, platform-lookaside.fbsbx.com, cdn.example.com). Plain http: only for the configured asset origin itself (local development). No credentials, no .svg, no non-default port on fixed hosts. On the asset origin the path must be under /public/, checked after repeated URL-decoding and separator collapse, with any . or .. segment refused. Site-relative paths never pass.
Background colourMust match ^#[0-9a-fA-F]{3,8}$; otherwise it parses to null and the fixture colour applies.
New-tab linktarget="_blank" always carries rel="noopener noreferrer".

The same link guard also protects the existing BannerCard.

Deploy Steps

Order does not matter between repos. Before the seed runs, the storefront gets seven 404s and shows fixtures, which equals the page today.

  1. Backend. Deploy, then run the seed:
    pnpm --filter @nano-store/db db:seed:placements
    seedPlacements is not part of seed-prod, so this is a manual step. Read the log: it lists inserted and already-present slugs, and warns when an existing row differs from the seed on layoutType, maxBanners, allowPartialRender or isActive. It never overwrites.
  2. Admin placement list cache. Flush the admin placement list cache (placements:admin:list:*) or wait one TTL, or the new rows do not appear in Placements.
  3. Storefront cache. Purge the banners tag through the admin cache revalidate route, or wait 300 seconds.
  4. Storefront deploy. Any time. This deploy is also the fix for the parser bug below; until it ships, no CMS banner renders.
  5. Admin deploy. Independent.

Preconditions

  • Tracking throttle. The storefront must reach the API over a direct hop, with TRUSTED_PROXY_HOPS at 1 or more (the variable is in the storefront .env.example; the API itself hard-codes trust proxy to 1 in main.ts). Otherwise all visitors share one PUBLIC_TRACKING_EVENT throttle bucket and excess events are dropped silently with 429 (roughly 85 home views per minute on the 600 per 60 seconds tier). The storefront tracking BFF does not forward the x-internal-client-ip pair (see follow-ups), so the owner must confirm in production that the API sees distinct visitor addresses. Not verified in this documentation pass.
  • Image origin. The admin's NEXT_PUBLIC_API_URL origin must equal the storefront's NEXT_PUBLIC_ASSET_ORIGIN. Only /public/… images on that origin render. Admin banner uploads are stored under public/landing/, so they pass. Confirm the landing uploads bucket is public in production.

Fixed Integration Bug

The storefront serve parser required generatedAt. The backend sends servedAt. Every serve response failed the schema, getBanners swallowed the error, and every slot rendered its fallback, so no CMS banner had ever rendered on the storefront, with every test green because fixtures were written from the parser, not from the DTO.

Fixed in the storefront:

  • The envelope now reads servedAt (optional) and items, and no longer requires generatedAt or slots.
  • The item schema keeps bgColor, displayOrder and ctaOpenNewTab.
  • Parse and fetch failures other than 404 are reported through logDegraded, so a repeat is visible in the server log.
  • Test fixtures are rebuilt from the backend DTO, with one test parsing a payload shaped like BannerServeResponseDto.

Error UX Mapping

ConditionStorefrontAdmin
PLACEMENT_NOT_FOUND (404) on serveCard shows fixture, no logPlacement not seeded or inactive
Serve 5xx, timeout, 429, parse failureCard shows fixture, logged via logDegradedNone
503 SYSTEM_MAINTENANCE_ACTIVEPropagates to error.tsxNone
Tracking 4xx or queue downSwallowed, BFF answers 202Event missing in Events
Placements_READ 403 on analytics filterNoneFilter shows "Any" only
Invalid slug in create dialogNoneInline error "Slug may contain lowercase letters, numbers, hyphens and underscores only"

Known Follow-ups

Recorded debt, none of it blocking:

  • Backend to bound. GET admin/banner-analytics/events treats to as $lte new Date(to) (00:00Z) although the DTO documents an inclusive end. The admin sends end-of-day as a workaround, which makes an exactly 90-day range exceed the 90-day cap (the admin shows a toast).
  • No images.localPatterns in the storefront next.config.ts.
  • packages/db has no test script. seed-placements.spec.ts (and category.spec.ts) run in no gate. They use node:test via tsx.
  • Dead admin AdSense code. The backend has no AdSense module. The tab is removed from the campaign detail page (the component file is kept), but the tab component, fetchers and actions remain.
  • Storefront asset-url.ts does not refuse a dot-segment walk past uploads/. It is guarded in safe-banner.ts; the root fix in asset-url.ts remains.
  • Backend write-time validation of ctaUrl and bgColor does not exist; the storefront guards are the only check.
  • One banner per placement is not enforced at assignment time.
  • Backend Redis serve cache is not invalidated on admin writes or schedule boundaries (up to about 60 seconds plus 300 seconds on the storefront).
  • Storefront BFF tracking does not send the x-internal-client-ip pair, and has no body-size cap.
  • Unused storefront components (banner-slot, hero-carousel, promo-banners) and unused hero-*.png files remain.
  • Pre-existing storefront gate failures, unrelated to this change: two header.test.tsx failures and three parity items (shop-by-brand-section, guest-checkout-dialog, ui/dialog, plus one orphaned test).

See Also