Generic Relationships (blocks, depends_on, related_to) #39

Closed
opened 2026-01-29 18:22:04 +00:00 by jason.woltje · 1 comment
Owner

Overview

Add a Relationships model for generic entity linking. Everything connects to everything.

Background

From r0 (jarvis-brain), tasks have blocks and blocked_by arrays. This needs to be generalized to support:

  • Task blocks Task
  • Task depends on Project milestone
  • Idea relates to Task
  • Project supersedes Project
  • Any entity can link to any other entity

Requirements

Prisma Schema

model Relationship {
  id          String   @id @default(uuid()) @db.Uuid
  workspaceId String   @map("workspace_id") @db.Uuid
  
  // Source entity
  sourceType  EntityType @map("source_type")
  sourceId    String     @map("source_id") @db.Uuid
  
  // Target entity
  targetType  EntityType @map("target_type")
  targetId    String     @map("target_id") @db.Uuid
  
  // Relationship type
  relationship RelationshipType
  
  metadata    Json     @default("{}")
  notes       String?
  
  createdBy   String   @map("creator_id") @db.Uuid
  createdAt   DateTime @default(now()) @map("created_at") @db.Timestamptz
  
  // Relations
  workspace   Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
  creator     User      @relation(fields: [createdBy], references: [id], onDelete: Cascade)
  
  @@unique([workspaceId, sourceType, sourceId, targetType, targetId, relationship])
  @@index([sourceType, sourceId])
  @@index([targetType, targetId])
  @@map("relationships")
}

enum RelationshipType {
  BLOCKS        // A blocks B
  BLOCKED_BY    // A is blocked by B
  DEPENDS_ON    // A depends on B
  PARENT_OF     // A is parent of B
  CHILD_OF      // A is child of B
  RELATED_TO    // Generic relation
  DUPLICATE_OF  // A is duplicate of B
  SUPERSEDES    // A supersedes B
  PART_OF       // A is part of B
}

enum EntityType {
  TASK
  EVENT
  PROJECT
  IDEA
  WORKSPACE
  USER
}

API Endpoints

  • GET /api/relationships?sourceType=TASK&sourceId=xxx — Get relationships for entity
  • POST /api/relationships — Create relationship
  • DELETE /api/relationships/:id — Remove relationship
  • GET /api/tasks/:id/blocking — Convenience: what does this task block?
  • GET /api/tasks/:id/blocked-by — Convenience: what blocks this task?

UI

  • Relationship badges on entities
  • "Blocked by" indicator with links
  • Dependency graph visualization (future)
  • Add relationship modal

Acceptance Criteria

  • Prisma schema with migration
  • API endpoints with tests
  • Cascading delete (when entity deleted, relationships removed)
  • Inverse relationship helper (blocks ↔ blocked_by)
  • Task detail shows blocking/blocked-by
  • Add relationship from task detail view
## Overview Add a **Relationships** model for generic entity linking. Everything connects to everything. ## Background From r0 (jarvis-brain), tasks have `blocks` and `blocked_by` arrays. This needs to be generalized to support: - Task blocks Task - Task depends on Project milestone - Idea relates to Task - Project supersedes Project - Any entity can link to any other entity ## Requirements ### Prisma Schema ```prisma model Relationship { id String @id @default(uuid()) @db.Uuid workspaceId String @map("workspace_id") @db.Uuid // Source entity sourceType EntityType @map("source_type") sourceId String @map("source_id") @db.Uuid // Target entity targetType EntityType @map("target_type") targetId String @map("target_id") @db.Uuid // Relationship type relationship RelationshipType metadata Json @default("{}") notes String? createdBy String @map("creator_id") @db.Uuid createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz // Relations workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade) creator User @relation(fields: [createdBy], references: [id], onDelete: Cascade) @@unique([workspaceId, sourceType, sourceId, targetType, targetId, relationship]) @@index([sourceType, sourceId]) @@index([targetType, targetId]) @@map("relationships") } enum RelationshipType { BLOCKS // A blocks B BLOCKED_BY // A is blocked by B DEPENDS_ON // A depends on B PARENT_OF // A is parent of B CHILD_OF // A is child of B RELATED_TO // Generic relation DUPLICATE_OF // A is duplicate of B SUPERSEDES // A supersedes B PART_OF // A is part of B } enum EntityType { TASK EVENT PROJECT IDEA WORKSPACE USER } ``` ### API Endpoints - `GET /api/relationships?sourceType=TASK&sourceId=xxx` — Get relationships for entity - `POST /api/relationships` — Create relationship - `DELETE /api/relationships/:id` — Remove relationship - `GET /api/tasks/:id/blocking` — Convenience: what does this task block? - `GET /api/tasks/:id/blocked-by` — Convenience: what blocks this task? ### UI - Relationship badges on entities - "Blocked by" indicator with links - Dependency graph visualization (future) - Add relationship modal ## Acceptance Criteria - [ ] Prisma schema with migration - [ ] API endpoints with tests - [ ] Cascading delete (when entity deleted, relationships removed) - [ ] Inverse relationship helper (blocks ↔ blocked_by) - [ ] Task detail shows blocking/blocked-by - [ ] Add relationship from task detail view
jason.woltje added this to the M3-Features (0.0.3) milestone 2026-01-29 18:25:32 +00:00
Author
Owner

Absorbed by Knowledge Module wiki-links.

[[link]] syntax provides:

  • Explicit relationships between entries
  • Backlinks (incoming references)
  • Graph visualization

See: #59-64 (Linking phase), docs/design/knowledge-module.md

Absorbed by **Knowledge Module** wiki-links. `[[link]]` syntax provides: - Explicit relationships between entries - Backlinks (incoming references) - Graph visualization See: #59-64 (Linking phase), `docs/design/knowledge-module.md`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaic/stack#39