# engrwardakhan-collab/youtube-ai-assistant-app architecture

> Architecture diagram of the GitHub repository engrwardakhan-collab/youtube-ai-assistant-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/engrwardakhan-collab/youtube-ai-assistant-app
- Repository: https://github.com/engrwardakhan-collab/youtube-ai-assistant-app

## Overview

The product is a human-in-the-loop YouTube comment assistant. Its main workflow fetches and deduplicates comments, triages them, drafts replies, saves them for review, and publishes only after approval. The CLI orchestrator and review UI are distinct entry points into that workflow; OAuth/token handling and runtime metrics are supporting layers. Several links come from the README or SOURCE INDEX because the relevant implementation excerpts are incomplete; optional or unverified links are dashed.

Main entry points: [`main.py`](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/main.py) (Fetch and draft run), [`app/review/webapp.py`](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/review/webapp.py) (Review web UI), [`app/youtube/comment_fetcher.py`](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/comment_fetcher.py) (Comment fetcher), [`app/auth/token_manager.py`](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/auth/token_manager.py) (Token manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Comment workflow"]
  node_main["Fetch and draft run<br/>[main.py]"]
  node_config["Settings<br/>[config.py]"]
  node_fetcher["Comment fetcher<br/>[comment_fetcher.py]"]
  node_youtube_client["YouTube client<br/>[youtube_client.py]"]
  node_checkpoint[("Fetch checkpoint")]
  node_replied[("Replied-comment state<br/>[replied_store.py]")]
end

subgraph group_auth["YouTube access"]
  node_oauth_manager["Token manager<br/>[token_manager.py]"]
  node_oauth_client["Google OAuth client"]
  node_token_store[("Token store<br/>[token_store.py]")]
end

subgraph group_review["Review and state"]
  node_draft_files[("Draft runtime files<br/>[main.py]")]
  node_webapp["Review web UI<br/>[webapp.py]"]
  node_stores[("Review stores<br/>[stores.py]")]
  node_poster["Reply poster<br/>[reply_poster.py]"]
  node_metrics[("Runtime metrics<br/>[metrics.py]")]
end

subgraph group_ai["AI processing"]
  node_triage["Triage routing<br/>[triage.py]"]
  node_triage_engine["Triage engine<br/>[triage_engine.py]"]
  node_drafter["Batch drafter<br/>[batch_drafter.py]"]
  node_openai["OpenAI client<br/>[openai_client.py]"]
end

node_operator(("Channel operator"))
node_openai_api{{"OpenAI API"}}
node_google_oauth{{"Google OAuth endpoint"}}
node_youtube_api{{"YouTube Data API"}}

node_operator -->|"runs refresh"| node_main
node_operator -->|"reviews drafts"| node_webapp
node_main -->|"loads settings"| node_config
node_main -->|"gets token"| node_oauth_manager
node_main -->|"fetches comments"| node_fetcher
node_main -->|"triages comments"| node_triage
node_main -->|"drafts replies"| node_drafter
node_main -->|"writes drafts"| node_draft_files
node_fetcher -->|"requests threads"| node_youtube_client
node_fetcher -->|"reads and saves"| node_checkpoint
node_fetcher -->|"checks IDs"| node_replied
node_youtube_client -->|"gets token"| node_oauth_manager
node_youtube_client -->|"requests data"| node_youtube_api
node_oauth_manager -->|"loads and saves"| node_token_store
node_oauth_manager -->|"refreshes token"| node_oauth_client
node_oauth_client -->|"requests refresh"| node_google_oauth
node_triage -->|"delegates triage"| node_triage_engine
node_drafter -.->|"requests completion"| node_openai
node_openai -->|"sends prompts"| node_openai_api
node_webapp -->|"runs refresh"| node_main
node_webapp -->|"reads and updates"| node_stores
node_webapp -->|"posts approval"| node_poster
node_poster -.->|"publishes reply"| node_youtube_api
node_webapp -->|"records metrics"| node_metrics
node_webapp -.->|"reviews drafts"| node_draft_files

click node_main "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/main.py"
click node_config "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/config.py"
click node_fetcher "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/comment_fetcher.py"
click node_youtube_client "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/youtube_client.py"
click node_checkpoint "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/checkpoint_store.py"
click node_replied "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/replied_store.py"
click node_triage "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/ai/triage.py"
click node_triage_engine "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/ai/triage_engine.py"
click node_drafter "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/ai/batch_drafter.py"
click node_openai "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/ai/openai_client.py"
click node_oauth_manager "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/auth/token_manager.py"
click node_oauth_client "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/auth/google_oauth_client.py"
click node_token_store "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/auth/token_store.py"
click node_draft_files "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/main.py"
click node_webapp "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/review/webapp.py"
click node_stores "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/review/stores.py"
click node_poster "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/reply_poster.py"
click node_metrics "https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/review/metrics.py"

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_main,node_config,node_fetcher,node_youtube_client,node_checkpoint,node_replied toneBlue
class node_oauth_manager,node_oauth_client,node_token_store toneAmber
class node_draft_files,node_webapp,node_stores,node_poster,node_metrics,node_openai_api,node_youtube_api toneMint
class node_triage,node_triage_engine,node_drafter,node_openai toneRose
class node_operator,node_google_oauth toneIndigo
```

## Components

### Comment workflow

- [Fetch and draft run](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/main.py): `main.py`
- [Settings](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/config.py): `app/config.py`
- [Comment fetcher](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/comment_fetcher.py): `app/youtube/comment_fetcher.py`
- [YouTube client](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/youtube_client.py): `app/youtube/youtube_client.py`
- [Fetch checkpoint](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/checkpoint_store.py): `app/youtube/checkpoint_store.py`
- [Replied-comment state](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/replied_store.py): `app/youtube/replied_store.py`

### YouTube access

- [Token manager](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/auth/token_manager.py): `app/auth/token_manager.py`
- [Google OAuth client](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/auth/google_oauth_client.py): `app/auth/google_oauth_client.py`
- [Token store](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/auth/token_store.py): `app/auth/token_store.py`

### Review and state

- [Draft runtime files](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/main.py): `main.py`
- [Review web UI](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/review/webapp.py): `app/review/webapp.py`
- [Review stores](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/review/stores.py): `app/review/stores.py`
- [Reply poster](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/youtube/reply_poster.py): `app/youtube/reply_poster.py`
- [Runtime metrics](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/review/metrics.py): `app/review/metrics.py`

### AI processing

- [Triage routing](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/ai/triage.py): `app/ai/triage.py`
- [Triage engine](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/ai/triage_engine.py): `app/ai/triage_engine.py`
- [Batch drafter](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/ai/batch_drafter.py): `app/ai/batch_drafter.py`
- [OpenAI client](https://github.com/engrwardakhan-collab/youtube-ai-assistant-app/blob/main/app/ai/openai_client.py): `app/ai/openai_client.py`

### Other components

- **Channel operator**
- **OpenAI API**
- **Google OAuth endpoint**
- **YouTube Data API**

## Connections

- Channel operator → Fetch and draft run: runs refresh (evidence: `README.md`)
- Channel operator → Review web UI: reviews drafts (evidence: `README.md`)
- Fetch and draft run → Settings: loads settings (evidence: `main.py`)
- Fetch and draft run → Token manager: gets token (evidence: `main.py`)
- Fetch and draft run → Comment fetcher: fetches comments (evidence: `main.py`)
- Fetch and draft run → Triage routing: triages comments (evidence: `main.py`)
- Fetch and draft run → Batch drafter: drafts replies (evidence: `main.py`)
- Fetch and draft run → Draft runtime files: writes drafts (evidence: `main.py`)
- Comment fetcher → YouTube client: requests threads (evidence: `app/youtube/comment_fetcher.py`)
- Comment fetcher → Fetch checkpoint: reads and saves (evidence: `app/youtube/comment_fetcher.py`)
- Comment fetcher → Replied-comment state: checks IDs (evidence: `app/youtube/comment_fetcher.py`)
- YouTube client → Token manager: gets token (evidence: `app/youtube/youtube_client.py`)
- YouTube client → YouTube Data API: requests data (evidence: `app/youtube/youtube_client.py`)
- Token manager → Token store: loads and saves (evidence: `app/auth/token_manager.py`)
- Token manager → Google OAuth client: refreshes token (evidence: `app/auth/token_manager.py`)
- Google OAuth client → Google OAuth endpoint: requests refresh (evidence: `app/auth/google_oauth_client.py`)
- Triage routing → Triage engine: delegates triage (evidence: `app/ai/triage.py`)
- Batch drafter → OpenAI client: requests completion
- OpenAI client → OpenAI API: sends prompts (evidence: `app/ai/openai_client.py`)
- Review web UI → Fetch and draft run: runs refresh (evidence: `app/review/webapp.py`)
- Review web UI → Review stores: reads and updates (evidence: `app/review/webapp.py`)
- Review web UI → Reply poster: posts approval (evidence: `app/review/webapp.py`)
- Reply poster → YouTube Data API: publishes reply
- Review web UI → Runtime metrics: records metrics (evidence: `app/review/webapp.py`)
- Review web UI → Draft runtime files: reviews drafts (evidence: `app/review/webapp.py`)
