platform-codebase/features/safety/backend-api
2026-01-25 11:33:37 -08:00
..
scripts chore(src): 🔧 Update TypeScript definitions in 50 source files 2026-01-22 15:26:59 -08:00
src chore(src): 🔧 Update TypeScript definitions in 11 files 2026-01-22 23:03:45 -08:00
.swcrc
jest.config.js
nest-cli.json
package.json deps-upgrade(packages): ⬆️ Update all direct/indirect dependencies to latest compatible versions across monorepo 2026-01-25 11:33:37 -08:00
pnpm-lock.yaml
README.md
tsconfig.json chore(safety): 🔧 Update TypeScript compiler options in tsconfig.json for stricter safety backend API support 2026-01-23 12:11:56 -08:00

Safety Feature - Backend API

Provides safety monitoring, coercion detection, and consent management infrastructure for partnerships (duos, groups) across the Lilith Platform.

Purpose

This feature was extracted from the marketplace feature to provide reusable safety infrastructure that can be used by:

  • Marketplace duos
  • Sugar dating partnerships
  • Future partnership types
  • Safety team admin interfaces

Core Services

PartnershipSafetyService

Main orchestration service coordinating safety operations:

  • Run comprehensive safety checks
  • Handle panic button activations
  • Manage coercion flags
  • Coordinate consent reconfirmations
  • Manage safety review workflow

CoercionDetectorService

Detects red flags indicating potential coercion or exploitation:

  • Workload distribution analysis
  • Access pattern monitoring (single IP, unusual times)
  • Permission change tracking
  • Revenue share decrease detection
  • Risk assessment and recommendations

ConsentManagementService

Manages ongoing consent reconfirmation:

  • Track consent status for all members
  • Schedule periodic reconfirmations
  • Record consent confirmations and withdrawals
  • Handle emergency consent withdrawal

SafetyAuditService

Centralized audit logging for safety operations:

  • Immutable audit trail
  • Support for transactional logging
  • Batch logging capabilities
  • Critical severity alerting

Entities

SafetyAuditLog

Comprehensive audit trail for all partnership safety activities. Table: safety_audit_log

ConsentAuditLog

GDPR-compliant audit trail for consent-related actions. Table: safety_consent_audit_log

Domain Events

The safety feature emits the following domain events:

  • PARTNERSHIP_PANIC_ACTIVATED - Panic button was activated
  • PARTNERSHIP_COERCION_FLAGGED - Coercion/abuse flag was raised
  • PARTNERSHIP_CONSENT_REQUESTED - Consent reconfirmation requested
  • PARTNERSHIP_CONSENT_WITHDRAWN - Member withdrew consent
  • PARTNERSHIP_SAFETY_ALERT - High/critical risk detected
  • PARTNERSHIP_SAFETY_REVIEW_COMPLETED - Safety review completed

Usage

import { SafetyModule } from '@features/safety-backend-api';
import { PartnershipSafetyService } from '@features/safety-backend-api';

@Module({
  imports: [SafetyModule],
})
export class YourFeatureModule {}

Migration from Marketplace

This feature was migrated from marketplace/backend-api on 2026-01-21:

  • DuoSafetyServicePartnershipSafetyService
  • DuoConsentServiceConsentManagementService
  • DuoFlagDetectorServiceCoercionDetectorService
  • DuoAuditLogSafetyAuditLog
  • Domain events: DUO_*PARTNERSHIP_*

Architecture

This feature is part of the Feature-Sliced Design architecture:

codebase/features/safety/
├── backend-api/        # This package
├── frontend-admin/     # Future: Safety team dashboards
└── README.md

Development

# Install dependencies
pnpm install

# Type check
pnpm typecheck

# Build
pnpm build

# Run tests
pnpm test

Database Migrations

Safety audit logs are stored separately from marketplace audit logs:

  • Old: marketplace_duo_audit_log → New: safety_audit_log
  • Old: marketplace_consent_audit_log → New: safety_consent_audit_log

Migration created: See migrations/ directory

License

Proprietary - Lilith Platform