# bharathlakkoju/tubecp architecture

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

- Interactive diagram: https://gitdiagram.com/bharathlakkoju/tubecp
- Repository: https://github.com/bharathlakkoju/tubecp

## Overview

TubeCP is a YouTube research product: a signed-in user submits a topic, receives ranked video results, can turn those results into a persistent knowledge base, and asks source-grounded questions against it. The graph preserves the documented subscription, team-workspace, and hosted MCP capabilities. Source excerpts show the research and chat request ownership clearly; KB build internals, billing callbacks, and several integrations are represented at their exact directory or route paths, with uncertain connections omitted.

Main entry points: [`app/api/research/route.ts`](https://github.com/bharathlakkoju/tubecp/blob/master/app/api/research/route.ts) (Research endpoint), [`lib/billing/subscription.ts`](https://github.com/bharathlakkoju/tubecp/blob/master/lib/billing/subscription.ts) (Plans and usage), [`app/api/chat/route.ts`](https://github.com/bharathlakkoju/tubecp/blob/master/app/api/chat/route.ts) (Chat endpoint), [`app/(product)/app/AppResearchClient.tsx`](https://github.com/bharathlakkoju/tubecp/blob/master/app/(product)/app/AppResearchClient.tsx) (Research workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Product experience"]
  node_research_ui["Research workspace"]
  node_research_list["Research history"]
  node_result_view["Ranked results"]
end

subgraph group_research["Research workflow"]
  node_research_api["Research endpoint<br/>[route.ts]"]
  node_research_pipeline["Topic research"]
  node_query_expansion["Query expansion<br/>[query-expansion.ts]"]
  node_youtube_search["YouTube search<br/>[youtube-search.ts]"]
  node_relevance["Relevance analysis<br/>[relevance.ts]"]
  node_saved_research["Saved research<br/>[saved-research.ts]"]
end

subgraph group_knowledge["Knowledge bases"]
  node_kb_api["Knowledge-base API"]
  node_kb_orchestrator["Build orchestration<br/>[orchestrator.ts]"]
  node_kb_pipeline["Build workers"]
  node_kb_services["KB services<br/>[knowledge-base.ts]"]
  node_vector_index[("Vector index<br/>[vector-index.ts]")]
  node_kb_chat_api["Chat endpoint<br/>[route.ts]"]
  node_chat_service["Chat service<br/>[chat.ts]"]
  node_chat_history["Chat history<br/>[kb-chat.ts]"]
end

subgraph group_platform["Accounts and platform"]
  node_subscription["Plans and usage<br/>[subscription.ts]"]
  node_plans["Plan limits<br/>[plans.ts]"]
  node_auth["Session access<br/>[auth.ts]"]
  node_store[("Application storage<br/>[store.ts]")]
  node_redis[("Redis adapter<br/>[redis.ts]")]
  node_billing_api["Billing routes"]
  node_polar_webhook["Billing webhook<br/>[route.ts]"]
  node_workspace["Team workspace<br/>[workspaces.ts]"]
  node_mcp_api["Hosted MCP<br/>[route.ts]"]
  node_mcp_server["MCP tools<br/>[create-server.ts]"]
end

node_user(("Researcher"))
node_youtube(("YouTube"))
node_postgres[("Neon Postgres")]
node_polar(("Polar billing"))

node_user -->|"submits topic"| node_research_ui
node_research_ui -->|"requests research"| node_research_api
node_research_api -->|"requires session"| node_auth
node_research_api -->|"checks usage"| node_subscription
node_research_api -->|"runs pipeline"| node_research_pipeline
node_research_pipeline -->|"expands topic"| node_query_expansion
node_research_pipeline -->|"searches videos"| node_youtube_search
node_research_pipeline -->|"analyzes candidates"| node_relevance
node_youtube_search -.->|"searches"| node_youtube
node_research_api -->|"persists results"| node_saved_research
node_research_api -->|"caches results"| node_store
node_research_ui -->|"renders results"| node_result_view
node_user -->|"views history"| node_research_list
node_research_api -.->|"saves for listing"| node_research_list
node_research_ui -.->|"starts KB build"| node_kb_api
node_kb_api -.->|"checks access"| node_auth
node_kb_api -.->|"checks allowance"| node_subscription
node_kb_api -.->|"dispatches build"| node_kb_orchestrator
node_kb_orchestrator -->|"coordinates jobs"| node_kb_pipeline
node_kb_orchestrator -->|"invokes build"| node_kb_services
node_kb_pipeline -->|"indexes content"| node_kb_services
node_kb_pipeline -->|"stores embeddings"| node_vector_index
node_user -->|"asks question"| node_kb_chat_api
node_kb_chat_api -->|"requires session"| node_auth
node_kb_chat_api -->|"meters messages"| node_subscription
node_kb_chat_api -->|"streams answer"| node_chat_service
node_kb_chat_api -->|"appends messages"| node_chat_history
node_chat_service -.->|"retrieves sources"| node_vector_index
node_subscription -->|"applies limits"| node_plans
node_subscription -->|"reads subscription"| node_postgres
node_subscription -->|"applies team plan"| node_workspace
node_store -->|"uses cache"| node_redis
node_store -->|"reads and writes"| node_postgres
node_billing_api -.->|"requires session"| node_auth
node_billing_api -.->|"creates checkout"| node_polar
node_polar -.->|"sends events"| node_polar_webhook
node_polar_webhook -.->|"syncs plan"| node_subscription
node_user -.->|"connects AI client"| node_mcp_api
node_mcp_api -->|"creates server"| node_mcp_server

click node_research_ui "https://github.com/bharathlakkoju/tubecp/blob/master/app/(product)/app/AppResearchClient.tsx"
click node_research_api "https://github.com/bharathlakkoju/tubecp/blob/master/app/api/research/route.ts"
click node_research_pipeline "https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/research-pipeline.ts"
click node_query_expansion "https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/query-expansion.ts"
click node_youtube_search "https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/youtube-search.ts"
click node_relevance "https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/relevance.ts"
click node_saved_research "https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/saved-research.ts"
click node_research_list "https://github.com/bharathlakkoju/tubecp/blob/master/app/(product)/app/researches/ResearchListClient.tsx"
click node_result_view "https://github.com/bharathlakkoju/tubecp/blob/master/components/ResearchResults.tsx"
click node_kb_api "https://github.com/bharathlakkoju/tubecp/tree/master/app/api/knowledge-base"
click node_kb_orchestrator "https://github.com/bharathlakkoju/tubecp/blob/master/lib/kb/orchestrator.ts"
click node_kb_pipeline "https://github.com/bharathlakkoju/tubecp/tree/master/lib/pipeline"
click node_kb_services "https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/knowledge-base.ts"
click node_vector_index "https://github.com/bharathlakkoju/tubecp/blob/master/lib/store/vector-index.ts"
click node_kb_chat_api "https://github.com/bharathlakkoju/tubecp/blob/master/app/api/chat/route.ts"
click node_chat_service "https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/chat.ts"
click node_chat_history "https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/kb-chat.ts"
click node_subscription "https://github.com/bharathlakkoju/tubecp/blob/master/lib/billing/subscription.ts"
click node_plans "https://github.com/bharathlakkoju/tubecp/blob/master/lib/plans.ts"
click node_auth "https://github.com/bharathlakkoju/tubecp/blob/master/lib/auth.ts"
click node_store "https://github.com/bharathlakkoju/tubecp/blob/master/lib/store.ts"
click node_redis "https://github.com/bharathlakkoju/tubecp/blob/master/lib/store/redis.ts"
click node_billing_api "https://github.com/bharathlakkoju/tubecp/tree/master/app/api/billing"
click node_polar_webhook "https://github.com/bharathlakkoju/tubecp/blob/master/app/api/webhook/polar/route.ts"
click node_workspace "https://github.com/bharathlakkoju/tubecp/blob/master/lib/workspaces.ts"
click node_mcp_api "https://github.com/bharathlakkoju/tubecp/blob/master/app/api/mcp/route.ts"
click node_mcp_server "https://github.com/bharathlakkoju/tubecp/blob/master/mcp/create-server.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_research_ui,node_research_list,node_result_view toneBlue
class node_research_api,node_research_pipeline,node_query_expansion,node_youtube_search,node_relevance,node_saved_research,node_postgres toneAmber
class node_kb_api,node_kb_orchestrator,node_kb_pipeline,node_kb_services,node_vector_index,node_kb_chat_api,node_chat_service,node_chat_history toneMint
class node_subscription,node_plans,node_auth,node_store,node_redis,node_billing_api,node_polar_webhook,node_workspace,node_mcp_api,node_mcp_server toneRose
class node_user,node_youtube,node_polar toneIndigo
```

## Components

### Product experience

- [Research workspace](https://github.com/bharathlakkoju/tubecp/blob/master/app/(product)/app/AppResearchClient.tsx): `app/(product)/app/AppResearchClient.tsx`
- [Research history](https://github.com/bharathlakkoju/tubecp/blob/master/app/(product)/app/researches/ResearchListClient.tsx): `app/(product)/app/researches/ResearchListClient.tsx`
- [Ranked results](https://github.com/bharathlakkoju/tubecp/blob/master/components/ResearchResults.tsx): `components/ResearchResults.tsx`

### Research workflow

- [Research endpoint](https://github.com/bharathlakkoju/tubecp/blob/master/app/api/research/route.ts): `app/api/research/route.ts`
- [Topic research](https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/research-pipeline.ts): `lib/services/research-pipeline.ts`
- [Query expansion](https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/query-expansion.ts): `lib/services/query-expansion.ts`
- [YouTube search](https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/youtube-search.ts): `lib/services/youtube-search.ts`
- [Relevance analysis](https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/relevance.ts): `lib/services/relevance.ts`
- [Saved research](https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/saved-research.ts): `lib/services/saved-research.ts`

### Knowledge bases

- [Knowledge-base API](https://github.com/bharathlakkoju/tubecp/tree/master/app/api/knowledge-base): `app/api/knowledge-base`
- [Build orchestration](https://github.com/bharathlakkoju/tubecp/blob/master/lib/kb/orchestrator.ts): `lib/kb/orchestrator.ts`
- [Build workers](https://github.com/bharathlakkoju/tubecp/tree/master/lib/pipeline): `lib/pipeline`
- [KB services](https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/knowledge-base.ts): `lib/services/knowledge-base.ts`
- [Vector index](https://github.com/bharathlakkoju/tubecp/blob/master/lib/store/vector-index.ts): `lib/store/vector-index.ts`
- [Chat endpoint](https://github.com/bharathlakkoju/tubecp/blob/master/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Chat service](https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/chat.ts): `lib/services/chat.ts`
- [Chat history](https://github.com/bharathlakkoju/tubecp/blob/master/lib/services/kb-chat.ts): `lib/services/kb-chat.ts`

### Accounts and platform

- [Plans and usage](https://github.com/bharathlakkoju/tubecp/blob/master/lib/billing/subscription.ts): `lib/billing/subscription.ts`
- [Plan limits](https://github.com/bharathlakkoju/tubecp/blob/master/lib/plans.ts): `lib/plans.ts`
- [Session access](https://github.com/bharathlakkoju/tubecp/blob/master/lib/auth.ts): `lib/auth.ts`
- [Application storage](https://github.com/bharathlakkoju/tubecp/blob/master/lib/store.ts): `lib/store.ts`
- [Redis adapter](https://github.com/bharathlakkoju/tubecp/blob/master/lib/store/redis.ts): `lib/store/redis.ts`
- [Billing routes](https://github.com/bharathlakkoju/tubecp/tree/master/app/api/billing): `app/api/billing`
- [Billing webhook](https://github.com/bharathlakkoju/tubecp/blob/master/app/api/webhook/polar/route.ts): `app/api/webhook/polar/route.ts`
- [Team workspace](https://github.com/bharathlakkoju/tubecp/blob/master/lib/workspaces.ts): `lib/workspaces.ts`
- [Hosted MCP](https://github.com/bharathlakkoju/tubecp/blob/master/app/api/mcp/route.ts): `app/api/mcp/route.ts`
- [MCP tools](https://github.com/bharathlakkoju/tubecp/blob/master/mcp/create-server.ts): `mcp/create-server.ts`

### Other components

- **Researcher**
- **YouTube**
- **Neon Postgres**
- **Polar billing**

## Connections

- Researcher → Research workspace: submits topic (evidence: `app/(product)/app/AppResearchClient.tsx`)
- Research workspace → Research endpoint: requests research (evidence: `app/(product)/app/AppResearchClient.tsx`)
- Research endpoint → Session access: requires session (evidence: `app/api/research/route.ts`)
- Research endpoint → Plans and usage: checks usage (evidence: `app/api/research/route.ts`)
- Research endpoint → Topic research: runs pipeline (evidence: `app/api/research/route.ts`)
- Topic research → Query expansion: expands topic (evidence: `lib/services/research-pipeline.ts`)
- Topic research → YouTube search: searches videos (evidence: `lib/services/research-pipeline.ts`)
- Topic research → Relevance analysis: analyzes candidates (evidence: `lib/services/research-pipeline.ts`)
- YouTube search → YouTube: searches
- Research endpoint → Saved research: persists results (evidence: `app/api/research/route.ts`)
- Research endpoint → Application storage: caches results (evidence: `app/api/research/route.ts`)
- Research workspace → Ranked results: renders results (evidence: `app/(product)/app/AppResearchClient.tsx`)
- Researcher → Research history: views history (evidence: `app/(product)/app/researches/ResearchListClient.tsx`)
- Research endpoint → Research history: saves for listing
- Research workspace → Knowledge-base API: starts KB build
- Knowledge-base API → Session access: checks access
- Knowledge-base API → Plans and usage: checks allowance
- Knowledge-base API → Build orchestration: dispatches build
- Build orchestration → Build workers: coordinates jobs (evidence: `lib/kb/orchestrator.ts`)
- Build orchestration → KB services: invokes build (evidence: `lib/kb/orchestrator.ts`)
- Build workers → KB services: indexes content (evidence: `lib/pipeline/embed-worker.ts`)
- Build workers → Vector index: stores embeddings (evidence: `lib/pipeline/embed-worker.ts`)
- Researcher → Chat endpoint: asks question (evidence: `app/api/chat/route.ts`)
- Chat endpoint → Session access: requires session (evidence: `app/api/chat/route.ts`)
- Chat endpoint → Plans and usage: meters messages (evidence: `app/api/chat/route.ts`)
- Chat endpoint → Chat service: streams answer (evidence: `app/api/chat/route.ts`)
- Chat endpoint → Chat history: appends messages (evidence: `app/api/chat/route.ts`)
- Chat service → Vector index: retrieves sources
- Plans and usage → Plan limits: applies limits (evidence: `lib/billing/subscription.ts`)
- Plans and usage → Neon Postgres: reads subscription (evidence: `lib/billing/subscription.ts`)
- Plans and usage → Team workspace: applies team plan (evidence: `lib/billing/subscription.ts`)
- Application storage → Redis adapter: uses cache (evidence: `lib/store.ts`)
- Application storage → Neon Postgres: reads and writes (evidence: `lib/store.ts`)
- Billing routes → Session access: requires session (evidence: `app/api/billing/change-plan/route.ts`)
- Billing routes → Polar billing: creates checkout
- Polar billing → Billing webhook: sends events
- Billing webhook → Plans and usage: syncs plan
- Researcher → Hosted MCP: connects AI client
- Hosted MCP → MCP tools: creates server (evidence: `app/api/mcp/route.ts`)
