---
url: /saas-starter/v0.9.0/guide/how-to/add-a-feature.md
---
# Add a feature: the checklist

::: tip 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](../tutorial.md) goes through each one
with a worked example, Contacts; the Todo feature shows more patterns
([Architecture](../architecture.md)).

## 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.

* &#x20;**The data:** a class that implements `ITenanted`, so it belongs to the request's organisation and queries only see that organisation's data.
* &#x20;**The data:** a class with an `OwnerId`, which every query and change checks.
* &#x20;**The data:** a class with a `Guid Id`.
* &#x20;**Storage:** Marten creates the table itself; add `opts.Schema.For<T>().MultiTenanted();` in `Data/Marten/MartenPersistence.cs`.
* &#x20;**Storage:** Marten creates the table itself; index the owner in `Data/Marten/MartenPersistence.cs`.
* &#x20;**Storage:** Marten creates the table itself.
* &#x20;**Storage:** a `DbSet` in `Data/EfCore/AppDbContext.cs`, then [a migration](./add-a-migration.md).
* **Requests:** a record for each request body, and a FluentValidation validator for it, which
  runs before the endpoint.
* &#x20;**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.
* &#x20;**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.
* &#x20;**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.
* &#x20;**Live updates:** a message with `[MessageIdentity("...")]`, routed in `Program.cs` with `opts.PublishMessage<T>().ToSignalR();`.
* &#x20;**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`).
* &#x20;**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).
* &#x20;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).
* &#x20;A link in `features/account/AccountNavigation.tsx`.
* &#x20;Its URL in `src/Client/src/routes.ts` and `src/Client/src/pages.ts` (a unit test checks they match).
* &#x20;A link in `App.tsx`.

## Tests

* &#x20;API tests in `tests/ApiHost.Tests`: the happy path, validation, and that nobody else can see or change the data.
* &#x20;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](../testing.md).
