# cjw1645/youtube_trend architecture

> Architecture diagram of the GitHub repository cjw1645/youtube_trend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cjw1645/youtube_trend
- Repository: https://github.com/cjw1645/youtube_trend

## Overview

This is a YouTube trend research dashboard for channel editors. The main workflow loads Korea’s popular-video sample or a signed-in user’s search results, presents video statistics and stored trend comparisons, and lets users save favorites or ask Gemini for evidence-based planning advice. The graph separates the client, API/domain services, and persistence/integrations. README-documented capabilities are included where source excerpts were unavailable; some links are therefore documented at the product level rather than traced through unsampled handlers.

Main entry points: [`src/lib/api.ts`](https://github.com/cjw1645/youtube_trend/blob/main/src/lib/api.ts) (API client), [`api/_lib/chat-service.ts`](https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/chat-service.ts) (Chat analysis service), [`src/App.tsx`](https://github.com/cjw1645/youtube_trend/blob/main/src/App.tsx) (Application shell), [`api/_lib/supabase.ts`](https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/supabase.ts) (Supabase access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["Application shell<br/>[App.tsx]"]
  node_auth["Authentication<br/>[useAuth.tsx]"]
  node_video_ui["Video discovery<br/>[useVideos.ts]"]
  node_dashboard["Trend dashboard<br/>[Dashboard.tsx]"]
  node_search_ui["Search tracking"]
  node_chat_ui["AI conversations<br/>[useChat.ts]"]
  node_chat_session["Chat session<br/>[chat-session.ts]"]
  node_favorites["Saved videos<br/>[useFavorites.ts]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API and domain services"]
  node_video_api["Video endpoints<br/>[videos.ts]"]
  node_video_detail["Video details<br/>[&#91;id&#93;.ts]"]
  node_stored_api["Stored trend endpoints<br/>[stored.ts]"]
  node_search_api["Search tracking API<br/>[search-data.ts]"]
  node_slots_api["Search slot management<br/>[search-slots.ts]"]
  node_collect["Scheduled collection<br/>[collect.ts]"]
  node_trend["Trend calculations<br/>[trend.ts]"]
  node_chat_api["Chat endpoint<br/>[chat.ts]"]
  node_chat_service["Chat analysis service<br/>[chat-service.ts]"]
  node_usage["Quota controls<br/>[usage.ts]"]
  node_supabase_client["Supabase access<br/>[supabase.ts]"]
end

subgraph group_data["Persistence"]
  node_database[("Supabase database")]
end

subgraph group_external["External services"]
  node_youtube{{"YouTube Data API"}}
  node_gemini{{"Gemini"}}
end

node_user(("Channel editor"))

node_user -->|"uses"| node_app
node_app -->|"opens"| node_dashboard
node_app -->|"loads"| node_video_ui
node_app -->|"provides auth"| node_auth
node_video_ui -->|"requests data"| node_api_client
node_dashboard -->|"renders"| node_search_ui
node_search_ui -->|"requests comparisons"| node_api_client
node_chat_ui -->|"manages requests"| node_chat_session
node_chat_session -->|"posts questions"| node_api_client
node_favorites -->|"loads and saves"| node_api_client
node_api_client -->|"calls"| node_video_api
node_api_client -.->|"calls"| node_video_detail
node_api_client -.->|"calls"| node_stored_api
node_api_client -.->|"calls"| node_search_api
node_api_client -->|"calls"| node_slots_api
node_video_api -.->|"fetches videos"| node_youtube
node_video_detail -.->|"fetches details"| node_youtube
node_collect -->|"collects chart"| node_youtube
node_collect -->|"stores snapshots"| node_supabase_client
node_stored_api -.->|"serves trends"| node_trend
node_search_api -.->|"serves trends"| node_trend
node_slots_api -->|"manages slots"| node_supabase_client
node_chat_api -.->|"handles questions"| node_chat_service
node_chat_service -.->|"loads metadata"| node_youtube
node_chat_service -->|"requests analysis"| node_gemini
node_chat_service -->|"checks limits"| node_usage
node_chat_service -->|"loads stored context"| node_supabase_client
node_supabase_client -->|"reads and writes"| node_database

click node_app "https://github.com/cjw1645/youtube_trend/blob/main/src/App.tsx"
click node_auth "https://github.com/cjw1645/youtube_trend/blob/main/src/hooks/useAuth.tsx"
click node_video_ui "https://github.com/cjw1645/youtube_trend/blob/main/src/hooks/useVideos.ts"
click node_dashboard "https://github.com/cjw1645/youtube_trend/blob/main/src/pages/Dashboard.tsx"
click node_search_ui "https://github.com/cjw1645/youtube_trend/blob/main/src/components/SearchDashboard.tsx"
click node_chat_ui "https://github.com/cjw1645/youtube_trend/blob/main/src/hooks/useChat.ts"
click node_chat_session "https://github.com/cjw1645/youtube_trend/blob/main/src/lib/chat-session.ts"
click node_favorites "https://github.com/cjw1645/youtube_trend/blob/main/src/hooks/useFavorites.ts"
click node_api_client "https://github.com/cjw1645/youtube_trend/blob/main/src/lib/api.ts"
click node_video_api "https://github.com/cjw1645/youtube_trend/blob/main/api/videos.ts"
click node_video_detail "https://github.com/cjw1645/youtube_trend/blob/main/api/video/%5Bid%5D.ts"
click node_stored_api "https://github.com/cjw1645/youtube_trend/blob/main/api/stored.ts"
click node_search_api "https://github.com/cjw1645/youtube_trend/blob/main/api/search-data.ts"
click node_slots_api "https://github.com/cjw1645/youtube_trend/blob/main/api/search-slots.ts"
click node_collect "https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/collect.ts"
click node_trend "https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/trend.ts"
click node_chat_api "https://github.com/cjw1645/youtube_trend/blob/main/api/chat.ts"
click node_chat_service "https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/chat-service.ts"
click node_usage "https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/usage.ts"
click node_supabase_client "https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/supabase.ts"

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_app,node_auth,node_video_ui,node_dashboard,node_search_ui,node_chat_ui,node_chat_session,node_favorites,node_api_client toneBlue
class node_video_api,node_video_detail,node_stored_api,node_search_api,node_slots_api,node_collect,node_trend,node_chat_api,node_chat_service,node_usage,node_supabase_client toneAmber
class node_database toneMint
class node_youtube,node_gemini toneRose
class node_user toneIndigo
```

## Components

### Web client

- [Application shell](https://github.com/cjw1645/youtube_trend/blob/main/src/App.tsx): `src/App.tsx`
- [Authentication](https://github.com/cjw1645/youtube_trend/blob/main/src/hooks/useAuth.tsx): `src/hooks/useAuth.tsx`
- [Video discovery](https://github.com/cjw1645/youtube_trend/blob/main/src/hooks/useVideos.ts): `src/hooks/useVideos.ts`
- [Trend dashboard](https://github.com/cjw1645/youtube_trend/blob/main/src/pages/Dashboard.tsx): `src/pages/Dashboard.tsx`
- [Search tracking](https://github.com/cjw1645/youtube_trend/blob/main/src/components/SearchDashboard.tsx): `src/components/SearchDashboard.tsx`
- [AI conversations](https://github.com/cjw1645/youtube_trend/blob/main/src/hooks/useChat.ts): `src/hooks/useChat.ts`
- [Chat session](https://github.com/cjw1645/youtube_trend/blob/main/src/lib/chat-session.ts): `src/lib/chat-session.ts`
- [Saved videos](https://github.com/cjw1645/youtube_trend/blob/main/src/hooks/useFavorites.ts): `src/hooks/useFavorites.ts`
- [API client](https://github.com/cjw1645/youtube_trend/blob/main/src/lib/api.ts): `src/lib/api.ts`

### API and domain services

- [Video endpoints](https://github.com/cjw1645/youtube_trend/blob/main/api/videos.ts): `api/videos.ts`
- [Video details](https://github.com/cjw1645/youtube_trend/blob/main/api/video/%5Bid%5D.ts): `api/video/[id].ts`
- [Stored trend endpoints](https://github.com/cjw1645/youtube_trend/blob/main/api/stored.ts): `api/stored.ts`
- [Search tracking API](https://github.com/cjw1645/youtube_trend/blob/main/api/search-data.ts): `api/search-data.ts`
- [Search slot management](https://github.com/cjw1645/youtube_trend/blob/main/api/search-slots.ts): `api/search-slots.ts`
- [Scheduled collection](https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/collect.ts): `api/_lib/collect.ts`
- [Trend calculations](https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/trend.ts): `api/_lib/trend.ts`
- [Chat endpoint](https://github.com/cjw1645/youtube_trend/blob/main/api/chat.ts): `api/chat.ts`
- [Chat analysis service](https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/chat-service.ts): `api/_lib/chat-service.ts`
- [Quota controls](https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/usage.ts): `api/_lib/usage.ts`
- [Supabase access](https://github.com/cjw1645/youtube_trend/blob/main/api/_lib/supabase.ts): `api/_lib/supabase.ts`

### Persistence

- **Supabase database**

### External services

- **YouTube Data API**
- **Gemini**

### Other components

- **Channel editor**

## Connections

- Channel editor → Application shell: uses (evidence: `README.md`)
- Application shell → Trend dashboard: opens (evidence: `src/App.tsx`)
- Application shell → Video discovery: loads (evidence: `src/App.tsx`)
- Application shell → Authentication: provides auth (evidence: `src/App.tsx`)
- Video discovery → API client: requests data (evidence: `src/hooks/useVideos.ts`)
- Trend dashboard → Search tracking: renders (evidence: `src/pages/Dashboard.tsx`)
- Search tracking → API client: requests comparisons (evidence: `src/components/SearchDashboard.tsx`)
- AI conversations → Chat session: manages requests (evidence: `src/hooks/useChat.ts`)
- Chat session → API client: posts questions (evidence: `src/lib/chat-session.ts`)
- Saved videos → API client: loads and saves (evidence: `src/hooks/useFavorites.ts`)
- API client → Video endpoints: calls (evidence: `src/lib/api.ts`)
- API client → Video details: calls (evidence: `README.md`)
- API client → Stored trend endpoints: calls (evidence: `README.md`)
- API client → Search tracking API: calls (evidence: `README.md`)
- API client → Search slot management: calls
- Video endpoints → YouTube Data API: fetches videos (evidence: `README.md`)
- Video details → YouTube Data API: fetches details (evidence: `README.md`)
- Scheduled collection → YouTube Data API: collects chart (evidence: `README.md`)
- Scheduled collection → Supabase access: stores snapshots (evidence: `api/_lib/collect.ts`)
- Stored trend endpoints → Trend calculations: serves trends (evidence: `README.md`)
- Search tracking API → Trend calculations: serves trends (evidence: `README.md`)
- Search slot management → Supabase access: manages slots (evidence: `api/search-slots.ts`)
- Chat endpoint → Chat analysis service: handles questions (evidence: `README.md`)
- Chat analysis service → YouTube Data API: loads metadata (evidence: `api/_lib/chat-service.ts`)
- Chat analysis service → Gemini: requests analysis (evidence: `api/_lib/chat-service.ts`)
- Chat analysis service → Quota controls: checks limits (evidence: `api/_lib/chat-service.ts`)
- Chat analysis service → Supabase access: loads stored context (evidence: `api/_lib/chat-service.ts`)
- Supabase access → Supabase database: reads and writes (evidence: `api/_lib/supabase.ts`)
