Skip to content

Where to add things ​

What this page covers

Every choice of --Persistence, --Auth, --IncludeTests and --Aspire: a label says which options a part is for. The copy in your app's docs/ folder has only the parts for yours. ApiHost stands for your app's name.

The app is meant to be built on, and to keep taking fixes from newer versions of the template. That goes best when your code lives in files of its own and plugs into the places below, rather than being written into the template's files. This page lists those places. For a worked example of a whole feature, see the tutorial.

Keeping your changes easy to update ​

  • Put each feature in its own folders: src/ApiHost/Features/<Name>/ for the API and src/Client/src/features/<name>/ for the pages. Wolverine finds endpoints by their attributes and handlers by their names, so they need no registering.
  • Register services in one call: give a feature that needs services an Add<Name>(this IServiceCollection services, IConfiguration configuration) extension, and add one line for it to Program.cs. A newer Program.cs then needs only that line copied back in.
  • Settings in their own section: an options class with a SectionName, bound in that extension, with its rules checked at startup (Analytics/AnalyticsOptions.cs shows how), and a row in Deployment for each environment variable.
  • When a template file must change (a new tab in the back office, a new section in Settings), keep the change to one line that points at your code, so it's easy to see and carry over.

To take a newer version of the template, make a patch from the old version to the new one, generated with your app's name and options, and apply it with git apply -3, which merges it with your changes. Upgrading an app has a script that makes the patch, and a guide for each version on what changed and what to check. The script reads the template version, name and options this app was created with from .saas-starter.json; keep that file.

The API ​

To addWhere
EndpointsA static class with [WolverineGet], [WolverinePost], ... methods, in Features/<Name>/
Request validationAn AbstractValidator<TRequest> next to the request record: it runs before the endpoint
Background work and eventsReturn a message from an endpoint (it goes through the outbox), and handle it in a class whose name ends in Handler
Scheduled workOutgoingMessages.Delay(message, delay), returned from the endpoint (Features/Todos/RemindTodoEndpoint.*.cs)
Marten Stored dataA document class, with opts.Schema.For<T>() in Data/Marten/MartenPersistence.cs for its indexes; Marten creates the table
EF Core Stored dataA DbSet in Data/EfCore/AppDbContext.cs, then a migration
Health checksAddHealthChecks() in Program.cs, tagged ready if the app can't serve without it (observability)
Other sites the page may useContentSources in Security/SecurityHeaders.cs, the Content-Security-Policy's origins
Server-rendered public pagesMap them as usual (MapGet, Razor components): they take their paths ahead of the React app, with their own status codes, and can set their own Content-Security-Policy. List them in sitemap.xml with an ISitemapSource (ClientApp/ClientAppHosting.cs)
With accounts Who may call an endpoint[Authorize], or [Authorize(Roles = AppRoles.Admin)]; new roles in Identity/AppRoles.cs (add a role)
With accounts The signed-in userA ClaimsPrincipal parameter, and user.GetUserId()

With accounts

Accounts ​

To addWhere
A user preference (language, time zone, ...)A property on UserPreferences (Identity/UserPreferences.cs) and an endpoint that changes it; no migration (preferences)
A change that should ask who it is againuserManager.ConfirmItsYouAsync(...) with the password and code from the request (Identity/TwoFactor.cs; confirming it's you)
A notificationPublish SendNotification(...); a new kind in NotificationCategories (notifications)
An account emailA message and a handler like those in Identity/Email/AccountEmails.cs
A security emailA value in SecurityChange, and return a SendSecurityNotice (Identity/Email/SecurityNotices.cs)
Data in "Download your data"An IPersonalDataSource, registered with the feature's services (download your data)
Cleaning up when an account is deletedA handler for AccountDeleted (Features/Todos/DeleteTodosOfDeletedAccountHandler.*.cs). Each handler runs, commits and retries on its own (MultipleHandlerBehavior.Separated in Program.cs), so one feature's failure doesn't undo another's clean-up
A back office actionAn endpoint with [Authorize(Roles = AppRoles.Admin)] that records itself with IAuditLog.RecordAsync (Features/Admin/ManageUserEndpoints.cs)

With organisations

Organisations and plans ​

To addWhere
Data that belongs to an organisationTenanted data, like the Todos: Wolverine passes the organisation as the tenant (organisations)
Cleaning up when an organisation is deletedA handler for OrganisationDeleted (Features/Todos/DeleteTodosOfDeletedOrganisationHandler.*.cs)
Another way to find a request's organisationAn ITenantResolver, registered as a singleton (Organisations/TenantResolution.cs): asked after the access token's, such as by host name for an organisation's public site
Organisation data in the owners' exportAn IOrganisationDataSource
A feature flag or a limit for plansThe plan catalogue (plans, trials and limits)
An event other programs can subscribe toA webhook event type (integrations)

The client ​

To addWhere
A pageA route in src/Client/src/routes.ts and its path in pages.ts (index: true makes it public and pre-rendered; a test checks the two match)
API callsHooks in the feature's ...Queries.ts, with the typed client (lib/api/client.ts). After changing the API, regenerate the types with npm run gen:api
Componentssrc/Client/src/components/ui/ has the shadcn/ui components; add more with the shadcn CLI
With accounts A section in SettingsA component in your feature, and one line in features/account/SettingsPage.tsx
With accounts A tab in the back officeA route under admin in routes.ts, and an entry in features/admin/adminSections.ts

A library built on the template ​

A shared library (for example, a kit of public pages several apps use) adds itself the same way:

  • Its handlers and endpoints: Wolverine looks only in the app's own assembly unless told otherwise. Add opts.Discovery.IncludeAssembly(typeof(SomeTypeInTheLibrary).Assembly) in UseWolverine in Program.cs.
  • Its services: one Add<Library>() extension, called from Program.cs.
  • Marten Its data: Marten documents need nothing more.
  • EF Core Its data: the library's entities need a place in AppDbContext, and migrations in the app.
  • Its pages: React pages are copied into the client, or published as an npm package the client imports.

Documentation for v0.10.0. Released under the MIT licence.