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 deleted | After the purge | |
|---|---|---|
Project lists, switcher, GET /projects/reachable | Hidden | Gone |
| Active-project resolution (chat context, AI runs, live updates) | Never resolves | Gone |
| Automations stamped with it | Not swept; fire again after a restore | Deleted |
| Connections placed in it | Out of reach | Deleted by the foreign key |
Per-owner cap (MAX_PROJECTS_PER_OWNER) | Not counted | - |
| The one-project floor | Not counted: the owner keeps one live project | - |
Where people restore
| Surface | What 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 tools | projects_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 |
| API | DELETE /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.
| Event | Data |
|---|---|
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.
| Export | Use 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 |
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.beforePurge(projectIds) in functions/maintenance/project-purge.ts. A throw stops the purge, and the same projects are tried again on the next run.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.
Projects
The project entity that scopes a user's work inside their account or inside their active organization - ownership, the API, config.projects.enabled, and the useActiveProject hook.
Send transactional and marketing email through SMTP, SES, or Resend with @repo/mail, and sync newsletter lists with config.newsletter.