Where to add things
One page for every option
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 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 Add a feature.
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, generate a fresh app with the same options and the same name, and compare it with yours (for example, copy it over a branch of your repository and review the diff). The release notes in the template's repository list what changed and what to check.
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) |
| Stored data | Marten: a document class, with opts.Schema.For<T>() in Data/Marten/MartenPersistence.cs for its indexes. EF Core: 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 |
| 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). All the handlers run in one transaction: with Marten, save in a session of your own (store.LightweightSession()), not the shared one |
| 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) |
| 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. - Its data: Marten documents need nothing more; with EF Core, the library's entities need a place in
AppDbContextand migrations in the app. - Its pages: React pages are copied into the client, or published as an npm package the client imports.