App Suite for Teams
Home
Product
Development
Operations
API Reference
GitLab
Home
Product
Development
Operations
API Reference
GitLab
  • Features Overview
  • Technical Patterns Reference
  • Features

    • Feature: Assignment Workflow
    • Feature: Categories and Status Tracking
    • Feature: Collaborative Draft Editing
    • Feature Specification: Mentions in Thread Comments
    • Feature: Real-time Collaboration Infrastructure
    • Feature: Sentry Error Tracking Integration
    • Feature: Shared Inboxes and Multi-Account Support
    • Feature: Thread Management
  • User Stories

    • User Story: Assignment Workflow
    • User Story: Categories and Categorization
    • User Story: Collaborative Draft Editing
    • User Story: Comments and Discussion
    • User Story: Shared Inboxes
    • User Story: Status Tracking
    • User Story: Thread Management
  • Teams Application Workflow Showcase

Technical Patterns Reference

This document provides central reference for technical patterns used across Teams features. Feature documentation should link here instead of repeating these patterns.

Real-time Collaboration (Yjs/CRDT)

Teams uses Yjs (CRDT library) for conflict-free real-time collaboration.

Key Characteristics:

  • Collaborative editing without conflicts
  • Offline-capable with automatic sync
  • State persisted to PostgreSQL + IndexedDB
  • Custom WebSocket provider (ADR-0008)

Integration Pattern:

// Feature components use Yjs for shared state
import { useYjs } from '@/composables/useYjs'

const { doc, provider, awareness } = useYjs(threadId)

See: ADR-0007, ADR-0008

WebSocket Notifications

Real-time notifications use WebSocket broadcast pattern.

Notification Format:

{
  "type": "action_type",  // e.g., "mention", "assignment", "status"
  "data": {
    "threadId": "...",
    // Type-specific data
  }
}

Backend Pattern:

// Broadcast to all users with thread access
fastify.websocket.broadcast('teams:action:new', {
  type: 'assignment',
  data: { threadId, userId, ... }
})

Frontend Pattern:

// Listen for specific action types
websocket.on('teams:action:new', (payload) => {
  if (payload.type === 'assignment') {
    // Handle assignment notification
  }
})

API Endpoint Conventions

Filtering:

  • Query param format: ?filter=key:value,key2:value2
  • Common filters: status:active, status:done, tag:urgent
  • Server-side filtering required (never client-side for large datasets)

Response Format:

{
  "success": true,
  "data": [...],
  "meta": {
    "total": 100,
    "page": 1
  }
}

Error Format:

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable message"
  }
}

State Management (Pinia)

Store Pattern:

// stores/feature.js
import { defineStore } from 'pinia'

export const useFeatureStore = defineStore('feature', () => {
  // State
  const items = ref([])

  // Actions
  async function fetchItems() {
    const response = await api.get('/items')
    items.value = response.data
  }

  return { items, fetchItems }
})

Optimistic Updates:

async function updateItem(id, data) {
  // Update locally first
  const index = items.value.findIndex(i => i.id === id)
  const original = items.value[index]
  items.value[index] = { ...original, ...data }

  try {
    await api.put(`/items/${id}`, data)
  } catch (error) {
    // Rollback on failure
    items.value[index] = original
    throw error
  }
}

Database Transactions

Transaction Pattern:

// Use database transactions for related updates
await fastify.db.transaction(async (tx) => {
  await tx.update(threads).set({ status: 'done' })
  await tx.insert(actions).values({ type: 'status', ... })
  // Broadcast after commit
})

Foreign Key Cascades:

  • Use ON DELETE CASCADE for automatic cleanup
  • Example: thread_id REFERENCES threads(id) ON DELETE CASCADE

Authentication & Authorization

Permission Check Pattern:

// Check user has access to thread's inbox
const hasAccess = await fastify.db.query.accounts.findFirst({
  where: and(
    eq(accounts.userId, userId),
    eq(accounts.inboxId, thread.inboxId)
  )
})

if (!hasAccess) {
  throw fastify.httpErrors.forbidden()
}

See: ADR-0011

Testing Patterns

See: docs/development/testing.md, docs/development/e2e-testing.md

Edit this page on GitLab
Prev
Features Overview