# markomilos/netflix-clone architecture

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

- Interactive diagram: https://gitdiagram.com/markomilos/netflix-clone
- Repository: https://github.com/markomilos/netflix-clone

## Overview

##### Main components
- Frontend Application: Represented by the Next.js “app” directory that contains pages for browsing, movies, my list, profiles, authentication, etc. Also note the component library (components directory), and Storybook for isolated UI components.
- API Endpoints: Under the “app/api” directory you have endpoints for authentication (including social login via NextAuth), movie details, managing “my list”, and user data.
- Business Logic/Services: The “service” directory encapsulates services like AuthService, ContentService, MyListService, ProfileService, TMDBService, and UserService. These form the backend logic connecting frontend actions to data operations.
- Database: The PostgreSQL database is interfaced via Prisma (see prisma/schema.prisma) and its connection is managed with Prisma’s client in “lib/prismadb.ts”.
- External Integrations: The TMDB API is used to retrieve content data (see TMDBService.ts and lib/tmdb-image.ts).
- Infrastructure: Docker Compose is used to simplify the deployment, indicating separate containers for the Next.js application, the PostgreSQL database, and pgAdmin for database administration.

##### Relationships and interactions
- The Frontend (Next.js) communicates with the internal API endpoints for authentication, content fetching, and user data management.
- The API endpoints, in turn, call the respective services (service/AuthService, service/ContentService, etc.) which encapsulate business logic.
- Data persistence is handled via Prisma which interfaces with the PostgreSQL database.
- The TMDBService integrates with the external TMDB API to fetch movie/TV content and images.
- Internal libraries (in the “lib” folder) provide shared functionality (e.g., logging, fetching utilities, authentication management).

##### Architectural patterns & technologies
- MVC/MV* like separation is evident wherein Next.js pages render the frontend while API routes and services handle backend logic.
- API layering: The separation of concerns is visible with dedicated API routes invoking service logic.
- External API integration: TMDB is used to source content data.
- Component-based UI design: React components are modularized with component directories and are developed/tested using Storybook.
- Dockerized Infrastructure: Using Docker Compose to manage and run multi-container applications.
- Integration with modern state management (Zustand) and data fetching (SWR) is used on the client side.

- Chart out the flow from API calls to the Service layer and then to the PostgreSQL database, including communication with the TMDB external API.
- A separate node for the Docker Compose setup, which houses multiple containers (Next.js, PostgreSQL, pgAdmin).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client / Frontend
    subgraph "Client / Frontend"
        Browser("User/Browser"):::client
        NextApp("Next.js Frontend"):::frontend
        UIComponents("UI Components"):::frontend
        Storybook("Storybook"):::frontend
    end

    %% Backend API Layer
    subgraph "Backend API Layer"
        API("API Endpoints"):::api
    end

    %% Business Logic / Services
    subgraph "Business Logic / Services"
        Auth("AuthService"):::service
        Content("ContentService"):::service
        MyList("MyListService"):::service
        Profile("ProfileService"):::service
        TMDBService("TMDB Service"):::service
        UserS("UserService"):::service
    end

    %% Database Layer
    subgraph "Database Layer"
        Prisma("Prisma Client"):::db
        Postgre("PostgreSQL DB"):::db
    end

    %% External Integrations
    subgraph "External Integrations"
        TMDB("TMDB External API"):::external
    end

    %% Infrastructure
    subgraph "Infrastructure"
        Docker("Docker Compose"):::infra
        PgAdmin("pgAdmin"):::infra
    end

    %% Connections
    Browser -->|"loads"| NextApp
    NextApp -->|"makesAPICall"| API
    API -->|"invokesAuth"| Auth
    API -->|"invokesContent"| Content
    API -->|"invokesMyList"| MyList
    API -->|"invokesProfile"| Profile
    API -->|"invokesTMDB"| TMDBService
    API -->|"invokesUser"| UserS

    Auth -->|"queriesDB"| Prisma
    Content -->|"queriesDB"| Prisma
    MyList -->|"queriesDB"| Prisma
    Profile -->|"queriesDB"| Prisma
    UserS -->|"queriesDB"| Prisma
    Prisma -->|"persistsTo"| Postgre

    TMDBService -->|"fetchesData"| TMDB

    Docker --- NextApp
    Docker --- Postgre
    Docker --- PgAdmin

    %% Click Events
    click NextApp "https://github.com/markomilos/netflix-clone/tree/main/app/(main)"
    click UIComponents "https://github.com/markomilos/netflix-clone/tree/main/components"
    click Storybook "https://github.com/markomilos/netflix-clone/tree/main/.storybook/stories"
    click API "https://github.com/markomilos/netflix-clone/tree/main/app/api"
    click Auth "https://github.com/markomilos/netflix-clone/tree/main/service"
    click Content "https://github.com/markomilos/netflix-clone/tree/main/service"
    click MyList "https://github.com/markomilos/netflix-clone/tree/main/service"
    click Profile "https://github.com/markomilos/netflix-clone/tree/main/service"
    click TMDBService "https://github.com/markomilos/netflix-clone/blob/main/service/TMDBService.ts"
    click UserS "https://github.com/markomilos/netflix-clone/tree/main/service"
    click Prisma "https://github.com/markomilos/netflix-clone/blob/main/lib/prismadb.ts"
    click Postgre "https://github.com/markomilos/netflix-clone/blob/main/prisma/schema.prisma"
    click TMDB "https://github.com/markomilos/netflix-clone/blob/main/lib/tmdb-image.ts"
    click Docker "https://github.com/markomilos/netflix-clone/blob/main/docker-compose.yaml"

    %% Styles
    classDef client fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef frontend fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef api fill:#a9dfbf,stroke:#333,stroke-width:2px;
    classDef service fill:#f5cba7,stroke:#333,stroke-width:2px;
    classDef db fill:#d6eaf8,stroke:#333,stroke-width:2px;
    classDef external fill:#f7c6c7,stroke:#333,stroke-width:2px;
    classDef infra fill:#abebc6,stroke:#333,stroke-width:2px;
```
