# sarthaksharmassss14/moviefy architecture

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

- Interactive diagram: https://gitdiagram.com/sarthaksharmassss14/moviefy
- Repository: https://github.com/sarthaksharmassss14/moviefy

## Overview

#### Purpose and Runtime
Moviefy is a Next.js 15 App Router application for movie discovery, personalized AI recommendations, and private social watch parties. It runs as a Node.js web application, with server-rendered routes, API route handlers, and server actions. Primary application shell and landing entry points are `src/app/layout.tsx` and `src/app/page.tsx`.

#### Route and UI Composition
User-facing routes cover discovery, movie/person/director detail, lists, profiles, watchlists, and party rooms. Dynamic resources are addressed by route IDs, notably `src/app/movies/[id]/page.tsx`, `src/app/lists/[id]/page.tsx`, and `src/app/party/[id]/page.tsx`. Shared interactive UI—including movie cards, personalized shelves, mood input, and the watch-room experience—lives in `src/components/MovieCard.tsx`, `src/components/PickedForYouSection.tsx`, and `src/components/WatchPartyRoom.tsx`.

#### Identity and Access Boundary
Clerk supplies authentication and session identity. Middleware at `src/middleware.ts` is the cross-cutting request boundary for protected routes, while dedicated sign-in/sign-up route pages provide Clerk entry points under `src/app/sign-in/[[...sign-in]]/page.tsx` and `src/app/sign-up/[[...sign-up]]/page.tsx`. Authenticated identity is expected to govern database access and private party participation.

#### Persistence, Realtime, and Social Parties
Supabase is the persistence and realtime backend, accessed through `src/lib/supabase.ts`. Watch-party lifecycle and room interaction are centered on `src/app/party/[id]/page.tsx`, `src/components/WatchPartyButton.tsx`, and `src/components/WatchPartyRoom.tsx`. The intended boundary is Clerk JWT-backed Supabase authorization plus Postgres RLS, protecting party sessions and realtime chat from unauthorized users.

#### Movie Catalog and Discovery Flow
TMDB/OMDb-backed catalog access is encapsulated by `src/lib/tmdb.ts`; route pages consume movie metadata rather than owning third-party API concerns. Search and browse flows enter through `src/app/search/page.tsx`, `src/app/movies/[id]/page.tsx`, and home carousel/card components such as `src/components/HeroCarousel.tsx`. This separates external catalog retrieval from presentation and user-owned data such as ratings, reviews, lists, and watchlists.

#### AI Mood Search and Recommendation Pipeline
Mood discovery is exposed as an API boundary at `src/app/api/ai/mood/route.ts`, with client interaction in `src/components/MoodSearch.tsx`. The AI layer is divided among Groq LLM orchestration (`src/lib/groq.ts`), broader AI logic (`src/lib/ai.ts`), and embedding generation (`src/lib/embedding.ts`). Groq Llama 3.3 interprets natural-language intent; Hugging Face embeddings and Supabase vector storage support semantic retrieval.

#### Personalized RAG and Mutations
The “Picked For You” shelf derives recommendations from user ratings/reviews and vector similarity through `src/lib/recommendations.ts`, surfaced by `src/components/PickedForYouSection.tsx` and likely served through `src/app/api/suggestions/route.ts`. Server-side mutations for user content and list state are concentrated in `src/app/actions.ts` and `src/app/list-actions.ts`, forming the application-to-Supabase write boundary.

#### Operational Dependencies
Required external services are Clerk, Supabase Postgres/Realtime/vector capabilities, TMDB, OMDb, Groq, and Hugging Face Inference. Database initialization and knowledge/vector ingestion are operationally separate from the web runtime, represented by `setup_db.sql`, `seed-knowledge.js`, and `scripts/seed-bulk.ts`. Deployment is intended for Vercel.

Main entry points: [`src/lib/supabase.ts`](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/supabase.ts) (Supabase access layer), [`src/lib/tmdb.ts`](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/tmdb.ts) (Catalog service), [`src/app/layout.tsx`](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/layout.tsx) (App shell & home), [`src/app/search/page.tsx`](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/search/page.tsx) (Discovery & detail routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Next.js web app"]
  node_app_shell["App shell &amp; home<br/>Next.js App Router<br/>[layout.tsx]"]
  node_route_pages["Discovery &amp; detail routes<br/>route pages<br/>[page.tsx]"]
  node_party_page["Party room route<br/>dynamic route<br/>[page.tsx]"]
  node_catalog_ui["Catalog UI<br/>React components<br/>[HeroCarousel.tsx]"]
  node_mood_ui["Mood search UI<br/>React component<br/>[MoodSearch.tsx]"]
  node_personalized_ui["Picked For You shelf<br/>React component"]
  node_watch_room_ui["Watch room UI<br/>React component<br/>[WatchPartyRoom.tsx]"]
end

subgraph group_identity["Identity &amp; access"]
  node_middleware{{"Protected-route middleware<br/>Next.js middleware<br/>[middleware.ts]"}}
  node_clerk{{"Clerk<br/>auth provider"}}
end

subgraph group_data["Data &amp; social"]
  node_supabase[("Supabase Postgres &amp; Realtime<br/>persistence backend")]
  node_supabase_client["Supabase access layer<br/>data client<br/>[supabase.ts]"]
  node_mutations["User-content mutations<br/>server actions<br/>[actions.ts]"]
  node_catalog_service["Catalog service<br/>third-party API adapter<br/>[tmdb.ts]"]
  node_tmdb_omdb(("TMDB &amp; OMDb<br/>movie catalog APIs"))
end

subgraph group_ai["AI &amp; recommendations"]
  node_mood_api["Mood API<br/>API route<br/>[route.ts]"]
  node_ai_orchestration["LLM orchestration<br/>AI service<br/>[groq.ts]"]
  node_embeddings["Embedding generation<br/>AI service<br/>[embedding.ts]"]
  node_recommendations["Recommendation engine<br/>RAG service<br/>[recommendations.ts]"]
  node_suggestions_api["Suggestions API<br/>API route<br/>[route.ts]"]
  node_ai_providers(("Groq &amp; Hugging Face<br/>AI providers"))
end

subgraph group_operations["Operations"]
  node_db_setup["Database initialization<br/>SQL setup<br/>[setup_db.sql]"]
  node_knowledge_ingestion["Knowledge/vector ingestion<br/>seed pipeline<br/>[seed-bulk.ts]"]
end

node_app_shell -->|"renders navigation to"| node_route_pages
node_route_pages -->|"composes"| node_catalog_ui
node_route_pages -->|"reads metadata from"| node_catalog_service
node_catalog_ui -->|"displays results from"| node_catalog_service
node_catalog_service -->|"queries"| node_tmdb_omdb
node_app_shell -->|"hosts"| node_mood_ui
node_mood_ui -->|"submits intent to"| node_mood_api
node_mood_api -->|"interprets via"| node_ai_orchestration
node_ai_orchestration -->|"uses Llama inference"| node_ai_providers
node_mood_api -->|"returns catalog matches via"| node_catalog_service
node_app_shell -->|"hosts"| node_personalized_ui
node_personalized_ui -->|"loads from"| node_suggestions_api
node_suggestions_api -->|"requests"| node_recommendations
node_recommendations -->|"retrieves profile vectors through"| node_supabase_client
node_recommendations -->|"uses semantic vectors from"| node_embeddings
node_embeddings -->|"uses embedding inference"| node_ai_providers
node_supabase_client -->|"accesses"| node_supabase
node_mutations -->|"writes through"| node_supabase_client
node_party_page -->|"renders"| node_watch_room_ui
node_watch_room_ui -->|"syncs room and chat through"| node_supabase_client
node_middleware -->|"validates sessions with"| node_clerk
node_middleware -->|"guards"| node_party_page
node_clerk -->|"JWT authorizes RLS access"| node_supabase
node_db_setup -->|"initializes schema and RLS"| node_supabase
node_knowledge_ingestion -->|"loads knowledge vectors"| node_supabase

click node_app_shell "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/layout.tsx"
click node_route_pages "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/search/page.tsx"
click node_party_page "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/party/%5Bid%5D/page.tsx"
click node_catalog_ui "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/components/HeroCarousel.tsx"
click node_mood_ui "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/components/MoodSearch.tsx"
click node_personalized_ui "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/components/PickedForYouSection.tsx"
click node_watch_room_ui "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/components/WatchPartyRoom.tsx"
click node_middleware "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/middleware.ts"
click node_supabase_client "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/supabase.ts"
click node_mutations "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/actions.ts"
click node_catalog_service "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/tmdb.ts"
click node_mood_api "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/api/ai/mood/route.ts"
click node_ai_orchestration "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/groq.ts"
click node_embeddings "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/embedding.ts"
click node_recommendations "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/recommendations.ts"
click node_suggestions_api "https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/api/suggestions/route.ts"
click node_db_setup "https://github.com/sarthaksharmassss14/moviefy/blob/main/setup_db.sql"
click node_knowledge_ingestion "https://github.com/sarthaksharmassss14/moviefy/blob/main/scripts/seed-bulk.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_route_pages,node_party_page,node_catalog_ui,node_mood_ui,node_personalized_ui,node_watch_room_ui toneBlue
class node_middleware,node_clerk toneAmber
class node_supabase,node_supabase_client,node_mutations,node_catalog_service,node_tmdb_omdb toneMint
class node_mood_api,node_ai_orchestration,node_embeddings,node_recommendations,node_suggestions_api,node_ai_providers toneRose
class node_db_setup,node_knowledge_ingestion toneIndigo
```

## Components

### Next.js web app

- [App shell & home](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/layout.tsx): Next.js App Router · Server-rendered application entry and landing experience. · `src/app/layout.tsx`
- [Discovery & detail routes](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/search/page.tsx): route pages · Search, movie, list, and other catalog-facing screens. · `src/app/search/page.tsx`
- [Party room route](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/party/%5Bid%5D/page.tsx): dynamic route · Private watch-party page addressed by room ID. · `src/app/party/[id]/page.tsx`
- [Catalog UI](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/components/HeroCarousel.tsx): React components · Hero carousel and movie cards present discovery results. · `src/components/HeroCarousel.tsx`
- [Mood search UI](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/components/MoodSearch.tsx): React component · `src/components/MoodSearch.tsx`
- [Picked For You shelf](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/components/PickedForYouSection.tsx): React component · `src/components/PickedForYouSection.tsx`
- [Watch room UI](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/components/WatchPartyRoom.tsx): React component · Interactive party lifecycle and room experience. · `src/components/WatchPartyRoom.tsx`

### Identity & access

- [Protected-route middleware](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/middleware.ts): Next.js middleware · Cross-cutting authenticated request boundary. · `src/middleware.ts`
- **Clerk**: auth provider · Supplies authentication, sessions, and JWT identity.

### Data & social

- **Supabase Postgres & Realtime**: persistence backend · Stores user data, party state, chat, and vectors under RLS.
- [Supabase access layer](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/supabase.ts): data client · `src/lib/supabase.ts`
- [User-content mutations](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/actions.ts): server actions · Write boundary for lists and user-owned content. · `src/app/actions.ts`
- [Catalog service](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/tmdb.ts): third-party API adapter · Encapsulates movie metadata retrieval. · `src/lib/tmdb.ts`
- **TMDB & OMDb**: movie catalog APIs

### AI & recommendations

- [Mood API](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/api/ai/mood/route.ts): API route · Client-facing natural-language discovery boundary. · `src/app/api/ai/mood/route.ts`
- [LLM orchestration](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/groq.ts): AI service · Interprets mood intent and coordinates AI logic. · `src/lib/groq.ts`
- [Embedding generation](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/embedding.ts): AI service · Creates vectors for semantic retrieval. · `src/lib/embedding.ts`
- [Recommendation engine](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/lib/recommendations.ts): RAG service · Combines ratings/reviews with vector similarity. · `src/lib/recommendations.ts`
- [Suggestions API](https://github.com/sarthaksharmassss14/moviefy/blob/main/src/app/api/suggestions/route.ts): API route · `src/app/api/suggestions/route.ts`
- **Groq & Hugging Face**: AI providers · Llama intent inference and embedding inference.

### Operations

- [Database initialization](https://github.com/sarthaksharmassss14/moviefy/blob/main/setup_db.sql): SQL setup · Operational schema and policy initialization. · `setup_db.sql`
- [Knowledge/vector ingestion](https://github.com/sarthaksharmassss14/moviefy/blob/main/scripts/seed-bulk.ts): seed pipeline · Seeds knowledge and bulk vector data outside web runtime. · `scripts/seed-bulk.ts`

## Connections

- App shell & home → Discovery & detail routes: renders navigation to
- Discovery & detail routes → Catalog UI: composes
- Discovery & detail routes → Catalog service: reads metadata from
- Catalog UI → Catalog service: displays results from
- Catalog service → TMDB & OMDb: queries
- App shell & home → Mood search UI: hosts
- Mood search UI → Mood API: submits intent to
- Mood API → LLM orchestration: interprets via
- LLM orchestration → Groq & Hugging Face: uses Llama inference
- Mood API → Catalog service: returns catalog matches via
- App shell & home → Picked For You shelf: hosts
- Picked For You shelf → Suggestions API: loads from
- Suggestions API → Recommendation engine: requests
- Recommendation engine → Supabase access layer: retrieves profile vectors through
- Recommendation engine → Embedding generation: uses semantic vectors from
- Embedding generation → Groq & Hugging Face: uses embedding inference
- Supabase access layer → Supabase Postgres & Realtime: accesses
- User-content mutations → Supabase access layer: writes through
- Party room route → Watch room UI: renders
- Watch room UI → Supabase access layer: syncs room and chat through
- Protected-route middleware → Clerk: validates sessions with
- Protected-route middleware → Party room route: guards
- Clerk → Supabase Postgres & Realtime: JWT authorizes RLS access
- Database initialization → Supabase Postgres & Realtime: initializes schema and RLS
- Knowledge/vector ingestion → Supabase Postgres & Realtime: loads knowledge vectors
