Blazor app menu

From IntentArchitect/Intent.Modules.NET · View interactive version

Blazor app menu is an AI agent skill from the GitHub repository IntentArchitect/Intent.Modules.NET. Populates MainLayoutHeader.razor, MainLayoutSider.razor, MainLayoutFooter.razor, and the Profile menu component (e.g. MainLayoutProfile.razor), either from a natural-language description of the app's menu structure or from modeled Navigation Target Ends (placement resolved from each association's ow

How to use this skill

Skill file

Purpose

Every Blazor project generated by this solution's Intent Architect module has a MainLayout.razor that is intentionally thin — it just composes <MainLayoutHeader/>, <MainLayoutSider/>, @Body (plus <MainLayoutFooter/> when a Footer is modeled), inside whatever provider/wrapper markup (e.g. <MudLayout>, <MudMainContent>) the first scaffold generation used. The actual menu content lives as literal, hand-authored markup inside those component files, plus (when a Profile Menu element is modeled) a Profile menu component composed into the Header. There is deliberately no shared nav-item data model — never a NavItem/AppNav list feeding a generic loop.

MainLayout.razor itself, MainLayoutHeader.razor, MainLayoutSider.razor, MainLayoutFooter.razor, and (when modeled) the Profile menu file are each scaffolded exactly once by Software Factory (OverwriteDisabled) — MainLayout.razor fully composed from whichever of Header/Sider/Footer/Profile exist at that time, the others with placeholder/minimal content only (Software Factory no longer sorts Navigation Target Ends into per-region content itself — that resolution is this skill's job, see Step 2). After that first generation, keeping MainLayoutHeader.razor/MainLayoutSider.razor/MainLayoutFooter.razor/the Profile file's literal markup in sync with navigation changes, and keeping MainLayout.razor's Header/Sider/Footer component references in sync as those regions are added, removed, or created by this skill, is entirely this skill's job.

This skill turns a menu description — either free-text prose, or the consolidated Navigation Target End context (route, roles/policies, and each item's verbatim placement comment) Software Factory attaches to MainLayout.razor — into that literal markup, correctly gated by <AuthorizeView> when (and only when) the target project actually has authentication.


MANDATORY: Read Before Making Any Change

STOP — you MUST read all of the following before writing anything:

  1. app-main-layout-sample.razor — MainLayout's own region-component composition (Header/Sider/conditional Footer/@Body), relevant whenever you're reconciling that file per Step 7
  2. app-sider-noauth-sample.razor — Sider with no auth gating
  3. app-sider-auth-sample.razor — Sider with a mix of gated and ungated items
  4. app-header-auth-sample.razor — Header with a gated nav item plus the unconditional Profile-component composition
  5. app-user-menu-auth-sample.razor — the real Auth Profile menu: modeled Profile-region items plus the fixed Login/Register-vs-Manage/Logout split that lives INSIDE this file (not the Header), relevant whenever you're populating that file per Step 6
  1. Components/Layout/MainLayout.razor (+ .razor.cs) — read its current region-component composition before touching anything else (see Step 7). Its attached AI context is now the single, consolidated list of every Navigation Target End modeled against this Layout (route, roles/policies, and each item's verbatim placement comment) — it is NOT pre-split per region. None of the region files below carry their own AI context any more; you resolve region placement yourself (Step 2) from this one list before populating any of them. That same AI context also states plainly whether theming is enabled or disabled for this Layout — read that fact alongside the navigation list, before Step 4 (it determines whether MainLayoutHeader.razor should carry a <ThemeToggle />).
  2. Components/Layout/MainLayoutHeader.razor (+ .razor.cs)
  3. Components/Layout/MainLayoutSider.razor (+ .razor.cs)
  4. Components/Layout/MainLayoutFooter.razor (+ .razor.cs) — only exists if a Footer was modeled, or this skill previously created it (see the create-if-needed rule above)
  5. The Profile menu file — only exists if MainLayout has a modeled Profile Menu child element, or this skill previously created it (see the create-if-needed rule above); the actual filename is {Layout name}{Profile Menu element name}.razor (commonly MainLayoutProfile.razor). Path varies: Components/Layout/ (NoAuth, or WASM NoAuth after path unification), Components/Account/Shared/ (Server Auth), or Layout/ in the .Client project (WASM Auth — kept separate from Components/Layout on purpose, see "WASM Auth specifics" below)
  6. Program.cs (and, for a hosted WASM Auth project, the host project's Program.cs too)

Do not proceed with a partial read. Any of items 2–5 may be missing for this project — modeling Header/Sider/Footer/Profile ahead of time is optional, and this skill does not require it. A missing file is only a problem once Step 2 resolves an item's placement comment to that specific canonical region (Header, Sider, Footer, or Profile): when that happens, CREATE the missing .razor file (and its trivial .razor.cs code-behind) yourself — matching the filename/namespace conventions of MainLayout.razor(.cs) and, where another region file already exists in this project, that sibling's conventions too — then populate it exactly as Steps 3–6 already do for an existing file, taking its fixed structural chrome verbatim from the matching sample (never improvised). Only fall back instead of creating when an item's placement comment doesn't resolve to any of the four canonical regions at all (see Step 2's "Region resolution"). Not all of the target files will be present for every solution before you start — some may remain absent throughout (e.g. no footer or profile content was ever described) and that's fine.

There is no ManageLayout.razor nav duplicate to maintain in current-generation projects — post-login "Manage" pages render inside the normal MainLayout/Sider like any other page, there is no separate static-SSR account layout with its own nav copy. If an older project still has a legacy ManageLayout.razor with its own <aside> nav block, treat it like any other file the context doesn't mention: leave it alone unless the user explicitly asks about it.


Step 1 — Detect the Project's Shape

Before touching any markup, determine two independent facts by inspecting Program.cs:

| Fact | How to tell | Why it matters |

| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| Auth capability | Does Program.cs call AddAuthorizationCore() / AddAuthorization() and AddCascadingAuthenticationState()? | If NO: this is a NoAuth project. <AuthorizeView> has no cascading auth state to consume and must never be introduced. If YES: this is an Auth project and <AuthorizeView> is safe anywhere. |

| Hosting model | Is there a separate .Client project referenced by a host project (ProjectReference + AddInteractiveWebAssemblyComponents), or is it a single project? | Hosted WASM Auth has real account/menu content split across host (static-SSR) and .Client (interactive) — see "WASM Auth specifics" below. Blazor Server and standalone WASM don't have this split. |

Never infer auth capability from the project's _name_ (e.g. don't assume "NoAuth" in a folder name means no auth, or vice versa) — always verify against Program.cs, since this skill may be run against a renamed or copied project.


Step 2 — Parse the Menu Description Into Items

The context you are given is the single source of truth.

Rules:

The context you're given will be prose, not a formal schema, along the lines of:

"The sider menu consists of the following:

- a navigation link to the product list page with route /product-list

- a navigation link to the order list page with route /order-list which requires roles Admin or Write"

For each described link, extract:

| Field | How to extract | Default if unstated |

| ----------------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |

| Label | The page/entity name mentioned (title-case it: "product list" → "Product List") | Required — ask if truly ambiguous |

| Href | The literal route given (e.g. ` /product-list `) | Required |

| Region | The item's own placement comment, matched against the closed vocabulary Header/Sider/Footer/Profile (e.g. "sider"/"side menu" → Sider, "footer" → Footer, "profile"/"account menu" → Profile) — see "Region resolution" below | Profile if judged profile/account/auth-related, else Sider — see "Region resolution" |

| Icon | Only if explicitly described (e.g. "with a home icon") — map to the closest Icons.Material.Filled.* member | None — omit the Icon attribute entirely rather than guessing |

| Authorization | Phrases like "requires roles X or Y", "requires policy X", "for logged-in users only" / "requires authentication" | None (item renders unconditionally) |

Region resolution (CRITICAL)

Software Factory no longer pre-sorts items into region files — MainLayout.razor's attached context is the same full list regardless of which region file you're about to populate. Before extracting Label/Href/Icon/Authorization for a given file (e.g. MainLayoutSider.razor), you must first resolve which of the items in that full list actually belong there:

Authorization phrase mapping:

If the target project is NoAuth (per Step 1) and the context nonetheless describes a role/policy/login requirement for an item: render the item unconditionally anyway (there is no auth infrastructure to gate it with) and say so plainly in your response — do not silently drop the item, and do not add AddAuthorizationCore/AddCascadingAuthenticationState to Program.cs to make the gating "work". That is a much bigger change than a menu edit and is out of scope for this skill.


Step 3 — Populate `MainLayoutSider.razor`

Follow app-sider-noauth-sample.razor or app-sider-auth-sample.razor depending on Step 1's result.

Rules:

Region source-of-truth and "mandatory" sync (CRITICAL)

This skill must be region-scoped: a nav item may only be generated into a given region/menu when its placement comment resolves to that region (per Step 2's "Region resolution").

Rules:


Step 4 — Populate `MainLayoutHeader.razor`

Follow app-header-auth-sample.razor. Three independent concerns live in this file — do not conflate them:

  1. Fixed chrome — preserve exactly as-is, in both Auth and NoAuth projects: the drawer-toggle (<span onclick="navDrawer.toggle()"><MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" /></span>), the brand MudButton, and MudSpacer. None of these carry OnClick/OnToggle EventCallback parameters in the current scaffold — do not add any; the drawer opens via navDrawer.toggle() JS interop, with no code-behind wiring in MainLayoutHeader.razor.cs. This chrome applies identically when creating MainLayoutHeader.razor from scratch (per the MANDATORY section) — copy it verbatim from app-header-auth-sample.razor, never improvised.

1a. <ThemeToggle /> — conditional on this Layout's theming context, not unconditional chrome: MainLayout.razor's attached AI context (see the MANDATORY section) states plainly whether theming is enabled or disabled for this Layout. Include a bare <ThemeToggle /> only when it's enabled; omit it entirely when disabled. Never add one to a no-theming project's header, and never remove one from a themed project's header. When present, it carries no OnClick/OnToggle wiring — it toggles internally, with no code-behind involvement.

  1. The Profile component slot — if the Profile menu file exists for this Layout (e.g. MainLayoutProfile.razor, whether modeled or created directly by this skill — see the MANDATORY read above), MainLayoutHeader.razor must include an unconditional reference to it
  2. Any Header-placed nav items the context describes: render as <MudButton Href="..." Color="Color.Inherit">Label</MudButton> (MudAppBar is not a MudNavMenu, so MudNavLink doesn't fit here), positioned between the brand button and <MudSpacer />. Gate exactly like a Sider item (Step 3's AuthorizeView rules), in a NoAuth project never gate at all.

Region source-of-truth and "mandatory" sync (CRITICAL)

Only add/ensure header nav items whose placement comment resolves to Header (per Step 2's "Region resolution") — explicitly, or via the missing-file fallback.

Rules:


Step 5 — Populate `MainLayoutFooter.razor`

Only touch this file if the context explicitly describes footer content. Otherwise leave it as the empty placeholder — do not invent footer content. The scaffolded file's body may literally be the placeholder comment // Content to be generated (not real markup at all) until you populate it — that's expected on first read, not a sign something's broken. If MainLayoutFooter.razor doesn't exist yet and an item's placement comment resolves to Footer (per Step 2), create it (and its trivial .razor.cs code-behind, per the MANDATORY section) starting from that same essentially-empty state — there is no bundled sample for Footer, none is needed, since the deterministic scaffold itself is trivial. If footer items are described, apply the same per-item rules as Step 3 (plain links, AuthorizeView-gated only in Auth projects, only for items with a stated requirement), rendered as plain <a>/MudLink elements rather than MudNavLink (footers typically aren't route-highlighted navigation).

Region source-of-truth and "mandatory" sync (CRITICAL)

Only add/ensure footer items whose placement comment resolves to Footer (per Step 2's "Region resolution") — explicitly, or via the missing-file fallback.

Rules:


Step 6 — Populate the Profile Menu file (e.g. `MainLayoutProfile.razor`)

This file exists whenever a Profile Menu was modeled (visible alongside Header/Sider/Footer in the User Interface designer) or whenever this skill has created it directly (see the MANDATORY section) because an item's placement comment resolved to Profile — modeling it ahead of time is optional, not a prerequisite; if neither is true, there is no Profile menu and this step doesn't apply. When present, it's scaffolded exactly like Steps 3-5: a Razor file (named {Layout name}{Profile Menu element name}.razor, e.g. MainLayoutProfile.razor, colocated with the other layout files per the path rules in "MANDATORY" above) generated once with OverwriteDisabled (or, if this skill created it from scratch, started the same way), with a bare, self-closing <UserMenu /> placeholder as its only content — from then on you own filling it in. When creating it fresh, take the fixed <Trigger>/dropdown chrome verbatim from app-user-menu-auth-sample.razor, never improvised.

UserMenu is a shared presentational component shipped from the UI-component library (not auth-specific — it carries no auth knowledge itself): a circuit-free <details>-based dropdown taking a Title (string, defaults to "Account menu"), a Trigger render fragment (the closed-state icon/content), and a ChildContent render fragment (the dropdown's items). It works identically on static-SSR Account pages and interactive pages.

MANDATORY: Any generated <UserMenu> markup MUST include a <Trigger>...</Trigger> node (as shown in app-user-menu-auth-sample.razor). The trigger is not optional; without it the menu surface is incomplete and may render incorrectly.

This menu is populated from Navigation Target Ends whose placement comment resolves to Profile (Step 2). It's primarily meant for profile/account-related pages (e.g. "My Profile", "Settings"), but it can hold any navigable page the context/model assigns to it — apply the same Label/Href/Icon/Authorization extraction as Step 2.

Do not add Login/Register/Manage/Logout by default, even in Auth projects. Only add those if they are present in the provided context (or explicitly modeled into the Profile region).

If the existing Profile menu file already contains a fixed auth block (e.g. Login/Register vs Logout) from past runs, do not treat that as a requirement. Keep or remove it only if the user's current context requires it; otherwise preserve existing content and only add the explicitly described items.

<AuthorizeView>
<Authorized>
<UserMenu>
<Trigger>...</Trigger>
<ChildContent>
<MudStack Spacing="0">
<!-- one item per modeled Profile nav link -->
<!-- fixed Logout form, always last -->
</MudStack>
</ChildContent>
</UserMenu>
</Authorized>
</AuthorizeView>

<AuthorizeView>
<NotAuthorized>
<UserMenu Title="Account">
<Trigger>...</Trigger>
<ChildContent>
<MudStack Spacing="0">
<!-- fixed Login + Register buttons -->
</MudStack>
</ChildContent>
</UserMenu>
</NotAuthorized>
</AuthorizeView>
<form method="post" action="/Account/Logout">
<AntiforgeryToken />
<input type="hidden" name="ReturnUrl" value="@ReturnUrl" />
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Text" Color="Color.Inherit" FullWidth="true">
Logout
</MudButton>
</form>

This requires a ReturnUrl code-behind member — if not already present, add to the file's @code block:

[CascadingParameter]
private HttpContext? HttpContext { get; set; }

private string? ReturnUrl => HttpContext is null ? null : $"{HttpContext.Request.Path}{HttpContext.Request.QueryString}";
<MudButton Href="/Account/Login" Variant="Variant.Text" Color="Color.Inherit" FullWidth="true">Login</MudButton>
<MudButton Href="/Account/Register" Variant="Variant.Text" Color="Color.Inherit" FullWidth="true">Register</MudButton>

Region source-of-truth and "mandatory" sync (CRITICAL)

Only add/ensure items whose placement comment resolves to Profile (per Step 2's "Region resolution") — explicitly, or via the missing-file fallback.

Rules:


Step 7 — Sync `MainLayout.razor`'s Composition

MainLayout.razor is scaffolded exactly once by Software Factory (OverwriteDisabled), the same as Header/Sider/Footer/Profile — it used to be regenerated deterministically on every run (so a Sider/Footer being added or removed in the model was reflected automatically), but that's no longer the case. From the first generation onward, keeping it in sync as regions are added or removed is this skill's job too, exactly like Steps 3–6 own the other layout files.

This ownership is deliberately narrow — follow app-main-layout-sample.razor:


Step 8 — CRITICAL: Ensure Idempotence (No Duplicate Items)

When this skill is run repeatedly (or when it is run after a menu file already contains some items), it MUST NOT create duplicates.

Before inserting any new menu item into a region file, you MUST check whether an equivalent item already exists in that same file/region.

De-duplication key (preferred order)

Treat a menu item as a duplicate if any of the following match:

  1. Same route/href (preferred):
  1. Same label (fallback):

De-duplication scope

Mandatory behavior


Forbidden


Definition of Done

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.