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
| Surface | Path | Auth |
|---|---|---|
| Admin read | GET /api/admin/navigation | JWT + Navigation_READ |
| Admin replace | PUT /api/admin/navigation | JWT + Navigation_UPDATE |
| Storefront read | GET /api/mobile/navigation | None (@Public()), IP-throttled |
| Admin UI | /dashboard/navigation (Happy-shop-admin) | Navigation_READ to open, Navigation_UPDATE to save |
| Storefront header | header / 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.
Link targets
targetKind | Links to | Notes |
|---|---|---|
system | A fixed storefront page | systemKey: all_products (All Products), brands (Brands), sale (On Sale) |
category | A category page | Depth 0 (root) or depth 1 (subcategory). Deeper categories are rejected. |
brand | A brand page | |
series | A brand page filtered to the series | /brands/<brand>?series=<slug> |
url | A site-relative path or an absolute https: URL | Label required |
Children mode
childrenMode | Behavior |
|---|---|
none | Plain link, no dropdown |
auto | The 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. |
manual | The 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
versionlast read. A mismatch is a 409NAVIGATION_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:
| Status | Meaning | Save |
|---|---|---|
ok | Target is live and linkable | Allowed |
hidden | Storefront will not render the item as configured | Allowed |
deleted | Target (or a series' owning brand) is soft-deleted or has no current slug | Blocked until fixed or removed |
invalid | The catalog changed so the item would now fail a PUT rule | Blocked 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
deletedorinvalid. - A custom role given
Navigation_UPDATEmust also holdCategories_READ,Brands_READandBrandSeries_READ, or the pickers cannot load. - After a successful save the admin invalidates the storefront cache with the
navigation.changedevent.
6. Storefront Behavior
- The header reads
GET /api/mobile/navigationthrough the Next data cache (revalidate 3600 s, tagnavigation). - The storefront builds every
hrefitself (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
hrefis 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 (brandandseries), 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'starget.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
navigationstorefront 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
navigationtag before the backend ships (see the deploy order inbackend.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
errorCode | Admin behavior |
|---|---|
NAVIGATION_VERSION_CONFLICT | Keeps the edits and shows "Navigation changed since you loaded it — reload to see the latest." with a Reload button |
NAVIGATION_TARGET_INVALID | Marks every row listed in details.violations; toast "Some items need fixing — see the marked rows." |
NAVIGATION_TARGET_NOT_FOUND | Same; the admin re-picks the target |
NAVIGATION_LIMIT_EXCEEDED | Same toast; the UI counts rows and blocks before save, so this is a defect signal |
NAVIGATION_SYSTEM_ITEMS_INVALID | Generic "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_MISSING | Standard error state; on the storefront, the three-link fallback |