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 slug | Card position | Label in admin |
|---|---|---|
home_bento_1 | row1[0] | Homepage Bento — Top row, left |
home_bento_2 | row1[1] | Homepage Bento — Top row, middle |
home_bento_3 | row1[2] | Homepage Bento — Top row, right |
home_bento_4 | row2.wide | Homepage Bento — Middle row, wide |
home_bento_5 | row2.narrow | Homepage Bento — Middle row, narrow |
home_bento_6 | row3[0] | Homepage Bento — Bottom row, left |
home_bento_7 | row3[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
| Surface | Where | Auth |
|---|---|---|
Storefront home / | Seven cards, fed by seven GET banners/serve/:slug calls | Public |
| Storefront tracking BFF | /api/store/banners/events/impression, /click | Same-origin, always 202 |
| Admin Placements | /dashboard/placements | Placements_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 seed | pnpm --filter @nano-store/db db:seed:placements | Operator with DB access |
Operator Runbook
Recommended image size per slot
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.
| Slot | Position | Recommended W × H | Ratio |
|---|---|---|---|
home_bento_1 | Top row, left | 1440 × 1800 | 4:5 |
home_bento_2 | Top row, middle | 1440 × 1800 | 4:5 |
home_bento_3 | Top row, right | 1920 × 2400 | 4:5 |
home_bento_4 | Middle row, wide | 2048 × 1024 | 2:1 |
home_bento_5 | Middle row, narrow | 2048 × 3250 | 29:46 |
home_bento_6 | Bottom row, left | 1440 × 720 | 2:1 |
home_bento_7 | Bottom row, right | 1440 × 720 | 2: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
- 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. - 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).
- Link the placement. On the campaign page, add
home_bento_nto the campaign. - Assign the banner to that placement.
- 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
bannerscache 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_leftandhome_promo_rightinactive 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
| Situation | Card 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 guard | Fixture (whole card) |
| Banner served, link missing or unsafe | Banner, rendered without a link; never the fixture's link |
Banner served, no bgColor | Banner, with the fixture's background colour (the one permitted inheritance) |
| Banner served, mobile image fails the guard | Banner 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.
| Value | Guard |
|---|---|
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. |
| Image | Absolute 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 colour | Must match ^#[0-9a-fA-F]{3,8}$; otherwise it parses to null and the fixture colour applies. |
| New-tab link | target="_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.
- Backend. Deploy, then run the seed:
pnpm --filter @nano-store/db db:seed:placementsseedPlacementsis not part ofseed-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 onlayoutType,maxBanners,allowPartialRenderorisActive. It never overwrites. - 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. - Storefront cache. Purge the
bannerstag through the admin cache revalidate route, or wait 300 seconds. - Storefront deploy. Any time. This deploy is also the fix for the parser bug below; until it ships, no CMS banner renders.
- Admin deploy. Independent.
Preconditions
- Tracking throttle. The storefront must reach the API over a direct hop, with
TRUSTED_PROXY_HOPSat 1 or more (the variable is in the storefront.env.example; the API itself hard-codestrust proxyto 1 inmain.ts). Otherwise all visitors share onePUBLIC_TRACKING_EVENTthrottle 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 thex-internal-client-ippair (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_URLorigin must equal the storefront'sNEXT_PUBLIC_ASSET_ORIGIN. Only/public/…images on that origin render. Admin banner uploads are stored underpublic/landing/, so they pass. Confirm thelandinguploads 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) anditems, and no longer requiresgeneratedAtorslots. - The item schema keeps
bgColor,displayOrderandctaOpenNewTab. - 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
| Condition | Storefront | Admin |
|---|---|---|
PLACEMENT_NOT_FOUND (404) on serve | Card shows fixture, no log | Placement not seeded or inactive |
| Serve 5xx, timeout, 429, parse failure | Card shows fixture, logged via logDegraded | None |
503 SYSTEM_MAINTENANCE_ACTIVE | Propagates to error.tsx | None |
| Tracking 4xx or queue down | Swallowed, BFF answers 202 | Event missing in Events |
Placements_READ 403 on analytics filter | None | Filter shows "Any" only |
| Invalid slug in create dialog | None | Inline error "Slug may contain lowercase letters, numbers, hyphens and underscores only" |
Known Follow-ups
Recorded debt, none of it blocking:
- Backend
tobound.GET admin/banner-analytics/eventstreatstoas$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.localPatternsin the storefrontnext.config.ts. packages/dbhas notestscript.seed-placements.spec.ts(andcategory.spec.ts) run in no gate. They usenode:testviatsx.- 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.tsdoes not refuse a dot-segment walk pastuploads/. It is guarded insafe-banner.ts; the root fix inasset-url.tsremains. - Backend write-time validation of
ctaUrlandbgColordoes 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-ippair, and has no body-size cap. - Unused storefront components (
banner-slot,hero-carousel,promo-banners) and unusedhero-*.pngfiles remain. - Pre-existing storefront gate failures, unrelated to this change: two
header.test.tsxfailures and three parity items (shop-by-brand-section,guest-checkout-dialog,ui/dialog, plus one orphaned test).
See Also
Navigation API Reference
Endpoint reference for the admin and storefront navigation menu — contracts, error codes, and integration rules.
Home Bento Dynamic Backend Architecture
Internal architecture of the home bento feature across backend seed, storefront and admin — composition, data model, invariants, and configuration.