/Build-youtube-clone-with-nextjs

Next 15 and React 19 with tRPC, prefetching in server components, leveraging suspense in client components, video processing, background jobs, AI features, and much more.

Primary LanguageTypeScript

NewTube - YouTube Clone

A modern, feature-rich YouTube clone built with Next.js, TypeScript, and Tailwind CSS. This project demonstrates the implementation of a video-sharing platform with a focus on user experience and performance.

๐Ÿš€ Features

Implemented

  • โœ… Modern and responsive UI using Tailwind CSS with mobile-first approach
  • โœ… Server-side rendering with Next.js 15 and App Router
  • โœ… Authentication system using Clerk for secure user management
  • โœ… Navigation sidebar with responsive design for different screen sizes
  • โœ… Search functionality with optimized performance
  • โœ… Home page layout with category filtering
  • โœ… Radix UI components integration for accessible UI elements
  • โœ… Categories system with filtering capabilities
  • โœ… tRPC integration for type-safe API calls between client and server
  • โœ… Database integration with Drizzle ORM and NeonDB

Planned

  • ๐Ÿ“ Video upload and processing with cloud storage integration
  • ๐Ÿ“ User profiles and channels with customization options
  • ๐Ÿ“ Video recommendations based on user preferences
  • ๐Ÿ“ Comments and interactions with real-time updates
  • ๐Ÿ“ Playlists management for organizing content
  • ๐Ÿ“ Watch history tracking for personalized experience
  • ๐Ÿ“ Subscriptions system for following creators
  • ๐Ÿ“ Video analytics for content creators
  • ๐Ÿ“ Advanced search with filters and sorting options
  • ๐Ÿ“ Notifications system for user engagement

๐Ÿ› ๏ธ Tech Stack

Frontend

  • Framework: Next.js 15 with TypeScript and App Router
  • Styling: Tailwind CSS 4 with custom components
  • UI Components: Radix UI (comprehensive suite of accessible components)
  • Form Handling: React Hook Form with Zod validation
  • State Management: React Query with tRPC
  • Client Utilities:
    • date-fns for date formatting
    • clsx and tailwind-merge for conditional styling
    • Lucide React for icons
    • Embla Carousel for slider components

Backend

  • API Layer: tRPC for end-to-end typesafe APIs
  • Authentication: Clerk for user management
  • Database: Drizzle ORM with NeonDB (PostgreSQL)
  • Caching: Upstash Redis
  • Rate Limiting: Upstash Rate Limit

DevOps

  • Package Manager: Bun (with npm compatibility)
  • Deployment: Netlify with continuous integration
  • Development Tools: Turbopack for fast refresh

๐Ÿ“ฆ Project Structure

โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ app/                # Next.js app directory with App Router
โ”‚   โ”‚   โ”œโ”€โ”€ (auth)/         # Authentication routes
โ”‚   โ”‚   โ”œโ”€โ”€ (home)/         # Home page routes
โ”‚   โ”‚   โ”œโ”€โ”€ api/            # API routes
โ”‚   โ”‚   โ”œโ”€โ”€ globals.css     # Global styles
โ”‚   โ”‚   โ””โ”€โ”€ layout.tsx      # Root layout component
โ”‚   โ”œโ”€โ”€ components/         # Reusable UI components
โ”‚   โ”‚   โ”œโ”€โ”€ ui/             # Base UI components
โ”‚   โ”‚   โ””โ”€โ”€ filter-carousel.tsx # Category filter component
โ”‚   โ”œโ”€โ”€ db/                 # Database configuration
โ”‚   โ”‚   โ”œโ”€โ”€ index.ts        # Database connection
โ”‚   โ”‚   โ””โ”€โ”€ schema.ts       # Database schema
โ”‚   โ”œโ”€โ”€ hooks/              # Custom React hooks
โ”‚   โ”œโ”€โ”€ lib/                # Utility functions and configurations
โ”‚   โ”‚   โ”œโ”€โ”€ ratelimit.ts    # Rate limiting configuration
โ”‚   โ”‚   โ”œโ”€โ”€ redis.ts        # Redis configuration
โ”‚   โ”‚   โ””โ”€โ”€ utils.ts        # Utility functions
โ”‚   โ”œโ”€โ”€ middleware.ts       # Next.js middleware
โ”‚   โ”œโ”€โ”€ modules/            # Feature-based modules
โ”‚   โ”‚   โ”œโ”€โ”€ auth/           # Authentication module
โ”‚   โ”‚   โ”œโ”€โ”€ categories/     # Categories module
โ”‚   โ”‚   โ””โ”€โ”€ home/           # Home page module
โ”‚   โ”œโ”€โ”€ providers/          # React context providers
โ”‚   โ”œโ”€โ”€ scripts/            # Utility scripts
โ”‚   โ”‚   โ””โ”€โ”€ seed-categories.ts # Database seeding
โ”‚   โ””โ”€โ”€ trpc/               # tRPC configuration
โ”‚       โ”œโ”€โ”€ client.tsx      # Client-side tRPC setup
โ”‚       โ”œโ”€โ”€ init.ts         # tRPC initialization
โ”‚       โ”œโ”€โ”€ query-client.ts # React Query client
โ”‚       โ”œโ”€โ”€ routers/        # tRPC routers
โ”‚       โ””โ”€โ”€ server.tsx      # Server-side tRPC setup
โ”œโ”€โ”€ public/                 # Static assets
โ””โ”€โ”€ config files            # Various configuration files

๐Ÿš€ Getting Started

  1. Clone the repository

    git clone [repository-url]
    cd youtube-clone
  2. Install dependencies

    bun install
    # or
    npm install
  3. Set up environment variables Create a .env.local file in the root directory with the following variables:

    # Clerk Authentication
    NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
    CLERK_SECRET_KEY=your_clerk_secret_key
    
    # Database
    DATABASE_URL=your_neondb_connection_string
    
    # Redis
    UPSTASH_REDIS_REST_URL=your_upstash_redis_url
    UPSTASH_REDIS_REST_TOKEN=your_upstash_redis_token
    
  4. Seed the database

    bun seed
    # or
    npm run seed
  5. Run the development server

    bun dev
    # or
    npm run dev
  6. Open http://localhost:3000 in your browser

๐Ÿ”ง Development

Available Scripts

  • Development Mode: bun dev or npm run dev
  • Development with Webhook: bun run dev:all (runs both dev server and ngrok webhook)
  • Build: bun build or npm run build
  • Production: bun start or npm start
  • Linting: bun lint or npm run lint
  • Database Seeding: bun seed or npm run seed

Architecture

The project follows a modular architecture with feature-based organization:

  • App Router: Utilizes Next.js 15 App Router for page routing
  • tRPC: Provides type-safe API communication between client and server
  • Modules: Features are organized into self-contained modules
  • Components: Reusable UI components built with Radix UI and Tailwind

๐ŸŽฏ Project Goals

  1. Create a modern and performant video-sharing platform
  2. Implement industry best practices for scalability
  3. Provide a seamless user experience across devices
  4. Demonstrate advanced Next.js and React patterns
  5. Build a fully accessible application following WCAG guidelines
  6. Optimize for performance with efficient data fetching and rendering

๐Ÿงช Testing

  • Unit testing implementation planned with Vitest
  • E2E testing with Cypress planned
  • Component testing with React Testing Library planned
  • Performance testing with Lighthouse planned

๐Ÿ“ฑ Responsive Design

  • Mobile-first approach with adaptive layouts
  • Responsive navigation with collapsible sidebar
  • Adaptive video player for different screen sizes
  • Cross-browser compatibility testing
  • Touch-friendly interactions for mobile devices

๐Ÿ” Security

  • Authentication with Clerk for secure user management
  • Protected API routes with proper authorization
  • Input validation with Zod schema validation
  • CSRF protection for form submissions
  • Rate limiting with Upstash Rate Limit
  • Secure environment variable handling

๐ŸŒ Performance Optimization

  • Server-side rendering for improved initial load
  • Image optimization with Next.js Image component
  • Code splitting and lazy loading
  • Efficient data fetching with React Query
  • Caching strategies with Redis
  • Bundle size optimization

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with โค๏ธ using Next.js and TypeScript