Skip to content

Add a feature: the checklist ​

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 steps for adding a feature, in order. The tutorial goes through each one with a worked example, Contacts; the Todo feature shows more patterns (Architecture).

The API ​

A feature is a folder, src/ApiHost/Features/<Feature>/. Nothing needs registering: Wolverine finds endpoints by their attributes and handlers by their class names.

  • With organisations The data: a class that implements ITenanted, so it belongs to the request's organisation and queries only see that organisation's data.
  • With accounts, without organisations The data: a class with an OwnerId, which every query and change checks.
  • Without accounts The data: a class with a Guid Id.
  • Marten, with organisations Storage: Marten creates the table itself; add opts.Schema.For<T>().MultiTenanted(); in Data/Marten/MartenPersistence.cs.
  • Marten, with accounts, without organisations Storage: Marten creates the table itself; index the owner in Data/Marten/MartenPersistence.cs.
  • Marten, without accounts Storage: Marten creates the table itself.
  • EF Core Storage: a DbSet in Data/EfCore/AppDbContext.cs, then a migration.
  • Requests: a record for each request body, and a FluentValidation validator for it, which runs before the endpoint.
  • With accounts Endpoints: static methods with [Authorize] and [WolverineGet], [WolverinePost] and the rest. Answer 404, not 403, for something that isn't the caller's, so its existence isn't revealed.
  • Without accounts Endpoints: static methods with [WolverineGet], [WolverinePost] and the rest.
  • Background work: return a message from the endpoint, and handle it in a class whose name ends in Handler. It's saved with the data (the outbox) and runs even after a restart.
  • With accounts Live updates: a message with [MessageIdentity("...")], routed in Program.cs with opts.PublishMessage<T>().ToSignalR();, and sent to a group (Realtime/RealtimeGroups.cs) with ToWebSocketGroup, so only the right people get it.
  • Without accounts Live updates: a message with [MessageIdentity("...")], routed in Program.cs with opts.PublishMessage<T>().ToSignalR();.
  • With organisations The data's lifetime: handle OrganisationDeleted to delete the organisation's data, and add it to the organisation's data export (Features/Todos/TodosOrganisationData.cs).
  • With accounts, without organisations The data's lifetime: handle AccountDeleted to delete the user's data, and add it to the user's data export (Features/Todos/TodosPersonalData.cs).

The client ​

  • With the API running, npm run gen:api in src/Client updates the API's types.
  • A folder, src/Client/src/features/<feature>/, with TanStack Query hooks and the page. Listen for live updates with useRealtime (lib/realtime.ts).
  • A route module in src/Client/src/routes/, which gives the page's title in handle (with index: true only if search engines should list it, which also pre-renders it).
  • With accounts Its URL in src/Client/src/routes.ts, inside the require-auth layout if it needs a login, and in src/Client/src/pages.ts (a unit test checks they match).
  • With accounts A link in features/account/AccountNavigation.tsx.
  • Without accounts Its URL in src/Client/src/routes.ts and src/Client/src/pages.ts (a unit test checks they match).
  • Without accounts A link in App.tsx.

Tests ​

  • With accounts, with the tests API tests in tests/ApiHost.Tests: the happy path, validation, and that nobody else can see or change the data.
  • Without accounts, with the tests API tests in tests/ApiHost.Tests: the happy path and validation.
  • A client test next to the page, with the API faked by MSW.

See Testing.

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