# Workspace Deletion Workflow

## Objective

Close a whole workspace without one click erasing everyone's work.

An owner-only deletion flow with an explicit inventory, a recovery window, and cascading cleanup across internal and external systems.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Restrict deletion to owners and require recent re-authentication plus typing the workspace name. This is the most destructive action in the product and should feel like it.
2. Show an inventory before confirming: how many members lose access, what happens to billing, how many files and records are affected, which integrations disconnect, and which shared links die.
3. Schedule the deletion rather than executing it. Mark the workspace as pending deletion, block access to it, notify every member and admin, and only purge after a stated recovery window.
4. Allow any owner to cancel during that window, and restore the workspace to exactly its previous state — not a default one.
5. Cancel the subscription at the point of scheduling, not at purge, so nobody pays for a workspace they have closed.
6. Make the purge idempotent and resumable, working in batches, so a failure halfway through can simply be re-run.
7. Do NOT leave external systems behind. Storage objects, search indexes, cache entries, queued jobs, and third-party resources are part of the delete, and they are what gets forgotten.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- A member who belongs only to this workspace needs somewhere to land after the purge — decide whether their user account survives.
- Legal holds, open disputes, and retention obligations must block or delay the purge, and the requester must be told why.
- Data the customer wants must be offered as an export before the window closes, not after the records are gone.
- Shared public links must stop resolving as soon as deletion is scheduled, not at purge — access ends when the owner says it ends.
- The workspace name or slug should not be immediately reusable; hold it until the purge completes, or old links resolve to a stranger's workspace.
- External deletions can partially fail and must be retried without re-deleting what already succeeded; record progress per system.
- Very large workspaces must not attempt a single transactional delete — batch it and keep the workspace unreachable throughout.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Only an owner can delete, after re-authentication and typing the workspace name.
- [ ] An inventory of members, billing, data, integrations, and links is shown before confirmation.
- [ ] Deletion is scheduled with a stated recovery window and every member is notified.
- [ ] Cancelling within the window restores the previous state exactly.
- [ ] Billing stops when deletion is scheduled.
- [ ] The purge is batched, idempotent, and resumable, and covers storage, indexes, caches, jobs, and third-party resources.
- [ ] Shared links stop working as soon as deletion is scheduled.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
