# Removing a feature

> Cleanly delete a vertical slice across the API, frontend, permissions and tests.

The inverse of [adding a vertical slice](/docs/vertical-slices). Slices remove cleanly because nothing else
depends on them: a feature lives in its own folder and is discovered by convention, not wired into a central
registry. The work is mostly deletion plus a few spots where a slice reached into shared surfaces (schema,
integration-event contracts, personal-data handlers, permissions).

Work the checklist top to bottom. The compiler and the test suite are your safety net: orphaned references
surface as build errors, schema drift surfaces in feature and API tests.

<!-- demo:begin -->
> The [demo environment](/docs/demo-environment) is removable as a unit (it spans the API and the
> landing site): run `./scripts/remove-demo.sh` instead of working this checklist by hand.
<!-- demo:end -->

## 1. Delete the Core slice and its endpoint

A slice is three files in three projects: the command and handler in `Slicekit.Core`, the HTTP adapter in
`Slicekit.Api`, and the tests. Remove all three.

```sh
rm -r api/src/Slicekit.Core/Features///
rm api/src/Slicekit.Api/Endpoints/v1//Endpoint.cs
rm api/tests/Slicekit.Feature.Tests/Features//Tests.cs
```

Also remove any API integration test under `api/tests/Slicekit.Api.Tests/` that covered the endpoint.

## 2. Check the integration-event contract

If the slice published an `IIntegrationEvent` (look under `api/src/Slicekit.Core/IntegrationEvents/`), decide
based on consumers:

- **Other services consume it:** keep the contract, retire only the publisher, and note that the event is no
  longer emitted.
- **Nobody consumes it:** delete the contract too.

Grep before you delete:

```sh
rg "" --type cs
```

See [CQRS and events](/docs/cqrs-and-events) for how raised and published events flow through the outbox.

## 3. Drop owned schema

If the slice owned tables or columns that nothing else uses, drop them with a new EF migration:

```sh
dotnet ef migrations add Drop \
  --project api/src/Slicekit.Core \
  --startup-project api/src/Slicekit.Api \
  --context AppDbContext
```

See [adding a migration](/docs/adding-a-migration) for outbox-aware sequencing if the dropped tables sat
alongside Wolverine's transactional outbox.

## 4. Strip personal-data branches

If the slice persisted user-personal data, remove its branch from the export and delete handlers:

- `api/src/Slicekit.Core/Features/Users/ExportMyData/Handler.cs`
- `api/src/Slicekit.Core/Features/Users/DeleteUser/Handler.cs`

Update their tests in the same change so the export and delete paths stay green.

## 5. Tidy API versioning

If the deleted endpoint was the last one in a published API version, tidy
`api/src/Slicekit.Api/Configuration/Versioning.cs` and `api/src/Slicekit.Api/Endpoints/RegisterEndpoints.cs`.
This is the inverse of standing a new version up.

## 6. Remove orphaned permissions

If the slice required a permission via `Allow.`, check whether anything else still references it in
`api/src/Slicekit.Core/Permissions/Allow.cs`:

```sh
rg "Allow." --type cs
```

If the permission is now orphaned, remove the constant and add a migration that deletes the permission row.
See [adding a permission](/docs/adding-a-permission) for the inverse.

## 7. Remove the frontend slice

If the API slice had a UI counterpart:

- Delete `frontend/src/features/<slice>/`.
- Drop any routes under `frontend/src/routes/` that mounted the slice, and remove nav entries that linked to
  them.
- Remove the slice's i18n keys from `frontend/src/shared/i18n/locales/en.json` and `nl.json`, plus any
  `errorCodeMap.ts` entries the slice added. Keeping the two locale files matched keeps the
  locale-completeness check green.

```sh
cd frontend && pnpm typecheck && pnpm lint
```

Typecheck and lint surface orphaned imports the file deletes left behind.

## Verify

- `dotnet build api/slicekit.slnx` passes. Compile errors expose orphaned references the grep missed.
- `dotnet test api/tests/Slicekit.Unit.Tests api/tests/Slicekit.Architecture.Tests --nologo` passes (the fast loop).
- `dotnet test api/slicekit.slnx --nologo` passes. The full suite catches schema drift in feature and API tests.
- `git grep ` returns nothing.

## Checklist

- [ ] Core slice folder deleted (`Features///`).
- [ ] `Slicekit.Api` endpoint deleted, plus its feature and API integration tests.
- [ ] Integration-event contract kept or deleted based on consumers.
- [ ] Migration added for any tables or columns the slice owned.
- [ ] Personal-data branches removed from `ExportMyData` and `DeleteUser`, tests updated.
- [ ] API versioning tidied if this was the last endpoint in a version.
- [ ] Orphaned `Allow.` permission removed, with a migration deleting the row.
- [ ] Frontend feature folder, routes, nav entries and i18n keys removed.
- [ ] Build, fast suite and full suite green, `git grep` clean.
