# agricidaniel/youtubepro architecture

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

- Interactive diagram: https://gitdiagram.com/agricidaniel/youtubepro
- Repository: https://github.com/agricidaniel/youtubepro

## Overview

#### Purpose and runtime entry points
YouTube Pro is a local-first workspace that turns public YouTube metadata into evidence-grounded research, Gemini-assisted ideas and scripts, and generated thumbnail packages. The browser entry point is `client/src/main.tsx`; the Express server starts from `server/index.ts` and serves API routes plus the Vite/production client bundle.

#### Client workflow shell
`client/src/App.tsx` composes the application shell, navigation, and workflow-aware pages. The principal stages are Research, Script Writer, Thumbnail Creator, and Settings, implemented in `client/src/pages/research.tsx`, `client/src/pages/script.tsx`, `client/src/pages/thumbnail.tsx`, and `client/src/pages/settings.tsx`. The legacy ideas route is folded into Research rather than represented as a separate page.

#### Local workflow persistence and state boundary
The client owns project history and active workflow state; no server database or session store exists. `client/src/lib/workflow-context.tsx` provides shared workflow state, while `client/src/lib/workflow-storage.ts` persists up to eight recent workflows in browser IndexedDB. Stored state includes snapshots, ideas, scripts, briefs, and results, but intentionally excludes uploaded thumbnail reference files and all API keys.

#### Research ingestion and analytics
Research begins in the client and calls server routes defined in `server/routes.ts`. The YouTube provider in `server/youtube.ts` searches and enriches up to 50 public videos with statistics, durations, captions, tags, status, live details, and channel metadata. The resulting ordered snapshot, deterministic analytics, filters, coverage, warnings, and snapshot identity form the evidence boundary consumed by subsequent AI stages.

#### Evidence contracts and AI generation
Shared schemas/contracts enforce the handoff from research to Gemini: `shared/schema.ts`, `shared/evidence-contracts.ts`, and `shared/research-contracts.test.ts`. `server/gemini.ts` invokes Google Gemini through server-held credentials; `server/gemini-models.ts` controls permitted text/image models. Insights, ideas, scripts, and section/paragraph regeneration must use bounded context from the active snapshot rather than arbitrary client claims. Script regeneration contracts are centralized in `server/script-regeneration-contract.ts`.

#### Thumbnail generation pipeline
The thumbnail page gathers a selected promise/concept, controls, and at most three browser-prepared image references. `server/thumbnail-contract.ts` validates bounded request semantics; `server/gemini.ts` submits permitted references and prompts to Gemini image generation. Generated outputs return to the current local workflow; reference uploads are not retained after the request/session workflow restoration boundary.

#### Server security and infrastructure boundaries
Express middleware and route assembly reside in `server/index.ts` and `server/routes.ts`; static/Vite serving is separated into `server/static.ts` and `server/vite.ts`. Server-only settings in `server/settings.ts` update ignored `.env` values without returning secrets to the client. `server/rate-limit.ts` applies an in-memory, per-process limit to billable YouTube/Gemini endpoints. The intended deployment is a loopback-bound Node.js 22+ process (`127.0.0.1:5000` by default), integrating only YouTube Data API v3 and Google Gemini; it is not designed as a publicly exposed multi-user service.

Main entry points: [`server/routes.ts`](https://github.com/agricidaniel/youtubepro/blob/main/server/routes.ts) (API routes), [`client/src/App.tsx`](https://github.com/agricidaniel/youtubepro/blob/main/client/src/App.tsx) (Workflow shell), [`server/gemini.ts`](https://github.com/agricidaniel/youtubepro/blob/main/server/gemini.ts) (Gemini generation), [`client/src/pages/research.tsx`](https://github.com/agricidaniel/youtubepro/blob/main/client/src/pages/research.tsx) (Research)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_client_entry["Client entry<br/>React bootstrap<br/>[main.tsx]"]
  node_app_shell["Workflow shell<br/>React app<br/>[App.tsx]"]
  node_workflow_state["Workflow state<br/>context"]
  node_workflow_storage[("Local workflow store<br/>IndexedDB persistence")]
  node_research_page["Research<br/>workflow page<br/>[research.tsx]"]
  node_script_page["Script Writer<br/>workflow page<br/>[script.tsx]"]
  node_thumbnail_page["Thumbnail Creator<br/>workflow page<br/>[thumbnail.tsx]"]
  node_settings_page["Settings<br/>workflow page<br/>[settings.tsx]"]
end

subgraph group_server["Loopback Node server"]
  node_server_entry["Express server<br/>Node entry<br/>[index.ts]"]
  node_routes["API routes<br/>route assembly<br/>[routes.ts]"]
  node_youtube["YouTube ingestion<br/>provider adapter<br/>[youtube.ts]"]
  node_gemini["Gemini generation<br/>provider adapter<br/>[gemini.ts]"]
  node_server_controls["Server controls<br/>security infrastructure<br/>[rate-limit.ts]"]
  node_thumbnail_contract["Thumbnail request contract<br/>server contract"]
end

subgraph group_shared["Shared contracts"]
  node_evidence_contracts["Evidence contracts<br/>shared schemas"]
  node_script_contract["Script regeneration contract<br/>shared contract"]
end

subgraph group_external["External APIs"]
  node_youtube_api{{"YouTube Data API v3<br/>metadata API"}}
  node_gemini_api{{"Google Gemini<br/>AI API"}}
end

node_client_entry -->|"mounts"| node_app_shell
node_app_shell -->|"research stage"| node_research_page
node_app_shell -->|"script stage"| node_script_page
node_app_shell -->|"thumbnail stage"| node_thumbnail_page
node_app_shell -->|"settings stage"| node_settings_page
node_app_shell -->|"uses"| node_workflow_state
node_workflow_state -->|"persists snapshots and outputs"| node_workflow_storage
node_research_page -->|"research requests"| node_routes
node_script_page -->|"grounded generation"| node_routes
node_thumbnail_page -->|"generation request"| node_routes
node_settings_page -->|"updates server settings"| node_routes
node_server_entry -->|"mounts"| node_routes
node_server_entry -->|"applies middleware and serving"| node_server_controls
node_routes -->|"rate-limited endpoints"| node_server_controls
node_routes -->|"delegates ingestion"| node_youtube
node_youtube -->|"public metadata"| node_youtube_api
node_routes -->|"delegates AI requests"| node_gemini
node_gemini -->|"text and image generation"| node_gemini_api
node_research_page -->|"creates bounded snapshot"| node_evidence_contracts
node_evidence_contracts -->|"grounds insights and ideas"| node_gemini
node_script_contract -->|"bounds regeneration"| node_gemini
node_thumbnail_contract -->|"validates image request"| node_gemini
node_gemini -->|"returns generated outputs"| node_workflow_state

click node_client_entry "https://github.com/agricidaniel/youtubepro/blob/main/client/src/main.tsx"
click node_app_shell "https://github.com/agricidaniel/youtubepro/blob/main/client/src/App.tsx"
click node_workflow_state "https://github.com/agricidaniel/youtubepro/blob/main/client/src/lib/workflow-context.tsx"
click node_workflow_storage "https://github.com/agricidaniel/youtubepro/blob/main/client/src/lib/workflow-storage.ts"
click node_research_page "https://github.com/agricidaniel/youtubepro/blob/main/client/src/pages/research.tsx"
click node_script_page "https://github.com/agricidaniel/youtubepro/blob/main/client/src/pages/script.tsx"
click node_thumbnail_page "https://github.com/agricidaniel/youtubepro/blob/main/client/src/pages/thumbnail.tsx"
click node_settings_page "https://github.com/agricidaniel/youtubepro/blob/main/client/src/pages/settings.tsx"
click node_server_entry "https://github.com/agricidaniel/youtubepro/blob/main/server/index.ts"
click node_routes "https://github.com/agricidaniel/youtubepro/blob/main/server/routes.ts"
click node_youtube "https://github.com/agricidaniel/youtubepro/blob/main/server/youtube.ts"
click node_gemini "https://github.com/agricidaniel/youtubepro/blob/main/server/gemini.ts"
click node_server_controls "https://github.com/agricidaniel/youtubepro/blob/main/server/rate-limit.ts"
click node_evidence_contracts "https://github.com/agricidaniel/youtubepro/blob/main/shared/evidence-contracts.ts"
click node_script_contract "https://github.com/agricidaniel/youtubepro/blob/main/server/script-regeneration-contract.ts"
click node_thumbnail_contract "https://github.com/agricidaniel/youtubepro/blob/main/server/thumbnail-contract.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_client_entry,node_app_shell,node_workflow_state,node_workflow_storage,node_research_page,node_script_page,node_thumbnail_page,node_settings_page toneBlue
class node_server_entry,node_routes,node_youtube,node_gemini,node_server_controls,node_thumbnail_contract toneAmber
class node_evidence_contracts,node_script_contract toneMint
class node_youtube_api,node_gemini_api toneRose
```

## Components

### Browser client

Local workflow UI and persistence.

- [Client entry](https://github.com/agricidaniel/youtubepro/blob/main/client/src/main.tsx): React bootstrap · `client/src/main.tsx`
- [Workflow shell](https://github.com/agricidaniel/youtubepro/blob/main/client/src/App.tsx): React app · Navigation and stage composition. · `client/src/App.tsx`
- [Workflow state](https://github.com/agricidaniel/youtubepro/blob/main/client/src/lib/workflow-context.tsx): context · Active workflow and project history boundary. · `client/src/lib/workflow-context.tsx`
- [Local workflow store](https://github.com/agricidaniel/youtubepro/blob/main/client/src/lib/workflow-storage.ts): IndexedDB persistence · Retains up to eight workflows without keys or reference files. · `client/src/lib/workflow-storage.ts`
- [Research](https://github.com/agricidaniel/youtubepro/blob/main/client/src/pages/research.tsx): workflow page · `client/src/pages/research.tsx`
- [Script Writer](https://github.com/agricidaniel/youtubepro/blob/main/client/src/pages/script.tsx): workflow page · `client/src/pages/script.tsx`
- [Thumbnail Creator](https://github.com/agricidaniel/youtubepro/blob/main/client/src/pages/thumbnail.tsx): workflow page · Prepares up to three transient image references. · `client/src/pages/thumbnail.tsx`
- [Settings](https://github.com/agricidaniel/youtubepro/blob/main/client/src/pages/settings.tsx): workflow page · `client/src/pages/settings.tsx`

### Loopback Node server

Express API and provider boundary.

- [Express server](https://github.com/agricidaniel/youtubepro/blob/main/server/index.ts): Node entry · Loopback server serving APIs and client bundle. · `server/index.ts`
- [API routes](https://github.com/agricidaniel/youtubepro/blob/main/server/routes.ts): route assembly · Research and billable generation endpoints. · `server/routes.ts`
- [YouTube ingestion](https://github.com/agricidaniel/youtubepro/blob/main/server/youtube.ts): provider adapter · Searches and enriches up to 50 public videos. · `server/youtube.ts`
- [Gemini generation](https://github.com/agricidaniel/youtubepro/blob/main/server/gemini.ts): provider adapter · Creates grounded text and thumbnail outputs. · `server/gemini.ts`
- [Server controls](https://github.com/agricidaniel/youtubepro/blob/main/server/rate-limit.ts): security infrastructure · Rate limits, manages secrets, and serves static or Vite assets. · `server/rate-limit.ts`
- [Thumbnail request contract](https://github.com/agricidaniel/youtubepro/blob/main/server/thumbnail-contract.ts): server contract · Validates bounded concepts, controls, and references. · `server/thumbnail-contract.ts`

### Shared contracts

Evidence and request contracts.

- [Evidence contracts](https://github.com/agricidaniel/youtubepro/blob/main/shared/evidence-contracts.ts): shared schemas · Bounds research evidence passed into AI stages. · `shared/evidence-contracts.ts`
- [Script regeneration contract](https://github.com/agricidaniel/youtubepro/blob/main/server/script-regeneration-contract.ts): shared contract · `server/script-regeneration-contract.ts`

### External APIs

- **YouTube Data API v3**: metadata API
- **Google Gemini**: AI API

## Connections

- Client entry → Workflow shell: mounts
- Workflow shell → Research: research stage
- Workflow shell → Script Writer: script stage
- Workflow shell → Thumbnail Creator: thumbnail stage
- Workflow shell → Settings: settings stage
- Workflow shell → Workflow state: uses
- Workflow state → Local workflow store: persists snapshots and outputs
- Research → API routes: research requests
- Script Writer → API routes: grounded generation
- Thumbnail Creator → API routes: generation request
- Settings → API routes: updates server settings
- Express server → API routes: mounts
- Express server → Server controls: applies middleware and serving
- API routes → Server controls: rate-limited endpoints
- API routes → YouTube ingestion: delegates ingestion
- YouTube ingestion → YouTube Data API v3: public metadata
- API routes → Gemini generation: delegates AI requests
- Gemini generation → Google Gemini: text and image generation
- Research → Evidence contracts: creates bounded snapshot
- Evidence contracts → Gemini generation: grounds insights and ideas
- Script regeneration contract → Gemini generation: bounds regeneration
- Thumbnail request contract → Gemini generation: validates image request
- Gemini generation → Workflow state: returns generated outputs
