Getting started
This tutorial builds a small product list in two steps: first the data logic with no UI at all, using the headless packages, then a Blazor Web App that shows the same kind of list with a stat card and a form drawer. It takes about fifteen minutes and every file is shown in full.
On this page
Check the prerequisites first: the .NET 10 or .NET 11 SDK, and for the components a Blazor app with Klyroo.UI set up.
1. Query data without a UI
Klyroo. references the headless engine of each library. Create a console app and add it:
dotnet new console -n ShopLogic
cd ShopLogic
dotnet add package Klyroo.Stack.Core --prereleaseReplace Program.:
using Klyroo.Query;
using Klyroo.Stack;
// Which library owns a component, and which packages does it ship in?
var module = KlyrooStackCatalog.ResolveComponentModule("KlyDataList<Product>")!;
Console.WriteLine($"{module.Name}: {module.CorePackage} + {module.UiPackage}");
// Describe the data once, then filter, sort and page it with no UI involved.
var schema = DataListSchema.For<Product>(s => s
.RowKey(p => p.Id)
.Search(p => p.Name)
.Field(p => p.Name, f => f.Key("name").Sortable())
.Field(p => p.Price, f => f.Key("price").Sortable()));
var request = new DataListRequest(
DataListPaging.Offset.ForPage(1, 10),
[new DataListSort("price", Descending: true)],
DataListFilterGroup.Empty);
var result = schema.ExecuteInMemory(
[new Product(1, "Keyboard", 120m), new Product(2, "Monitor", 350m), new Product(3, "Mouse", 40m)],
request);
Console.WriteLine($"{result.TotalCount} products, most expensive first: {result.Items[0].Name}");
sealed record Product(int Id, string Name, decimal Price);Run it with dotnet run:
Klyroo.Table: Klyroo.Table.Core + Klyroo.Table
3 products, most expensive first: MonitorDataListSchema is a Klyroo.Query type: it declares which fields exist, which are sortable and how rows are keyed. The same schema later drives the table in Blazor, so the rules you test here are the rules the UI applies. Klyroo is the one type that Klyroo. adds itself.
2. Create the Blazor app
Create an interactive Blazor Web App and add the meta-package:
dotnet new blazor -n Shop --interactivity Server --all-interactive --empty
cd Shop
dotnet add package Klyroo.Stack --prereleaseThe steps below describe the files that the template generates; your copy may differ in details such as the layout. Keep what the template gives you and make the changes shown.
Register the libraries
AddKlyrooStack() registers all eight libraries. Replace Program.:
using Klyroo.Stack;
using Shop.Components;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKlyrooStack();
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
app.UseHsts();
}
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
app.UseHttpsRedirection();
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();Load the stylesheets
In Components/, add the three head components and the three stylesheets inside <head>. KlyColor applies the stored color mode before the first paint, KlyCultureMeta writes the culture of the request so a WebAssembly client formats like the prerender, and KlyThemeStyle sends the theme variables. The first two stylesheets come from Klyroo.UI, the third from the meta-package; all of them are precompiled, so the app does not need Node or Tailwind:
<KlyColorModeScript />
<KlyCultureMeta />
<KlyThemeStyle />
<link rel="stylesheet" href="@Assets["_content/Klyroo.UI/klyroo.preflight.css"]" />
<link rel="stylesheet" href="@Assets["_content/Klyroo.UI/klyroo.css"]" />
<link rel="stylesheet" href="@Assets["_content/Klyroo.Stack/klyroo-stack.css"]" />In a .NET MAUI Blazor Hybrid app, which has no server to render <head>, <KlyHead /> in the layout does the job of the three head components.
If the project still loads Bootstrap or another stylesheet that sits outside CSS layers, remove it: unlayered CSS overrides the layered CSS of Tailwind v4 and changes how the components look.
Add the root component
Replace Components/. KlyApp is the root of the Klyroo components, KlyFormProvider hosts the form overlays and KlyFile hosts the file preview:
<KlyApp>
<KlyFormProvider />
<KlyFilePreviewProvider />
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" />
</Found>
</Router>
</KlyApp>Import the namespaces
Add these lines to Components/_:
@using Klyroo.UI
@using Klyroo.Query
@using Klyroo.Table
@using Klyroo.Form
@using Klyroo.Dashboard
@using Klyroo.Display
@using Klyroo.Spreadsheet
@using Klyroo.Agent
@using Klyroo.Stack3. Build the page
Delete Components/ if it exists and create Components/. The page combines three libraries: Klyroo.Dashboard for the stat cards, Klyroo.Table for the list and Klyroo.Form for the "new product" drawer.
@page "/"
@inject FormService Forms
<KlyDashboardPage Dashboard="_dashboard" Title="Shop">
<KlyDashboardGrid>
<KlyDashboardStat Label="Products" Value="_products.Count" />
<KlyDashboardStat Label="Catalog value" Value="(double)_products.Sum(p => p.Price)" Format="DashboardFormatPreset.Compact" />
</KlyDashboardGrid>
<div class="mt-6">
<KlyButton Label="New product" Color="KlyColor.Primary" OnClick="AddProductAsync" />
</div>
<div class="mt-4">
<KlyDataList Schema="Schema" Items="_products" UrlSync="false">
<KlyDataListTable TItem="Product">
<KlyDataListFieldColumn TItem="Product" Field="name" Title="Product" />
<KlyDataListFieldColumn TItem="Product" Field="price" Title="Price" Summary="DataListSummaryKind.Sum" />
</KlyDataListTable>
</KlyDataList>
</div>
</KlyDashboardPage>
@code {
private sealed record Product(int Id, string Name, decimal Price);
private static readonly DataListSchema<Product> Schema = DataListSchema.For<Product>(s => s
.RowKey(p => p.Id)
.RowLabel(p => p.Name)
.Field(p => p.Name, f => f.Key("name").Sortable())
.Field(p => p.Price, f => f.Key("price").Sortable())
.DefaultSort(p => p.Name));
private readonly DashboardController _dashboard = new("shop");
private readonly List<Product> _products =
[
new(1, "Keyboard", 120m),
new(2, "Monitor", 350m),
new(3, "Mouse", 40m),
];
private async Task AddProductAsync()
{
var outcome = await Forms.CreateFormAsync(NewProductSchema, mode: FormShellMode.Drawer);
if (outcome is { IsCompleted: true, Model: { } created })
{
_products.Add(new Product(_products.Count + 1, created.Name, created.Price));
}
}
// What the form edits: its fields are the members of this class, with the types the members have.
private sealed class NewProduct
{
public string Name { get; set; } = "";
public decimal Price { get; set; }
}
private static readonly FormSchema<NewProduct> NewProductSchema = FormSchema.For<NewProduct>(s =>
{
s.FormKey = "new-product";
s.Title = "New product";
s.Field(p => p.Name, f => f.Required());
s.Field(p => p.Price, f => f.Default(50m));
});
}Run dotnet run, open the address it prints, and you see the two stat cards, the list sorted by name with a sum row under the price column, and a button that opens the drawer. UrlSync="false" keeps the list state out of the query string, which is what you want for an in-memory list on a single page. FormService. returns when the drawer closes, and outcome. is true only when the user submitted the form.
The form fills a NewProduct, so the price comes back as a decimal in outcome. with no conversion. A form that is only known at run time uses the Klyroo. types instead, which key the values by name.
Next steps
- Guides: register a single library, share options between the server and the client, test a page with bUnit, let an agent drive a form, and connect the MCP server.
- Concepts: how the libraries, the
.packages and the registration call fit together.Core - Platforms: render modes, .NET MAUI Blazor Hybrid and NativeAOT.
- Templates: start the next project from
dotnet new klyroo-saasinstead of editing files by hand.