Skip to Content
GenerateSaaS

Deleting and restoring

Soft delete with a restore window, the Recently deleted list, the daily purge, the project/deleted and project/restored events, and the service seams a product hooks billing and cleanup into.

Deleting a project is soft: the row gets a deletedAt and leaves every list at once, stays restorable for PROJECT_RESTORE_DAYS (30, the same for every plan, from @repo/config), and a daily job then removes it for good.

While deletedAfter the purge
Project lists, switcher, GET /projects/reachableHiddenGone
Active-project resolution (chat context, AI runs, live updates)Never resolvesGone
Automations stamped with itNot swept; fire again after a restoreDeleted
Connections placed in itOut of reachDeleted by the foreign key
Per-owner cap (MAX_PROJECTS_PER_OWNER)Not counted-
The one-project floorNot counted: the owner keeps one live project-

Where people restore

SurfaceWhat it offers
/settings/project (web and desktop)A Recently deleted card listing each restorable project with its restore-until date; Restore for the owner or an organization admin. Hidden while empty
AI toolsprojects_delete (answers restorableUntil), projects_deleted_list, projects_restore, projects_list - in the chat and over MCP, never in automations, only while projects.enabled is on. On a multi-tenant build each takes an optional organizationId: an MCP call has no active organization, so without one it acts in the user's only organization and asks for an id when they have several
APIDELETE /projects/:id, GET /projects/deleted, POST /projects/:id/restore - see Projects

projects_delete runs when called, like every tool. Its description tells the model to confirm with the person first unless they said not to ask (Confirming risky changes).

Events

Both are sent with inngest.send after the write commits; a failed send is logged and never fails the write. Exactly one of ownerUserId and organizationId is set.

EventData
project/deleted{ projectId, ownerUserId, organizationId, restorableUntil } (ISO-8601)
project/restored{ projectId, ownerUserId, organizationId }

Service seams

Every surface above calls the same functions in packages/api/src/services/projects.ts; refusals throw ProjectActionError with an error code and an HTTP status.

ExportUse it for
activeProjects (@repo/database)The deletedAt IS NULL filter. Add it to every query of live projects: and(entityFilter(projects, owner), activeProjects)
softDeleteProject({ projectId, actor })Owner or admin, one-project floor; returns { restorableUntil }
restoreProject({ projectId, actor, beforeRestore? })Owner or admin, inside the window, under the cap; returns the project
listDeletedProjects({ owner, now? })The restorable deleted projects, newest first
purgeDeletedProjects({ now?, beforePurge? })Removes up to 500 expired projects per call; the project-purge job runs it daily at 03:45
Gate a restore (a plan's project allowance, a payment): pass beforeRestore(project) where the route and the projects_restore tool call restoreProject. Answer null to allow, or { code, message } to refuse - the client receives code as the error, so translate it. It runs after every built-in check, under the owner's lock.
Clean up your own data (files in storage, rows at a vendor): pass beforePurge(projectIds) in functions/maintenance/project-purge.ts. A throw stops the purge, and the same projects are tried again on the next run.
React to a delete or restore (pause a subscription seat, notify someone): add an Inngest function triggered by project/deleted or project/restored, as described in Background jobs.

Chat threads stamped with a purged project are not deleted; they stay out of every project's list.

On this page