Service Layer high complexity backend
2
Dependencies
2
Dependents
1
Entities
0
Integrations

Description

Server-side service that executes duplicate detection logic both synchronously on activity creation and asynchronously during the nightly batch job. Compares incoming and existing activities on the composite key (peer_mentor_id, activity_date, activity_type_id, organization_id) against a configurable similarity threshold. Raises flag records when duplicates are found and ensures the composite index is used for all detection queries.

Feature: Activity Flagging

duplicate-detection-service

Responsibilities

  • Run duplicate check on activity_create events before the record is committed
  • Execute nightly batch scan across all unresolved activities and raise new flags
  • Apply configurable similarity threshold (default exact match on all four key fields)
  • Insert flag records into activity_flags with source, confidence, and comparison metadata
  • Expose a query interface for retrieving open duplicate alerts per organization

Interfaces

checkOnCreate(activity: ActivityRecord): Promise<DuplicateCheckResult>
runBatchDetection(orgId: string): Promise<BatchDetectionReport>
getDuplicateAlerts(orgId: string, status: FlagStatus): Promise<DuplicateAlert[]>
resolveDuplicateFlag(flagId: string, resolution: FlagResolution, actorId: string): Promise<void>
getSimilarityThreshold(orgId: string): Promise<DetectionConfig>

Relationships

Dependencies (2)

Components this component depends on

Dependents (2)

Components that depend on this component

Related Data Entities (1)

Data entities managed by this component