Skip to main content

Application Logic

:::info Source Sourced from services/media-service/APPLICATION_LOGIC.md in the documentation repo. :::

1. Application Services

  • UploadService — issue signed URLs; handle multipart.
  • ScannerService — AV + content-safety scan on S3 event.
  • TranscodeService — orchestrate transcode jobs (MediaConvert / ffmpeg workers).
  • CaptionService — request STT via ai-gateway; parse + store.
  • TranscriptService — full-transcript generation.
  • AIImageService — generate image via ai-gateway.
  • AIAudioService — TTS generation.
  • RetentionService — enforce tenant retention policies.

2. Commands

CommandTrigger
CreateUploadURLUser initiates upload
FinalizeUploadClient confirms completion
ScanAssetS3 event on asset arrival
QueueTranscodeAfter clean scan
GenerateCaptionsAsset ready (video/audio) or user request
GenerateTranscriptAsset ready or user request
GenerateImageUser request via AI
GenerateAudioUser request TTS
DeleteAssetUser request or retention policy

3. Queries

  • getAsset, listAssets(tenantId, filters), getVariants(assetId), getCaptions(assetId, language), getTranscript(assetId).

4. Sagas

  • Transcode Pipeline Saga: upload → scan → transcode → captions → transcript → ready.
  • GDPR Erasure Saga: delete assets owned by user; anonymize AI provenance.

5. Policies

  • Idempotency on uploads (client provides SHA-256; server dedups if exists).
  • Quarantine quarantines originating + variants; notifies security.
  • AI generation subject to ai-gateway budget.
  • Content-safety hits (CSAM, adult content) trigger immediate quarantine + law enforcement reporting procedure.

6. Use Case Flows

6.1 Video Upload + Transcode + Caption

POST /api/v1/media/upload-url → signed multipart S3 URL
Client uploads to S3.
S3 event → media-service.
Scan: ClamAV + content-safety classifier.
- clean → queue transcode (multiple variant profiles)
- hit → quarantine, alert security
Transcode completes → variants persisted.
Generate captions via ai-gateway STT.
Captions reviewable by author (HITL).
Emit ready event → authoring can reference.

6.2 AI Image Generation

Author: POST /api/v1/media/ai/generate-image { prompt, size, style }


Check ai-gateway budget.
Call ai-gateway with prompt (safety-moderated).
Receive image bytes.
Persist as MediaAsset with source='ai_generated'; aiProvenance attached.
Make variants.
Return asset.

6.3 TTS

Author: POST /api/v1/media/ai/generate-audio { text, voice, language }


Safety-check text; call ai-gateway TTS.
Persist as MediaAsset kind='ai_audio'.