Micro-frontend standard¶
This page sets the rules for building Blazor micro-frontends and composing them into a ConnectSoft shell. It is written for engineers who work on the Shell, micro-frontend and UIKit templates and on products generated from them. Component-level rules are in Blazor.
How composition works¶
A micro-frontend is a Razor class library that owns a product slice: its pages, its components and its calls to one backend. A shell is a Blazor Server host that composes micro-frontends and owns the chrome: layout, navigation, identity, theme and preferences.
flowchart LR
Shell["Shell host (Blazor Server)"] -->|AdditionalAssemblies| MfeA["Orders micro-frontend (RCL)"]
Shell -->|AdditionalAssemblies| MfeB["Customers micro-frontend (RCL)"]
MfeA --> Contracts["Shell.Contracts and Shell.Services.Abstractions"]
MfeB --> Contracts
Shell --> Contracts
MfeA -->|ServiceModel or API client package| OrdersApi["Orders service"]
MfeB -->|ServiceModel or API client package| CustomersApi["Customers service"]
Shell -.->|iframe, legacy only| Legacy["Legacy external app"]
ConnectSoft.Blazor.Shell.Contractsholds dependency-free composition types: navigation items, notifications, preferences and theMfeEventfamily.ConnectSoft.Blazor.Shell.Services.Abstractionsholds the interfaces a micro-frontend consumes from the shell.- Backend request and response types live in the owning service's
*.ServiceModelpackage, never in the shell contracts.
Rules¶
CS-UI-021: Compose micro-frontends in process on InteractiveServer¶
Severity: major · Applies to: blazor, template · Enforced by: manual (target: ENF-053) · Status: active
Why¶
One hosting model keeps authentication, theming, preferences, telemetry and tests the same in every product. In-process Razor class libraries share the shell's circuit and services, so a micro-frontend gets the signed-in user and the UI context without a second sign-in or a message protocol. Earlier design pages describe WebAssembly custom elements loaded from a CDN; that is not the ConnectSoft model.
Do¶
- Ship a micro-frontend as a Razor class library (
Microsoft.NET.Sdk.Razor). - Register its assembly and navigation items in the shell's registry, which feeds
AdditionalAssemblieson the router and onMapRazorComponents. - Run it under the shell's
InteractiveServerrender mode (CS-UI-003). - Host a legacy external application only in the shell's iframe mode, with these settings:
- an
AllowedOriginthat equals the origin of itsBaseUrl; - that origin added to the CSP
frame-src; - only the allow-listed
postMessagetypes.
Don't¶
- Package a micro-frontend as a WebAssembly app, a custom element or a CDN bundle.
- Use the iframe mode for a new micro-frontend.
Example¶
internal static class ShellMfeRegistry
{
public static readonly Assembly[] Assemblies =
[
typeof(OrdersMfe).Assembly,
typeof(CustomersMfe).Assembly,
];
}
How to check¶
- The micro-frontend project uses
Microsoft.NET.Sdk.Razor. - The shell's composition wiring test asserts that the registry assemblies reach the router and
MapRazorComponents.
CS-UI-022: Depend only on the shell contracts, never on another micro-frontend¶
Severity: blocker · Applies to: blazor, template · Enforced by: architecture test · Status: active
Why¶
A reference from one micro-frontend to another, or from the shell to a micro-frontend's internals, couples their releases and breaks independent delivery. The micro-frontend library template already enforces this with architecture tests.
Do¶
- Reference
ConnectSoft.Blazor.Shell.ContractsandConnectSoft.Blazor.Shell.Services.Abstractionsfor everything shared with the shell. - Communicate between micro-frontends through the shell: navigation requests and
MfeEventmessages. - Copy the template's isolation tests into every shell and micro-frontend repository.
Don't¶
- Add a project or package reference from one micro-frontend to another.
- Reference a micro-frontend's internal types from the shell.
- Put backend DTOs into the shell contracts.
How to check¶
- Architecture tests (for example
MicrofrontendIsolationTestsin the micro-frontend library template) assert that no micro-frontend depends on another and that the shell does not depend on micro-frontend internals. - Review
ProjectReferenceandPackageReferencechanges in micro-frontend projects. - Types added to
ConnectSoft.Blazor.Shell.Contractsare not backend request or response DTOs.
CS-UI-023: Reach backends only through published contract packages¶
Severity: major · Applies to: blazor, template · Enforced by: manual (target: ENF-049) · Status: active
Why¶
A hand-copied DTO drifts from the service. A field the copy does not declare is dropped without an error, and an edit form built on it then writes nulls back (CS-UI-009). A published contract package changes in step with the service and is versioned with it.
Do¶
- Call a backend through its published
*.ServiceModelpackage or a ConnectSoft API client package. - Map the contract to a view model inside the micro-frontend when the screen needs a different shape, and keep the mapping lossless for anything the screen edits.
Don't¶
- Copy request or response classes into the micro-frontend or into a shared contracts project in new code.
- Call a third-party API directly from a micro-frontend.
How to check¶
Review new request and response types in the micro-frontend: each comes from a *.ServiceModel or API client package.
CS-UI-024: Pin one UIKit and Shell package version across a shell and its micro-frontends¶
Severity: major · Applies to: blazor, template · Enforced by: manual (target: ENF-050) · Status: active
Why¶
The shell and its micro-frontends run in one process and load one copy of each assembly and one set of static assets. When two versions are pinned, the package build resolves one of them and a micro-frontend runs against a UIKit or Shell.Services version it was never tested with.
Do¶
- Pin
ConnectSoft.Blazor.UIKit, its adapter packages,ConnectSoft.Blazor.Shell.Contracts,ConnectSoft.Blazor.Shell.Services.AbstractionsandConnectSoft.Blazor.Shell.ServicesinDirectory.Packages.props. - Bump these packages together, in the shell and in every micro-frontend it composes, in one change.
Don't¶
- Pin a different version of any of these packages in a micro-frontend than in its shell.
How to check¶
Compare the version pins of these packages in Directory.Packages.props of the shell and of each composed micro-frontend.
CS-UI-025: Prefix each micro-frontend's routes and prove they are unique¶
Severity: major · Applies to: blazor, template · Enforced by: manual (target: ENF-051) · Status: active
Why¶
All composed assemblies share one router. Two pages with the same route make the router throw an ambiguous-route error at runtime, and a route that collides with a shell page silently replaces it.
Do¶
- Start every
@pageroute of a micro-frontend with its own prefix, for example/ordersand/orders/{id:guid}. - Add a test to the shell that collects the
RouteAttributetemplates of the shell and of every registered assembly and asserts they are unique.
Don't¶
- Use generic routes such as
/list,/edit/{id}or/settingsin a micro-frontend.
Example¶
[TestMethod]
public void ComposedRoutesAreUnique()
{
var routes = ShellMfeRegistry.Assemblies
.Append(typeof(App).Assembly)
.SelectMany(assembly => assembly.GetExportedTypes())
.SelectMany(type => type.GetCustomAttributes<RouteAttribute>())
.Select(route => route.Template.ToLowerInvariant())
.ToList();
CollectionAssert.AllItemsAreUnique(routes);
}
How to check¶
The shell has a route uniqueness test, and every route in the change starts with the micro-frontend's prefix.