Skip to main content

Overview

Connect World leverages The Movie Database (TMDB) API to provide a rich catalog of movies and TV series. The platform fetches trending content, now playing movies, and top-rated series with localized Spanish content.

Trending Content

Discover what’s popular daily and weekly

Now Playing

Current movies in theaters

Top Rated

Highest rated TV series

TMDB Service

The TMDB integration is centralized in the tmdbService.ts file, providing a clean API for content fetching.

Configuration

import axios from "axios";

const TMDB_API_KEY = process.env.NEXT_PUBLIC_TMDB_API_KEY;
const BASE_URL = "https://api.themoviedb.org/3";

const tmdbClient = axios.create({
  baseURL: BASE_URL,
  params: { api_key: TMDB_API_KEY, language: "es-ES" },
});
Source: src/infrastructure/external/tmdbService.ts:3-27
The service is configured with language: "es-ES" to provide Spanish-localized content including titles, descriptions, and metadata.

Data Models

TMDB Movie Interface

export interface TmdbMovie {
  id: number;
  title?: string;
  name?: string;
  poster_path: string | null;
  backdrop_path: string | null;
  overview: string;
  vote_average: number;
  release_date?: string;
  first_air_date?: string;
  genre_ids: number[];
  media_type?: string;
}
Source: src/infrastructure/external/tmdbService.ts:6-18
  • id: Unique TMDB identifier
  • title: Movie title (for movies)
  • name: Series name (for TV shows)
  • poster_path: Poster image path (can be null)
  • backdrop_path: Backdrop/banner image path (can be null)
  • overview: Content description/synopsis
  • vote_average: Rating score (0-10)
  • release_date: Movie release date
  • first_air_date: TV series first air date
  • genre_ids: Array of genre identifiers
  • media_type: Content type (movie/tv)

TMDB Response Interface

export interface TmdbResponse {
  results: TmdbMovie[];
}
Source: src/infrastructure/external/tmdbService.ts:20-22

Content Fetching Functions

Image Handling

Poster URL Generation

Convert TMDB image paths to full URLs:
export function getPosterUrl(path: string | null, size = "w500"): string {
  if (!path) return "/images/placeholder.jpg";
  return `https://image.tmdb.org/t/p/${size}${path}`;
}
Source: src/infrastructure/external/tmdbService.ts:44-47 Parameters:
  • path: The poster_path or backdrop_path from TMDB
  • size: Image size (default: “w500”)
Available Sizes:
  • Poster sizes: w92, w154, w185, w342, w500, w780, original
  • Backdrop sizes: w300, w780, w1280, original
Always check if path is null before generating URLs. The function returns a placeholder image for null paths.

Usage Example

import { getTrendingAll } from '@/infrastructure/external/tmdbService';

// Fetch weekly trending content
const weeklyTrending = await getTrendingAll('week');

// Fetch daily trending content
const dailyTrending = await getTrendingAll('day');

Content Display Patterns

const displayTitle = movie.title || movie.name || 'Untitled';
Since movies use title and TV shows use name, always check both fields.

Environment Configuration

NEXT_PUBLIC_TMDB_API_KEY=your_tmdb_api_key_here
Get your TMDB API key by creating a free account at https://www.themoviedb.org/ and requesting an API key from your account settings.

API Endpoints Used

Trending

GET /trending/all/{time_window}Returns trending movies and TV shows

Now Playing

GET /movie/now_playingReturns current theatrical releases

Top Rated TV

GET /tv/top_ratedReturns highest-rated TV series

Images

GET https://image.tmdb.org/t/p/{size}{path}Returns poster and backdrop images

Best Practices

  1. Always check for null images - Use the getPosterUrl helper to handle null paths
  2. Handle both movies and TV shows - Check both title/name and release_date/first_air_date
  3. Limit results - The service already limits to 5-10 items per request
  4. Use appropriate image sizes - Choose based on display context to optimize bandwidth
  5. Cache responses - Consider caching TMDB responses to reduce API calls
  6. Localization - The service is configured for Spanish (es-ES) content
  7. Error handling - Implement try-catch blocks when calling these functions
TMDB API has rate limits. Implement caching and avoid excessive requests to prevent rate limiting.

Content Categories

The TMDB service provides three main content categories:
Trending (Weekly/Daily)
  • Most popular content across movies and TV
  • Updated regularly by TMDB’s algorithm
  • Mix of new releases and popular classics
  • Limited to 10 items for homepage display
Now Playing Movies
  • Current theatrical releases
  • Updated as movies enter/leave theaters
  • Relevant for time-sensitive promotions
  • Limited to 10 items
Top Rated TV Series
  • Highest user-rated series
  • More stable than trending content
  • Great for showcasing quality content
  • Limited to 5 items for curated selection

Build docs developers (and LLMs) love