# jsmastery-pro/vertex-learning-platform architecture

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

- Interactive diagram: https://gitdiagram.com/jsmastery-pro/vertex-learning-platform
- Repository: https://github.com/jsmastery-pro/vertex-learning-platform

## Overview

#### Purpose and Runtime
Vertex is a TypeScript/Next.js learning platform for browsing courses, consuming video lessons, and natural-language video search with timecode-level results. The root Next.js App Router application is the learner-facing runtime; Sanity Studio is a separate CMS runtime. Primary entry points: `app/layout.tsx`, `app/page.tsx`, and `studio/sanity.config.ts`.

#### Application Routing and Access
App Router pages expose the course catalog, course and lesson detail pages, search, and Clerk-hosted sign-in/up flows. `proxy.ts` is the request boundary for Clerk route protection/session handling. Key routes are `app/courses/page.tsx`, `app/courses/[slug]/page.tsx`, `app/lessons/[slug]/page.tsx`, `app/search/page.tsx`, and `app/sign-in/[[...sign-in]]/page.tsx`.

#### Content Delivery Layer
Sanity is the source of truth for courses, instructors, lessons, videos, modules, resources, and timecoded video chunks. The application accesses it through a dedicated client/fetch/query layer rather than embedding CMS calls in UI: `sanity/lib/client.ts`, `sanity/lib/fetch.ts`, `sanity/lib/queries.ts`. Generated content types are represented by `sanity.types.ts`; server-side Sanity reads require `SANITY_API_READ_TOKEN`.

#### Learner Experience Composition
Route pages assemble domain components for catalog cards, course presentation/progress, and lesson consumption. The course layer is centered on `components/course/course-content.tsx`, `components/course/course-hero.tsx`, and `components/cards/course-grid.tsx`. The lesson layer combines playback, curriculum navigation, notes/resources, and completion context through `components/lesson/lesson-video.tsx`, `components/lesson/lesson-sidebar.tsx`, and `components/lesson/lesson-tabs.tsx`. Video URL/provider handling is isolated in `lib/video.ts`.

#### Intelligent Search Pipeline
The browser search UI posts to `app/api/search/route.ts`. That server endpoint is the security boundary for OpenAI and Sanity Context MCP credentials, coordinating agent grounding and response generation via `lib/search/ground.ts`, `lib/search/mcp.ts`, and `lib/search/system-prompt.ts`. Search result contracts live in `lib/search/types.ts`; rendered results distinguish lessons and videos in `components/search/search-results.tsx` and `components/search/video-result-card.tsx`. Results link learners to lesson/video locations, including relevant timestamps.

#### CMS Studio and Content Ingestion
The independently deployable Sanity Studio defines editorial structure and authoring UI in `studio/sanity.config.ts` and `studio/structure.ts`. Its core schema establishes the course-to-module-to-lesson/video model in `studio/schemaTypes/documents/course.ts`, `studio/schemaTypes/documents/lesson.ts`, and `studio/schemaTypes/documents/video.ts`. Video ingestion scripts parse provider URLs, chunk material for retrieval, and produce NDJSON: `studio/scripts/ingest/ingest-videos.mjs`, `studio/scripts/ingest/chunk.mjs`, and `studio/scripts/ingest/providers/youtube.mjs`. The checked-in `studio/scripts/context/vertex-search.ndjson` is retrieval/context data.

#### Identity and Analytics Boundaries
Clerk provides authentication and protected-route enforcement, with UI entry points under `app/sign-in/` and `app/sign-up/`; secret keys remain server-only. PostHog tracks client and server events: `instrumentation-client.ts`, `lib/posthog-server.ts`, and canonical event definitions in `lib/analytics/events.ts`. Lesson view/watch tracking and search-result context connect learner activity to analytics through `components/lesson/lesson-view-tracker.tsx` and `lib/analytics/search-result-context.ts`.

#### Infrastructure Dependencies
Node.js/npm run two JavaScript/TypeScript applications: the Next.js frontend/API and Sanity Studio. External managed services are Sanity (content, assets, context MCP), OpenAI (search-agent generation), Clerk (identity), PostHog (analytics), and YouTube as an ingestion source. Environment boundaries and required credentials are documented in `.env.example`.

Main entry points: [`components/lesson/lesson-video.tsx`](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/components/lesson/lesson-video.tsx) (Lesson experience), [`app/layout.tsx`](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/app/layout.tsx) (App shell & routes), [`components/search/search-results.tsx`](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/components/search/search-results.tsx) (Search results UI), [`sanity/lib/fetch.ts`](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/sanity/lib/fetch.ts) (Sanity delivery layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_learner["Next.js Learner App"]
  node_app_shell["App shell &amp; routes<br/>Next.js App Router<br/>[layout.tsx]"]
  node_access_proxy["Access proxy<br/>Clerk middleware<br/>[proxy.ts]"]
  node_course_experience["Course experience<br/>course components<br/>[course-content.tsx]"]
  node_lesson_experience["Lesson experience<br/>lesson components<br/>[lesson-video.tsx]"]
  node_video_provider["Video provider handling<br/>video utility<br/>[video.ts]"]
  node_analytics["Learner analytics<br/>PostHog integration<br/>[events.ts]"]
end

subgraph group_content["Content Platform"]
  node_sanity_delivery["Sanity delivery layer<br/>CMS client and queries<br/>[fetch.ts]"]
  node_content_types["Generated content types<br/>TypeScript contracts<br/>[sanity.types.ts]"]
  node_sanity_studio["Sanity Studio<br/>CMS runtime<br/>[sanity.config.ts]"]
  node_content_schema["Course/lesson/video schema<br/>Sanity schemas<br/>[course.ts]"]
  node_video_ingestion["Video ingestion<br/>Node scripts<br/>[ingest-videos.mjs]"]
  node_retrieval_context["Search context data<br/>NDJSON"]
end

subgraph group_search["Search Pipeline"]
  node_search_ui["Search results UI<br/>React components<br/>[search-results.tsx]"]
  node_search_api["Search API<br/>Next.js route handler<br/>[route.ts]"]
  node_search_agent["Grounded search agent<br/>search orchestration<br/>[ground.ts]"]
end

subgraph group_services["Managed Services"]
  node_clerk{{"Clerk<br/>identity service"}}
  node_sanity[("Sanity<br/>content and Context MCP")]
  node_openai{{"OpenAI<br/>generation service"}}
  node_posthog{{"PostHog<br/>analytics service"}}
  node_youtube{{"YouTube<br/>video source"}}
end

node_app_shell -->|"requests pass through"| node_access_proxy
node_access_proxy -->|"sessions and protection"| node_clerk
node_app_shell -->|"renders course views"| node_course_experience
node_app_shell -->|"renders lesson views"| node_lesson_experience
node_course_experience -->|"loads course content"| node_sanity_delivery
node_lesson_experience -->|"loads lesson content"| node_sanity_delivery
node_lesson_experience -->|"resolves playback URL"| node_video_provider
node_sanity_delivery -->|"uses typed content"| node_content_types
node_sanity_delivery -->|"queries content"| node_sanity
node_sanity_studio -->|"registers schemas"| node_content_schema
node_sanity_studio -->|"authors content"| node_sanity
node_video_ingestion -->|"imports provider videos"| node_youtube
node_video_ingestion -->|"produces chunks"| node_retrieval_context
node_video_ingestion -->|"publishes video content"| node_sanity
node_search_ui -->|"posts natural-language query"| node_search_api
node_app_shell -->|"renders search page"| node_search_ui
node_search_api -->|"coordinates search"| node_search_agent
node_search_agent -->|"grounds via Context MCP"| node_sanity
node_search_agent -->|"generates response"| node_openai
node_search_ui -.->|"links to timestamped lessons"| node_lesson_experience
node_lesson_experience -->|"records view/watch events"| node_analytics
node_search_ui -->|"records result context"| node_analytics
node_analytics -->|"sends events"| node_posthog

click node_app_shell "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/app/layout.tsx"
click node_access_proxy "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/proxy.ts"
click node_course_experience "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/components/course/course-content.tsx"
click node_lesson_experience "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/components/lesson/lesson-video.tsx"
click node_video_provider "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/lib/video.ts"
click node_analytics "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/lib/analytics/events.ts"
click node_sanity_delivery "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/sanity/lib/fetch.ts"
click node_content_types "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/sanity.types.ts"
click node_sanity_studio "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/studio/sanity.config.ts"
click node_content_schema "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/studio/schemaTypes/documents/course.ts"
click node_video_ingestion "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/studio/scripts/ingest/ingest-videos.mjs"
click node_retrieval_context "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/studio/scripts/context/vertex-search.ndjson"
click node_search_ui "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/components/search/search-results.tsx"
click node_search_api "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/app/api/search/route.ts"
click node_search_agent "https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/lib/search/ground.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_shell,node_access_proxy,node_course_experience,node_lesson_experience,node_video_provider,node_analytics toneBlue
class node_sanity_delivery,node_content_types,node_sanity_studio,node_content_schema,node_video_ingestion,node_retrieval_context toneAmber
class node_search_ui,node_search_api,node_search_agent toneMint
class node_clerk,node_sanity,node_openai,node_posthog,node_youtube toneRose
```

## Components

### Next.js Learner App

Learner-facing web runtime and API.

- [App shell & routes](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/app/layout.tsx): Next.js App Router · Catalog, course, lesson, search, and auth pages. · `app/layout.tsx`
- [Access proxy](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/proxy.ts): Clerk middleware · Protects routes and handles sessions. · `proxy.ts`
- [Course experience](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/components/course/course-content.tsx): course components · Course hero, content, and catalog grid. · `components/course/course-content.tsx`
- [Lesson experience](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/components/lesson/lesson-video.tsx): lesson components · Playback, curriculum, resources, and completion UI. · `components/lesson/lesson-video.tsx`
- [Video provider handling](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/lib/video.ts): video utility · `lib/video.ts`
- [Learner analytics](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/lib/analytics/events.ts): PostHog integration · Tracks lesson and search activity. · `lib/analytics/events.ts`

### Content Platform

Sanity delivery and authoring.

- [Sanity delivery layer](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/sanity/lib/fetch.ts): CMS client and queries · Dedicated typed server-side content reads. · `sanity/lib/fetch.ts`
- [Generated content types](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/sanity.types.ts): TypeScript contracts · `sanity.types.ts`
- [Sanity Studio](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/studio/sanity.config.ts): CMS runtime · Editorial authoring and content structure. · `studio/sanity.config.ts`
- [Course/lesson/video schema](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/studio/schemaTypes/documents/course.ts): Sanity schemas · Defines the course-to-module-to-lesson/video model. · `studio/schemaTypes/documents/course.ts`
- [Video ingestion](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/studio/scripts/ingest/ingest-videos.mjs): Node scripts · Parses providers and creates retrieval chunks. · `studio/scripts/ingest/ingest-videos.mjs`
- [Search context data](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/studio/scripts/context/vertex-search.ndjson): NDJSON · Checked-in retrieval/context corpus. · `studio/scripts/context/vertex-search.ndjson`

### Search Pipeline

Grounded natural-language video search.

- [Search results UI](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/components/search/search-results.tsx): React components · Renders lesson/video results with timestamps. · `components/search/search-results.tsx`
- [Search API](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/app/api/search/route.ts): Next.js route handler · Server credential boundary and search coordinator. · `app/api/search/route.ts`
- [Grounded search agent](https://github.com/jsmastery-pro/vertex-learning-platform/blob/main/lib/search/ground.ts): search orchestration · MCP grounding, prompt, and response contracts. · `lib/search/ground.ts`

### Managed Services

- **Clerk**: identity service
- **Sanity**: content and Context MCP
- **OpenAI**: generation service
- **PostHog**: analytics service
- **YouTube**: video source

## Connections

- App shell & routes → Access proxy: requests pass through
- Access proxy → Clerk: sessions and protection
- App shell & routes → Course experience: renders course views
- App shell & routes → Lesson experience: renders lesson views
- Course experience → Sanity delivery layer: loads course content
- Lesson experience → Sanity delivery layer: loads lesson content
- Lesson experience → Video provider handling: resolves playback URL
- Sanity delivery layer → Generated content types: uses typed content
- Sanity delivery layer → Sanity: queries content
- Sanity Studio → Course/lesson/video schema: registers schemas
- Sanity Studio → Sanity: authors content
- Video ingestion → YouTube: imports provider videos
- Video ingestion → Search context data: produces chunks
- Video ingestion → Sanity: publishes video content
- Search results UI → Search API: posts natural-language query
- App shell & routes → Search results UI: renders search page
- Search API → Grounded search agent: coordinates search
- Grounded search agent → Sanity: grounds via Context MCP
- Grounded search agent → OpenAI: generates response
- Search results UI → Lesson experience: links to timestamped lessons
- Lesson experience → Learner analytics: records view/watch events
- Search results UI → Learner analytics: records result context
- Learner analytics → PostHog: sends events
