# dinuradamsara99/cinemanest-automated architecture

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

- Interactive diagram: https://gitdiagram.com/dinuradamsara99/cinemanest-automated
- Repository: https://github.com/dinuradamsara99/cinemanest-automated

## Overview

This repository is a Next.js movie and TV streaming catalog. A viewer can browse catalog pages, open a title, and use its watch-page player and related features; the sampled watch route shows catalog data being fetched before the client watch experience is rendered. Separate branches support comments, AI insights, watch progress, user requests, and automated content ingestion. The source index identifies these capabilities, but several route and component bodies were not sampled, so their internal connections are omitted where not evidenced.

Main entry points: [`lib/automation/pipeline.ts`](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/pipeline.ts) (Ingestion pipeline), [`components/WatchPageClient.tsx`](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/WatchPageClient.tsx) (Watch experience), [`lib/auth.ts`](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/auth.ts) (Authentication), [`lib/rate-limiter.ts`](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/rate-limiter.ts) (Rate limiting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_catalog["Catalog browsing"]
  node_catalog_pages["Catalog pages<br/>[page.tsx]"]
  node_category_language["Category and language<br/>[page.tsx]"]
  node_search_api["Search API<br/>[route.ts]"]
  node_catalog_data["Catalog queries<br/>[sanity.ts]"]
  node_content_grid["Content grid<br/>[ContentGrid.tsx]"]
  node_media_card["Media cards<br/>[MediaCard.tsx]"]
end

subgraph group_watch["Viewing experience"]
  node_watch_route["Watch route<br/>[page.tsx]"]
  node_watch_client["Watch experience"]
  node_video_player["Video player"]
  node_video_resolver["Video resolver<br/>[video-resolver.ts]"]
  node_resolve_api["Resolve video API<br/>[route.ts]"]
  node_subtitle_download["Subtitle downloads"]
end

subgraph group_engagement["Viewer features"]
  node_comments_ui["Comments<br/>[CommentSection.tsx]"]
  node_comments_api["Comments API<br/>[route.ts]"]
  node_comments_store["Comment queries<br/>[comments.ts]"]
  node_ai_insights["AI insights"]
  node_ai_api["AI insights API<br/>[route.ts]"]
  node_progress_api["Watch progress API<br/>[route.ts]"]
  node_request_api["Request API<br/>[route.ts]"]
  node_request_actions["Request actions<br/>[movie-request.ts]"]
end

subgraph group_content["Content operations"]
  node_automation["Scrape automation<br/>[route.ts]"]
  node_pipeline["Ingestion pipeline<br/>[pipeline.ts]"]
  node_scraper["Movie scraper<br/>[scraper.ts]"]
  node_link_validator["Link validation<br/>[link-validator.ts]"]
  node_tmdb_enricher["TMDB enrichment<br/>[tmdb-enricher.ts]"]
  node_ai_generator["Description generation<br/>[ai-generator.ts]"]
  node_publisher["Sanity publishing"]
  node_sanity_cms[("Sanity CMS<br/>[client.ts]")]
end

subgraph group_platform["Identity and safeguards"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_prisma[("User database<br/>[prisma.ts]")]
  node_security["Security utilities<br/>[security.ts]"]
  node_rate_limiter["Rate limiting<br/>[rate-limiter.ts]"]
  node_redis[("Upstash Redis")]
end

node_viewer(("Viewer"))

node_viewer -.->|"browses"| node_catalog_pages
node_catalog_pages -.->|"fetches content"| node_catalog_data
node_category_language -->|"fetches content"| node_catalog_data
node_category_language -->|"renders"| node_content_grid
node_category_language -->|"renders"| node_media_card
node_search_api -->|"searches"| node_catalog_data
node_viewer -.->|"opens title"| node_watch_route
node_watch_route -->|"fetches title"| node_catalog_data
node_watch_route -->|"renders"| node_watch_client
node_watch_client -->|"renders"| node_video_player
node_watch_client -->|"renders"| node_subtitle_download
node_watch_client -->|"renders"| node_comments_ui
node_watch_client -->|"renders"| node_ai_insights
node_resolve_api -->|"resolves stream"| node_video_resolver
node_comments_ui -.->|"loads and posts"| node_comments_api
node_comments_api -->|"uses queries"| node_comments_store
node_comments_api -->|"limits requests"| node_rate_limiter
node_ai_insights -.->|"requests insights"| node_ai_api
node_ai_api -->|"checks session"| node_auth
node_ai_api -->|"verifies and sanitizes"| node_security
node_ai_api -->|"limits requests"| node_rate_limiter
node_progress_api -->|"checks session"| node_auth
node_request_api -->|"checks session"| node_auth
node_request_api -->|"validates input"| node_security
node_request_api -->|"limits requests"| node_rate_limiter
node_request_api -.->|"submits request"| node_sanity_cms
node_automation -.->|"starts pipeline"| node_pipeline
node_pipeline -->|"scrapes titles"| node_scraper
node_pipeline -->|"validates links"| node_link_validator
node_pipeline -->|"enriches titles"| node_tmdb_enricher
node_pipeline -->|"generates descriptions"| node_ai_generator
node_pipeline -->|"publishes titles"| node_publisher
node_publisher -.->|"writes content"| node_sanity_cms
node_auth -->|"reads user data"| node_prisma
node_auth -->|"logs auth events"| node_security
node_rate_limiter -->|"gets client IP"| node_security
node_rate_limiter -.->|"uses when configured"| node_redis

click node_catalog_pages "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/(main)/(home)/page.tsx"
click node_category_language "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/category/%5Bslug%5D/page.tsx"
click node_search_api "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/search/route.ts"
click node_catalog_data "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/sanity.ts"
click node_content_grid "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/ContentGrid.tsx"
click node_media_card "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/MediaCard.tsx"
click node_watch_route "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/(main)/watch/%5Bslug%5D/page.tsx"
click node_watch_client "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/WatchPageClient.tsx"
click node_video_player "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/CustomVideoPlayer.tsx"
click node_video_resolver "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/video-resolver.ts"
click node_resolve_api "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/resolve-video/route.ts"
click node_subtitle_download "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/SubtitleDownload.tsx"
click node_comments_ui "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/CommentSection.tsx"
click node_comments_api "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/comments/route.ts"
click node_comments_store "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/queries/comments.ts"
click node_ai_insights "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/VideoAIInsights.tsx"
click node_ai_api "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/ai-insights/route.ts"
click node_progress_api "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/watch-progress/route.ts"
click node_request_api "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/request/route.ts"
click node_request_actions "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/actions/movie-request.ts"
click node_automation "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/cron/scrape-movies/route.ts"
click node_pipeline "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/pipeline.ts"
click node_scraper "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/scraper.ts"
click node_link_validator "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/link-validator.ts"
click node_tmdb_enricher "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/tmdb-enricher.ts"
click node_ai_generator "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/ai-generator.ts"
click node_publisher "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/sanity-publisher.ts"
click node_sanity_cms "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/sanity/lib/client.ts"
click node_auth "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/auth.ts"
click node_prisma "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/prisma.ts"
click node_security "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/security.ts"
click node_rate_limiter "https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/rate-limiter.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_catalog_pages,node_category_language,node_search_api,node_catalog_data,node_content_grid,node_media_card,node_viewer toneBlue
class node_watch_route,node_watch_client,node_video_player,node_video_resolver,node_resolve_api,node_subtitle_download toneAmber
class node_comments_ui,node_comments_api,node_comments_store,node_ai_insights,node_ai_api,node_progress_api,node_request_api,node_request_actions toneMint
class node_automation,node_pipeline,node_scraper,node_link_validator,node_tmdb_enricher,node_ai_generator,node_publisher,node_sanity_cms toneRose
class node_auth,node_prisma,node_security,node_rate_limiter,node_redis toneIndigo
```

## Components

### Catalog browsing

- [Catalog pages](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/(main)/(home)/page.tsx): `app/(main)/(home)/page.tsx`
- [Category and language](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/category/%5Bslug%5D/page.tsx): `app/category/[slug]/page.tsx`
- [Search API](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/search/route.ts): `app/api/search/route.ts`
- [Catalog queries](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/sanity.ts): `lib/sanity.ts`
- [Content grid](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/ContentGrid.tsx): `components/ContentGrid.tsx`
- [Media cards](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/MediaCard.tsx): `components/MediaCard.tsx`

### Viewing experience

- [Watch route](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/(main)/watch/%5Bslug%5D/page.tsx): `app/(main)/watch/[slug]/page.tsx`
- [Watch experience](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/WatchPageClient.tsx): `components/WatchPageClient.tsx`
- [Video player](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/CustomVideoPlayer.tsx): `components/CustomVideoPlayer.tsx`
- [Video resolver](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/video-resolver.ts): `lib/video-resolver.ts`
- [Resolve video API](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/resolve-video/route.ts): `app/api/resolve-video/route.ts`
- [Subtitle downloads](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/SubtitleDownload.tsx): `components/SubtitleDownload.tsx`

### Viewer features

- [Comments](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/CommentSection.tsx): `components/CommentSection.tsx`
- [Comments API](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/comments/route.ts): `app/api/comments/route.ts`
- [Comment queries](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/queries/comments.ts): `lib/queries/comments.ts`
- [AI insights](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/components/VideoAIInsights.tsx): `components/VideoAIInsights.tsx`
- [AI insights API](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/ai-insights/route.ts): `app/api/ai-insights/route.ts`
- [Watch progress API](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/watch-progress/route.ts): `app/api/watch-progress/route.ts`
- [Request API](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/request/route.ts): `app/api/request/route.ts`
- [Request actions](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/actions/movie-request.ts): `app/actions/movie-request.ts`

### Content operations

- [Scrape automation](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/app/api/cron/scrape-movies/route.ts): `app/api/cron/scrape-movies/route.ts`
- [Ingestion pipeline](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/pipeline.ts): `lib/automation/pipeline.ts`
- [Movie scraper](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/scraper.ts): `lib/automation/scraper.ts`
- [Link validation](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/link-validator.ts): `lib/automation/link-validator.ts`
- [TMDB enrichment](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/tmdb-enricher.ts): `lib/automation/tmdb-enricher.ts`
- [Description generation](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/ai-generator.ts): `lib/automation/ai-generator.ts`
- [Sanity publishing](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/automation/sanity-publisher.ts): `lib/automation/sanity-publisher.ts`
- [Sanity CMS](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/sanity/lib/client.ts): `sanity/lib/client.ts`

### Identity and safeguards

- [Authentication](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/auth.ts): `lib/auth.ts`
- [User database](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/prisma.ts): `lib/prisma.ts`
- [Security utilities](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/security.ts): `lib/security.ts`
- [Rate limiting](https://github.com/dinuradamsara99/cinemanest-automated/blob/main/lib/rate-limiter.ts): `lib/rate-limiter.ts`
- **Upstash Redis**

### Other components

- **Viewer**

## Connections

- Viewer → Catalog pages: browses
- Catalog pages → Catalog queries: fetches content
- Category and language → Catalog queries: fetches content (evidence: `app/category/[slug]/page.tsx`)
- Category and language → Content grid: renders (evidence: `app/category/[slug]/page.tsx`)
- Category and language → Media cards: renders (evidence: `app/category/[slug]/page.tsx`)
- Search API → Catalog queries: searches (evidence: `app/api/search/route.ts`)
- Viewer → Watch route: opens title
- Watch route → Catalog queries: fetches title (evidence: `app/(main)/watch/[slug]/page.tsx`)
- Watch route → Watch experience: renders (evidence: `app/(main)/watch/[slug]/page.tsx`)
- Watch experience → Video player: renders (evidence: `components/WatchPageClient.tsx`)
- Watch experience → Subtitle downloads: renders (evidence: `components/WatchPageClient.tsx`)
- Watch experience → Comments: renders (evidence: `components/WatchPageClient.tsx`)
- Watch experience → AI insights: renders (evidence: `components/WatchPageClient.tsx`)
- Resolve video API → Video resolver: resolves stream (evidence: `app/api/resolve-video/route.ts`)
- Comments → Comments API: loads and posts
- Comments API → Comment queries: uses queries
- Comments API → Rate limiting: limits requests (evidence: `app/api/comments/route.ts`)
- AI insights → AI insights API: requests insights
- AI insights API → Authentication: checks session (evidence: `app/api/ai-insights/route.ts`)
- AI insights API → Security utilities: verifies and sanitizes (evidence: `app/api/ai-insights/route.ts`)
- AI insights API → Rate limiting: limits requests (evidence: `app/api/ai-insights/route.ts`)
- Watch progress API → Authentication: checks session (evidence: `app/api/watch-progress/route.ts`)
- Request API → Authentication: checks session (evidence: `app/api/request/route.ts`)
- Request API → Security utilities: validates input (evidence: `app/api/request/route.ts`)
- Request API → Rate limiting: limits requests (evidence: `app/api/request/route.ts`)
- Request API → Sanity CMS: submits request (evidence: `app/api/request/route.ts`)
- Scrape automation → Ingestion pipeline: starts pipeline
- Ingestion pipeline → Movie scraper: scrapes titles (evidence: `lib/automation/pipeline.ts`)
- Ingestion pipeline → Link validation: validates links (evidence: `lib/automation/pipeline.ts`)
- Ingestion pipeline → TMDB enrichment: enriches titles (evidence: `lib/automation/pipeline.ts`)
- Ingestion pipeline → Description generation: generates descriptions (evidence: `lib/automation/pipeline.ts`)
- Ingestion pipeline → Sanity publishing: publishes titles (evidence: `lib/automation/pipeline.ts`)
- Sanity publishing → Sanity CMS: writes content
- Authentication → User database: reads user data (evidence: `lib/auth.ts`)
- Authentication → Security utilities: logs auth events (evidence: `lib/auth.ts`)
- Rate limiting → Security utilities: gets client IP (evidence: `lib/rate-limiter.ts`)
- Rate limiting → Upstash Redis: uses when configured (evidence: `lib/rate-limiter.ts`)
