| .. | ||
| scripts | ||
| src | ||
| .swcrc | ||
| jest.config.js | ||
| nest-cli.json | ||
| package.json | ||
| pnpm-lock.yaml | ||
| README.md | ||
| tsconfig.json | ||
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 activatedPARTNERSHIP_COERCION_FLAGGED- Coercion/abuse flag was raisedPARTNERSHIP_CONSENT_REQUESTED- Consent reconfirmation requestedPARTNERSHIP_CONSENT_WITHDRAWN- Member withdrew consentPARTNERSHIP_SAFETY_ALERT- High/critical risk detectedPARTNERSHIP_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:
DuoSafetyService→PartnershipSafetyServiceDuoConsentService→ConsentManagementServiceDuoFlagDetectorService→CoercionDetectorServiceDuoAuditLog→SafetyAuditLog- 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