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 andsrc/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 toProgram.cs. A newerProgram.csthen 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.csshows 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 add | Where |
|---|---|
| Endpoints | A static class with [WolverineGet], [WolverinePost], ... methods, in Features/<Name>/ |
| Request validation | An AbstractValidator<TRequest> next to the request record: it runs before the endpoint |
| Background work and events | Return a message from an endpoint (it goes through the outbox), and handle it in a class whose name ends in Handler |
| Scheduled work | OutgoingMessages.Delay(message, delay), returned from the endpoint (Features/Todos/RemindTodoEndpoint.*.cs) |
| Marten Stored data | A document class, with opts.Schema.For<T>() in Data/Marten/MartenPersistence.cs for its indexes; Marten creates the table |
| EF Core Stored data | A DbSet in Data/EfCore/AppDbContext.cs, then a migration |
| Health checks | AddHealthChecks() in Program.cs, tagged ready if the app can't serve without it (observability) |
| Other sites the page may use | ContentSources in Security/SecurityHeaders.cs, the Content-Security-Policy's origins |
| Server-rendered public pages | Map 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 user | A ClaimsPrincipal parameter, and user.GetUserId() |
With accounts
Accounts
| To add | Where |
|---|---|
| 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 again | userManager.ConfirmItsYouAsync(...) with the password and code from the request (Identity/TwoFactor.cs; confirming it's you) |
| A notification | Publish SendNotification(...); a new kind in NotificationCategories (notifications) |
| An account email | A message and a handler like those in Identity/Email/AccountEmails.cs |
| A security email | A 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 deleted | A 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 action | An endpoint with [Authorize(Roles = AppRoles.Admin)] that records itself with IAuditLog.RecordAsync (Features/Admin/ManageUserEndpoints.cs) |
With organisations
Organisations and plans
| To add | Where |
|---|---|
| Data that belongs to an organisation | Tenanted data, like the Todos: Wolverine passes the organisation as the tenant (organisations) |
| Cleaning up when an organisation is deleted | A handler for OrganisationDeleted (Features/Todos/DeleteTodosOfDeletedOrganisationHandler.*.cs) |
| Another way to find a request's organisation | An 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' export | An IOrganisationDataSource |
| A feature flag or a limit for plans | The plan catalogue (plans, trials and limits) |
| An event other programs can subscribe to | A webhook event type (integrations) |
The client
| To add | Where |
|---|---|
| A page | A 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 calls | Hooks 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 |
| Components | src/Client/src/components/ui/ has the shadcn/ui components; add more with the shadcn CLI |
| With accounts A section in Settings | A component in your feature, and one line in features/account/SettingsPage.tsx |
| With accounts A tab in the back office | A 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)inUseWolverineinProgram.cs. - Its services: one
Add<Library>()extension, called fromProgram.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.