import { * } from 'sruja.ai/stdlib'

YouTube = system "Video Platform" {
  description "Video upload, transcoding, and playback platform"

  WebApp = container "Web App" {
    technology "React"
    description "User-facing web application"
  }
  API = container "API Server" {
    technology "Go"
    description "Backend API for video metadata and upload"
  }

  Transcoder = container "Transcoding Service" {
    technology "FFmpeg"
    description "Converts raw video to HLS format"
    scale { min 50 }
  }

  S3 = database "Blob Storage" {
    technology "S3-compatible object storage"
    description "Stores raw and processed video files"
  }

  MetadataDB = database "Metadata DB" {
    technology "PostgreSQL"
    description "Stores video metadata, encoding status, and playlists"
  }

  CDNEdge = container "CDN Edge Cache" {
    technology "Cloudflare / Akamai"
    description "Edge cache serving video chunks"
  }

  WebApp -> API "HTTPS"
  API -> MetadataDB "Reads/Writes"
  API -> S3 "Uploads"
  API -> Transcoder "Triggers"
  Transcoder -> S3 "Reads/Writes"
  Transcoder -> MetadataDB "Updates status"
}

User = person "Viewer"

User -> YouTube "Watches videos"
YouTube.CDNEdge -> YouTube.S3 "Fetch chunks (cache miss)"

deployment GlobalInfra "Global Infrastructure" {
  node OriginDC "Origin Data Center" {
    containerInstance WebApp
    containerInstance API
    containerInstance Transcoder
    containerInstance S3
  }

  node CDN "CDN (Edge Locations)" "Cloudflare / Akamai" {
    containerInstance CDNEdge
    node USEast "US-East Edge"
    node Europe "Europe Edge"
    node Asia "Asia Edge"
  }
}

scenario WatchVideo "User watches a video" {
  User -> WebApp "Get Video Page"
  WebApp -> API "Get Metadata (Title, URL)"
  API -> MetadataDB "Query"
  API -> User "Return Video Manifest URL"
  User -> CDNEdge "Request Video Chunk (1080p)"
  CDNEdge -> User "Stream Chunk"
}
