flowchart TD
  VInput["Video input"] --> ExtractAudio["Extract audio\n(ffmpeg)"]
  ExtractAudio --> Transcribe["Transcription\n(faster-whisper / openai-whisper)"]
  Transcribe --> Segments["Segments\n(start/end/text)"]
  Segments --> Translate["Translation decision\n(usecase)"]
  Translate -->|local| LocalTranslate["Local MarianMT\n(Helsinki-NLP)"]
  Translate -->|remote| GeminiAPI["Gemini / LLM HTTP API"]
  LocalTranslate --> SRTGen["Generate SRT\n(translated)"]
  GeminiAPI --> SRTGen
  SRTGen --> KokoroTTS["Kokoro TTS\n(per-segment synth)"]
  KokoroTTS --> ChunkAdjust["Align / Pad / Trim\n(per segment)"]
  ChunkAdjust --> Concat["Concat / Normalize WAVs"]
  Concat --> AudioProc["FFmpeg Audio Proc\n(replace or mix)"]
  AudioProc --> BurnSubs["Burn subtitles (ffmpeg)"]
  BurnSubs --> Output["output/<basename>/\n(final artifacts)"]

  %% Agrupar visualmente (se mantiene la semántica, ahora vertical)
  subgraph InfraAdapters [Infra adapters]
    direction TB
    ExtractAudio
    Transcribe
    KokoroTTS
    AudioProc
  end

  subgraph Usecase [Usecase / Orchestrator]
    direction TB
    Transcribe
    Translate
    SRTGen
    Concat
  end

  %% servicios auxiliares (con conexiones punteadas)
  Logs["Logging (logs/infra, logs/usecases, logs/cli)"]
  Cache["Model cache (~/.cache/transformers)"]
  Logs -.-> Transcribe
  Logs -.-> KokoroTTS
  Cache -.-> Transcribe
  Cache -.-> LocalTranslate

  classDef infra fill:#f8f9fa,stroke:#0366d6,color:#000
  class InfraAdapters infra
