# ieee-sb-vit-pune/agentplay architecture

> Architecture diagram of the GitHub repository ieee-sb-vit-pune/agentplay, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ieee-sb-vit-pune/agentplay
- Repository: https://github.com/ieee-sb-vit-pune/agentplay

## Overview

#### Purpose and Entry Points
This repository is a YouTube learning/translation companion: a Chrome extension augments YouTube pages while a Python backend extracts transcripts, generates AI summaries/notes/Q&A, translates timed segments, and returns synthesized audio. Backend startup is `backend/main.py`; the unpacked browser-extension entry is `frontend/extension/manifest.json`.

#### Browser Extension Client
The extension runs page-facing logic through `frontend/extension/content.js`, coordinates YouTube navigation/state through `frontend/extension/navigation.js`, and exposes controls via `frontend/extension/popup.js` and `frontend/extension/sidebar.html`. It detects video context, renders transcript/translation UI, tracks playback to synchronize highlighted lines, locally caches transcript-related state, and requests backend artifacts or audio on demand.

#### HTTP API and Orchestration
`backend/main.py` is the application boundary between the extension and content-processing services. It serves endpoints for transcript and metadata retrieval, summaries/notes, audio by video/language/segment, precomputation, and POST-based video Q&A. Its primary control flow keys work by YouTube video ID, target language, and transcript segment index.

#### Transcript and Cache Pipeline
The backend fetches YouTube transcripts, determines whether source text needs English normalization, and retains reusable transcript/derived artifacts so repeated client requests can avoid regeneration. Full-video text supports summary, notes, and Q&A; individual timestamped segments support playback-aligned translation/audio. This storage/cache responsibility is centered in `backend/main.py`.

#### AI Translation and Content Agents
`backend/crew_helper.py` encapsulates CrewAI-oriented content processing used by the backend. Translation handles large transcript input in chunks and translates requested segments with a nearby context window; this preserves local meaning while permitting independently generated audio. The same backend workflow invokes AI-generated concise summaries, structured notes, and answers to video-specific queries.

#### Audio Delivery
For a requested `(video_id, target_language, segment_number)`, the system resolves or creates a translated segment, synthesizes speech with Edge TTS, caches the resulting audio, and returns it to the extension. `frontend/extension/content.js` aligns returned audio with current YouTube playback; `backend/main.py` owns the server-side retrieval/generation path.

#### Runtime and External Boundaries
The backend is Python with dependencies declared in `backend/requirements.txt`; it requires root-level environment credentials for Gemini, Serper, and Mistral services. External integrations include YouTube transcript/metadata access, LLM and search-backed agent services, CrewAI orchestration, and Edge TTS. The frontend is a Chrome extension governed by `frontend/extension/manifest.json`, requiring browser permissions to interact with YouTube pages and inject its interface.

Main entry points: [`backend/main.py`](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/main.py) (HTTP API & cache owner), [`frontend/extension/content.js`](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/content.js) (Page UI & playback sync), [`frontend/extension/manifest.json`](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/manifest.json) (Extension manifest), [`backend/crew_helper.py`](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/crew_helper.py) (Summary, notes & Q&A)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Chrome Extension"]
  node_manifest["Extension manifest<br/>Chrome extension entry<br/>[manifest.json]"]
  node_content["Page UI &amp; playback sync<br/>content script<br/>[content.js]"]
  node_navigation["YouTube navigation state<br/>navigation script<br/>[navigation.js]"]
  node_popup_sidebar["Extension controls<br/>popup and sidebar<br/>[popup.js]"]
  node_local_cache[("Local transcript state<br/>browser cache<br/>[content.js]")]
end

subgraph group_backend["Python Backend"]
  node_api{{"HTTP API &amp; cache owner<br/>Python application<br/>[main.py]"}}
  node_transcript_pipeline["Transcript &amp; normalization<br/>processing flow<br/>[main.py]"]
  node_artifact_cache[("Transcript artifact cache<br/>derived content cache<br/>[main.py]")]
  node_content_agents["Summary, notes &amp; Q&amp;A<br/>CrewAI workflow<br/>[crew_helper.py]"]
  node_translation["Contextual translation<br/>translation workflow<br/>[crew_helper.py]"]
  node_audio["Segment audio generation<br/>audio delivery flow<br/>[main.py]"]
  node_dependencies["Backend dependencies<br/>Python requirements<br/>[requirements.txt]"]
end

subgraph group_external["External Services"]
  node_youtube(("YouTube transcripts &amp; metadata<br/>YouTube integration"))
  node_llm_services(("LLM and search agents<br/>Gemini, Mistral, Serper"))
  node_crewai(("CrewAI<br/>agent orchestration"))
  node_edge_tts(("Edge TTS<br/>speech synthesis"))
end

node_manifest -->|"injects"| node_content
node_manifest -->|"loads"| node_navigation
node_manifest -->|"exposes"| node_popup_sidebar
node_navigation -->|"updates video context"| node_content
node_content -->|"caches state"| node_local_cache
node_content -->|"requests artifacts and audio"| node_api
node_api -->|"retrieves transcript"| node_transcript_pipeline
node_transcript_pipeline -->|"fetches timed text"| node_youtube
node_api -->|"reads and writes"| node_artifact_cache
node_api -->|"requests learning artifacts"| node_content_agents
node_api -->|"requests segment translation"| node_translation
node_content_agents -->|"orchestrates"| node_crewai
node_content_agents -->|"uses"| node_llm_services
node_translation -->|"uses"| node_llm_services
node_api -->|"serves requested segment"| node_audio
node_audio -->|"resolves translation"| node_translation
node_audio -->|"synthesizes speech"| node_edge_tts
node_dependencies -.->|"runtime dependencies"| node_api

click node_manifest "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/manifest.json"
click node_content "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/content.js"
click node_navigation "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/navigation.js"
click node_popup_sidebar "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/popup.js"
click node_local_cache "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/content.js"
click node_api "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/main.py"
click node_transcript_pipeline "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/main.py"
click node_artifact_cache "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/main.py"
click node_content_agents "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/crew_helper.py"
click node_translation "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/crew_helper.py"
click node_audio "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/main.py"
click node_dependencies "https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/requirements.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_manifest,node_content,node_navigation,node_popup_sidebar,node_local_cache toneBlue
class node_api,node_transcript_pipeline,node_artifact_cache,node_content_agents,node_translation,node_audio,node_dependencies toneAmber
class node_youtube,node_llm_services,node_crewai,node_edge_tts toneMint
```

## Components

### Chrome Extension

- [Extension manifest](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/manifest.json): Chrome extension entry · Declares YouTube access and extension runtime. · `frontend/extension/manifest.json`
- [Page UI & playback sync](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/content.js): content script · Renders learning UI and aligns transcript/audio to playback. · `frontend/extension/content.js`
- [YouTube navigation state](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/navigation.js): navigation script · Coordinates page changes and video context. · `frontend/extension/navigation.js`
- [Extension controls](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/popup.js): popup and sidebar · `frontend/extension/popup.js`
- [Local transcript state](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/frontend/extension/content.js): browser cache · `frontend/extension/content.js`

### Python Backend

- [HTTP API & cache owner](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/main.py): Python application · Keys reusable artifacts by video, language, and segment. · `backend/main.py`
- [Transcript & normalization](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/main.py): processing flow · Retrieves timed text and normalizes source text to English when needed. · `backend/main.py`
- [Transcript artifact cache](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/main.py): derived content cache · Stores transcripts, translations, generated content, and audio. · `backend/main.py`
- [Summary, notes & Q&A](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/crew_helper.py): CrewAI workflow · Generates full-video learning artifacts and query answers. · `backend/crew_helper.py`
- [Contextual translation](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/crew_helper.py): translation workflow · Chunks large transcripts and translates segments with nearby context. · `backend/crew_helper.py`
- [Segment audio generation](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/main.py): audio delivery flow · Resolves translated segments and synthesizes cacheable speech. · `backend/main.py`
- [Backend dependencies](https://github.com/ieee-sb-vit-pune/agentplay/blob/main/backend/requirements.txt): Python requirements · `backend/requirements.txt`

### External Services

- **YouTube transcripts & metadata**: YouTube integration
- **LLM and search agents**: Gemini, Mistral, Serper · Credentials are supplied through root-level environment settings.
- **CrewAI**: agent orchestration
- **Edge TTS**: speech synthesis

## Connections

- Extension manifest → Page UI & playback sync: injects
- Extension manifest → YouTube navigation state: loads
- Extension manifest → Extension controls: exposes
- YouTube navigation state → Page UI & playback sync: updates video context
- Page UI & playback sync → Local transcript state: caches state
- Page UI & playback sync → HTTP API & cache owner: requests artifacts and audio
- HTTP API & cache owner → Transcript & normalization: retrieves transcript
- Transcript & normalization → YouTube transcripts & metadata: fetches timed text
- HTTP API & cache owner → Transcript artifact cache: reads and writes
- HTTP API & cache owner → Summary, notes & Q&A: requests learning artifacts
- HTTP API & cache owner → Contextual translation: requests segment translation
- Summary, notes & Q&A → CrewAI: orchestrates
- Summary, notes & Q&A → LLM and search agents: uses
- Contextual translation → LLM and search agents: uses
- HTTP API & cache owner → Segment audio generation: serves requested segment
- Segment audio generation → Contextual translation: resolves translation
- Segment audio generation → Edge TTS: synthesizes speech
- Backend dependencies → HTTP API & cache owner: runtime dependencies
