# vanthom04/watch-movies architecture

> Architecture diagram of the GitHub repository vanthom04/watch-movies, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vanthom04/watch-movies
- Repository: https://github.com/vanthom04/watch-movies

## Overview

##### Main Components
- Frontend (User Interface):
- Pages and Routes: Located under src/app/(site) with pages for movie lists, movie details, search results, watch screens, and favorites.
- UI Components: Organized under src/components (including both authentication-specific and generic UI elements such as buttons, inputs, and carousel).
- Layout and Global Styling: Files such as layout.tsx and globals.css in src/app.
- Hooks: Custom hooks (e.g., use-debounce, use-routes) which help manage client-side behavior.
- Backend / API Layer:
- API Endpoints: In src/app/api (i.e., for authentication via NextAuth in src/app/api/auth) and any other Next.js APIs defined.
- Actions: Files under src/actions that contain business logic for operations (e.g., signing up, toggling favorites, retrieving movie information).
- Data Layer:
- Database Integration: Prisma is used as the ORM, with its schema defined under prisma/schema.prisma.
- Utility and Library Code: Files in src/lib (including constants, Prisma setup, and utility functions) which enable backend operations.
- Authentication and Session Management:
- Components and API for authentication: NextAuth configuration and endpoints, along with related UI components under src/components/auth.

##### Relationships and Interactions
- The UI components interact with the business logic layer by invoking actions (located in src/actions) to fetch or trigger changes (e.g., checking favorites, retrieving movies).
- The API endpoints serve as the bridge between the frontend and the backend service (including database operations) and handle authentication, using NextAuth.
- The Prisma client (configured in src/lib/prisma.ts and the prisma directory) is in charge of database interactions, abstracting data access for movies, user favorites, and authentication data.
- Hooks provide extra integration by managing state and side effects in the frontend, like debouncing user input during search or managing routing.

##### Architectural Patterns and Principles
- Separation of Concerns: Distinct directories split responsibilities (UI components, server actions, API endpoints, and data access logic).
- MVC-like or Layered Approach: Even if Next.js usually leaves you decide your structure, the “actions” and “api” folders function like Controllers/Services, while “components” and “app” pages serve as Views.
- Client-Server Interaction: Clearly defined boundary via API endpoints where requests are issued and responses (with movie data, auth details, etc.) are returned.
- Use of External Libraries: NextAuth for authentication, Prisma for database management, and Next.js core optimizations such as next/font.

##### Overall Approach
- Keep the details high – capture every component that plays a role in data flow: from user interaction (clicks, searches) all the way to the backend query execution.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        FR("Pages/Routes"):::frontend
        UC["UI Components"]:::frontend
        LS["Layout & Global Styling"]:::frontend
        CH["Client-side Hooks"]:::frontend
    end

    subgraph "API Layer"
        AE["API Endpoints"]:::api
        AA["Auth Endpoints"]:::api
    end

    subgraph "Business Logic"
        ACT["Business Logic / Actions"]:::actions
    end

    subgraph "Data & Utilities"
        DB(("Prisma (Database)")):::database
        UL["Utility & Library Code"]:::database
    end

    subgraph "Authentication"
        AUI["Auth UI Components"]:::auth
        SP["Session Provider"]:::auth
    end

    %% Connections
    FR -->|"triggers"| ACT
    UC -->|"invokes"| ACT
    CH -->|"enhances"| FR
    ACT -->|"calls"| AE
    AE -->|"contains"| AA
    ACT -->|"utilizes"| UL
    AE -->|"queries"| DB
    AUI -->|"authenticates"| AA
    FR -->|"displays"| AUI
    AA -->|"sets"| SP
    SP -->|"provides"| UC

    %% Click Events
    click FR "https://github.com/vanthom04/watch-movies/tree/master/src/app/(site)"
    click UC "https://github.com/vanthom04/watch-movies/tree/master/src/components"
    click LS "https://github.com/vanthom04/watch-movies/blob/master/src/app/layout.tsx"
    click CH "https://github.com/vanthom04/watch-movies/tree/master/src/hooks"
    click AE "https://github.com/vanthom04/watch-movies/tree/master/src/app/api"
    click AA "https://github.com/vanthom04/watch-movies/blob/master/src/app/api/auth/[...nextauth]"
    click ACT "https://github.com/vanthom04/watch-movies/tree/master/src/actions"
    click DB "https://github.com/vanthom04/watch-movies/blob/master/prisma/schema.prisma"
    click UL "https://github.com/vanthom04/watch-movies/tree/master/src/lib"
    click AUI "https://github.com/vanthom04/watch-movies/tree/master/src/components/auth"
    click SP "https://github.com/vanthom04/watch-movies/blob/master/src/components/providers/session-provider.tsx"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef api fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef actions fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef database fill:#FAD7A0,stroke:#AF601A,stroke-width:2px;
    classDef auth fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
```
