Building MovieFlix: A Complete Movie Explorer App with React, Firebase, TMDB & TailwindCSS

Chirag TyagiChirag Tyagi
4 min read

🎬 Introduction

Welcome to my blog! I'm Chirag Tyagi, a B.Tech CSE student and aspiring full-stack developer. In this post, I’ll take you through the journey of creating MovieFlix β€” a full-featured movie explorer app built with React, powered by Firebase for authentication, and integrated with TMDB API to fetch real movie data.

πŸš€ Live Demo β†’

πŸ“‚ GitHub Repository β†’


πŸ› οΈ Tech Stack

  • React + Vite: Fast, modern front-end framework and tooling.

  • TailwindCSS: Utility-first CSS for rapid UI development.

  • Firebase: For Google & Email authentication.

  • TMDB API: For fetching trending, popular, and top-rated movies.

  • Axios: For HTTP requests.

  • React Router DOM: For page navigation.

  • React Context API: Global state for handling favorite movies.

  • LocalStorage: Persistent favorites.

  • React Fast Marquee: For smooth background poster animation.

πŸ”§ Example: Firebase Auth Implementation

import { createUserWithEmailAndPassword } from "firebase/auth";

const signup = (email, password) => {
  return createUserWithEmailAndPassword(auth, email, password);
};

πŸ”§ Example: Axios API Fetch

const fetchMovies = async () => {
  const res = await axios.get(`https://api.themoviedb.org/3/trending/movie/day`, {
    params: {
      api_key: import.meta.env.VITE_TMDB_API_KEY,
      language: "en-US"
    }
  });
  setMovies(res.data.results);
};

πŸ”§ Example: Context API for Favorites

const addToFavorites = (movie) => {
  setFavorites(prev => {
    if (!prev.some(f => f.id === movie.id)) return [...prev, movie];
    return prev;
  });
};

πŸ“ Folder Structure Overview

src/
β”œβ”€β”€ components/         # Reusable UI components
β”œβ”€β”€ contexts/           # Auth and Movie context providers
β”œβ”€β”€ hooks/              # Custom hooks like useAuth
β”œβ”€β”€ pages/              # Page-level components (Home, Login, Signup, Favorites)
β”œβ”€β”€ services/           # API logic (TMDB requests)
β”œβ”€β”€ utils/              # Helpers like genre mapping
β”œβ”€β”€ App.jsx             # Main app component
└── main.jsx            # Entry point

πŸ” Firebase Authentication

  • Email/password login

  • Google OAuth

  • Session persistence with onAuthStateChanged

πŸ“¦ Code Example

useEffect(() => {
  const unsubscribe = onAuthStateChanged(auth, (currentUser) => {
    setUser(currentUser);
    setLoading(false);
  });
  return unsubscribe;
}, []);

🌍 Movie API Integration with TMDB

  • Stored API Key in .env

  • Used Axios to fetch movie lists

  • Displayed posters, titles, genres, overview

πŸ”§ Sample Genre Mapping Code

export const getGenreNames = (ids) => ids.map(id => genreMap[id] || "Unknown").join(", ");

πŸ–ΌοΈ Movie Cards + Favorites

  • Poster, title, release year, TMDB rating

  • On hover: shows overview and genre

  • Heart icon toggles favorite state

πŸ“¦ Code Sample

<button
  onClick={onFavoriteClick}
  className={favorite ? "text-red-500" : "text-white"}
>
  β™₯
</button>

πŸ’¨ Animated Poster Background with react-fast-marquee

  • Smooth animation using react-fast-marquee

  • Different layers for trending, top-rated, and popular

πŸ“¦ Code Snippet

<Marquee speed={60} gradient={false}>
  {posters.map(url => (
    <img key={url} src={url} className="w-64 h-[24rem] object-cover mx-3 rounded-xl" />
  ))}
</Marquee>

πŸ” Search & Genre Mapping

  • Search field fetches data from /search/movie

  • Genre names displayed using mapped genre_ids

πŸ“¦ Code Snippet

<p className="text-sm text-gray-400">
  Genres: {getGenreNames(movie.genre_ids)}
</p>

🏁 Pages and Routing

  • / β†’ Home

  • /login β†’ Login

  • /signup β†’ Sign-up

  • /favorites β†’ Protected route

πŸ“¦ Protected Route Code

const PrivateRoute = ({ children }) => {
  const { user } = useAuth();
  return user ? children : <Navigate to="/login" />;
};

πŸ“± Responsive Design with Tailwind

  • Tailwind’s utility classes used across all components

  • Dark UI theme

  • Fully mobile responsive


πŸš€ Deploying to Vercel

Vercel makes it super easy to deploy Vite + React apps. Here’s how I did it:

πŸ§ͺ Step-by-Step Guide

  1. Push your project to GitHub

  2. Sign in to vercel.com

  3. Import your GitHub repo

  4. Configure build settings:

    • Framework: Vite

    • Build Command: npm run build

    • Output Directory: dist

  5. Add Environment Variables in Vercel Dashboard:

    • VITE_TMDB_API_KEY = your_tmdb_api_key

    • (Also add Firebase keys if needed)

  6. Click Deploy β€” and you're live πŸŽ‰

You can view the deployed project here:
πŸ‘‰ https://movie-flix-pi-three.vercel.app


πŸ’‘ What I Learned

  • Firebase Auth + React integration

  • API handling with Axios

  • Persistent state with localStorage

  • Context API best practices

  • TailwindCSS theming and layout

  • Real-world deployment with Vercel


🌐 Live Demo

πŸ‘‰ Try it here: https://movie-flix-pi-three.vercel.app/

πŸ“¬ Contact Me


Thanks for reading! I’d love to hear your feedback and suggestions. Feel free to fork the repo and build your own version!

0
Subscribe to my newsletter

Read articles from Chirag Tyagi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chirag Tyagi
Chirag Tyagi

Profile Bio I’m currently pursuing B.Tech in Computer Science and Engineering at Roorkee Institute of Technology, where I am deeply engaged in learning full-stack development with the MERN stack. My passion for technology drives me to explore and stay updated with the latest advancements in the field. Eager to apply and expand my skills, I am committed to continuous learning and growth in the ever-evolving tech landscape.