Nano Store - Ecommerce Docs
Developer Resourcesnavigation

Navigation Feature Overview

The admin-managed storefront header menu — what it does, who edits it, the business rules, and how each repo behaves.

Navigation Module — Feature Overview

1. Purpose

An admin builds the storefront header menu (one model for desktop mega-menu and mobile menu). The backend stores it, validates it against the live catalog, and serves it to the storefront. The storefront never hard-codes the menu; it renders what the API returns and builds the links itself.

There is exactly one menu, with key header.


2. Surface Matrix

SurfacePathAuth
Admin readGET /api/admin/navigationJWT + Navigation_READ
Admin replacePUT /api/admin/navigationJWT + Navigation_UPDATE
Storefront readGET /api/mobile/navigationNone (@Public()), IP-throttled
Admin UI/dashboard/navigation (Happy-shop-admin)Navigation_READ to open, Navigation_UPDATE to save
Storefront headerheader / primary nav (nano-store-frontend)None

3. What an Item Is

A menu is an ordered list of at most 16 top-level items. Each top-level item may carry up to 30 manual children. Depth is fixed at two levels. A menu holds at most 200 rows in total.

targetKindLinks toNotes
systemA fixed storefront pagesystemKey: all_products (All Products), brands (Brands), sale (On Sale)
categoryA category pageDepth 0 (root) or depth 1 (subcategory). Deeper categories are rejected.
brandA brand page
seriesA brand page filtered to the series/brands/<brand>?series=<slug>
urlA site-relative path or an absolute https: URLLabel required

Children mode

childrenModeBehavior
nonePlain link, no dropdown
autoThe backend expands live children at read time: the visible subcategories of a root category, or the visible series of a brand. Only valid on brand targets and root (depth-0) category targets.
manualThe admin lists children explicitly (each child is a link with a category, brand, series or url target; children cannot be system items and cannot have children of their own). A manual item with zero children is served as a plain link.

Labels

A label is optional for catalog targets: when null, the live target name is used (system items fall back to their default label). A label, when set, is trimmed, NFC-normalised, 1 to 40 characters, and contains no control or format characters (this rejects bidi overrides and zero-width characters). An empty string is rejected, never coerced to null.


4. Business Rules

  • The menu has exactly one top-level item per system key. System items are top-level only, cannot have children, and cannot be added or removed by the admin UI (the kind is locked).
  • Saving replaces the whole menu in one transaction. Item ids change on every save; the admin adopts the ids from the response.
  • Saving requires the version last read. A mismatch is a 409 NAVIGATION_VERSION_CONFLICT; the second of two concurrent editors loses and must reload.
  • Hidden targets are accepted on save but are not served. Duplicate targets are allowed.
  • A depth-1 category link is served only when its parent has at least 2 visible subcategories. The storefront has no route for the child otherwise, so the backend omits the link (and emits no auto children for a root with fewer than 2 visible children).
  • A fully disabled menu is valid: the API returns items: [].
  • Items whose target is deleted, invalid or hidden are omitted from the storefront response.

Target status (admin view)

The admin response marks each row with targetStatus:

StatusMeaningSave
okTarget is live and linkableAllowed
hiddenStorefront will not render the item as configuredAllowed
deletedTarget (or a series' owning brand) is soft-deleted or has no current slugBlocked until fixed or removed
invalidThe catalog changed so the item would now fail a PUT ruleBlocked until fixed or removed

The admin client adds a local pending state for rows edited since load. It never crosses the wire.


5. Admin Builder (/dashboard/navigation)

  • Drag-and-drop ordering with dnd-kit, including a keyboard sensor for keyboard-only reordering.
  • Entity pickers for categories, brands and series.
  • Client-side validation mirroring the backend rules (label length by code points, URL rules, 16 top-level, 30 children per item, 200 total). Save is disabled while any row is deleted or invalid.
  • A custom role given Navigation_UPDATE must also hold Categories_READ, Brands_READ and BrandSeries_READ, or the pickers cannot load.
  • After a successful save the admin invalidates the storefront cache with the navigation.changed event.

6. Storefront Behavior

  • The header reads GET /api/mobile/navigation through the Next data cache (revalidate 3600 s, tag navigation).
  • The storefront builds every href itself (src/lib/catalog/nav-href.ts). A depth-1 category uses the two-level route /categories/<parent>/<child>; a series is /brands/<brand>?series=<slug>.
  • An item whose target cannot be turned into a safe href is dropped rather than rendered as a dead link.
  • A dropdown's children (manual or auto) are grouped by target kind, in a fixed order: Shop by category (category), Shop by brand (brand and series), More (url). Order inside a group is the served (admin) order. A group with no linkable items is not rendered. When only one group is non-empty, no headings are shown and the dropdown is a flat list. No API change: the storefront derives the groups from each child's target.kind.
  • The admin shows a note under a manual children list that the storefront groups them by category, brand and more.
  • If the read fails, the storefront renders a fallback of three links: All Products, Brands, On Sale, and reports the nav as degraded.

7. Cache Behavior

  • A menu save emits the navigation storefront tag.
  • Category, brand and brand-series writes also emit navigation, because a rename or hide changes a served link.
  • Product and stock writes do not purge navigation.
  • The storefront must accept the navigation tag before the backend ships (see the deploy order in backend.mdx).

8. Rate Limits

The public read uses RATE_LIMITS.PUBLIC_HIGH_FREQUENCY (300 requests per 60 seconds per IP). Storefront cache-miss requests share the egress IP, which is the same trade-off the category tree makes today.


9. Error UX Mapping

errorCodeAdmin behavior
NAVIGATION_VERSION_CONFLICTKeeps the edits and shows "Navigation changed since you loaded it — reload to see the latest." with a Reload button
NAVIGATION_TARGET_INVALIDMarks every row listed in details.violations; toast "Some items need fixing — see the marked rows."
NAVIGATION_TARGET_NOT_FOUNDSame; the admin re-picks the target
NAVIGATION_LIMIT_EXCEEDEDSame toast; the UI counts rows and blocks before save, so this is a defect signal
NAVIGATION_SYSTEM_ITEMS_INVALIDGeneric "the store pages are out of sync, reload" message; the UI cannot normally reach it
Validation 400 with no NAVIGATION_* code"Could not save — invalid data." (defect signal: the client mirrors the rules)
NAVIGATION_MENU_MISSINGStandard error state; on the storefront, the three-link fallback

See Also