Estimate: 34m · Depends on: 6.1.1, 6.4
The persistence + permission layer. Pure backend — no UI.
Schema (one migration, FKs as Prisma @relations): saved_filter — project FK, owner FK, name (unique per project, case-insensitive — cite the story decision), description?, visibility enum { private, project }, and the versioned AST envelope (JSONB carrying exactly what the 6.1.1 codec encodes, version field included); saved_filter_star — (filter, user) unique pair. Timestamps throughout.
Service + repos (4-layer): CRUD with the permission matrix — create/star: any project member incl. viewer (private only for viewers); visibility project requires role ≥ member; update/delete/change-owner: owner OR project admin (workspace owner/admin always); every read filtered by the 6.4 browse gate + visibility. Resolve (THE data-source contract, documented for 6.3 in the service JSDoc): id → decode + registry-validate the stored envelope via 6.1.1 (NEVER trust-and-compile) → the compiled WHERE fragment + metadata DTO; stale referents degrade per the 6.1.2 unknown-value rule; malformed/future-versioned envelopes → the typed recoverable error. List reads bounded + server-searched + paginated (mine / project / starred views; star counts aggregated in SQL — finding #57). Built-in defaults: the system filters as non-persisted AST constants (My open issues, Reported by me, All/Open/Done issues, Created/Updated/Resolved recently) exposed through the same list/resolve reads with builtin: true (no write paths). Delete dependents: the delete read enumerates dependents (subscriptions now; 6.3 widgets join in by FK later) so the UI can render the Cloud-style warning; deletion cascades subscriptions in the same transaction.
@relations; the name-uniqueness constraint is case-insensitive per project.pnpm test:coverage ≥90%.lib/filters/ast.ts (the envelope + codec — the single source of the stored shape) + the 6.1.2 stale-referent ruleProjectMembership, access levels) — the permission substrate; motir-core/CLAUDE.md (4-layer, required-tx, FK @relation rule)