Skip to content

huynguyen03dev/discord-clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Discord Clone

A modern, full-featured Discord clone built with Next.js 15, featuring real-time messaging, voice channels, server management, and more. This application replicates the core functionality of Discord with a clean, responsive interface.

Discord Clone TypeScript Tailwind CSS PostgreSQL

✨ Features

πŸ” Authentication & User Management

  • Secure Authentication with Clerk integration
  • User Profiles with customizable avatars and display names
  • Protected Routes with middleware-based authentication

🏠 Server Management

  • Create & Join Servers with unique invite codes
  • Server Customization with custom names and images
  • Member Management with role-based permissions (Admin, Moderator, Guest)
  • Server Settings and moderation tools

πŸ’¬ Real-time Communication

  • Text Channels with live messaging via Socket.IO
  • Direct Messages between server members
  • File Sharing with support for images, PDFs, videos, and audio
  • Emoji Support with emoji picker integration
  • Message History with persistent storage

🎡 Channel Types

  • Text Channels for messaging and file sharing
  • Audio Channels for voice communication (planned)
  • Video Channels for video calls (planned)

🎨 User Experience

  • Dark/Light Theme toggle with system preference detection
  • Responsive Design optimized for desktop and mobile
  • Real-time Status Indicators showing connection status
  • Intuitive Navigation with collapsible sidebars
  • Modal-based Interactions for seamless user experience

πŸ› οΈ Technology Stack

Frontend

Backend & Database

Authentication & File Handling

  • Clerk - Authentication and user management
  • UploadThing - File upload and storage service

State Management & Forms

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (version 18.0 or higher)
  • npm (version 8.0 or higher) or yarn (version 1.22 or higher)
  • PostgreSQL (version 15 or higher)
  • Git for version control

Required Accounts

  • Clerk account for authentication
  • UploadThing account for file uploads
  • PostgreSQL database (local or hosted, e.g., Supabase, Railway, PlanetScale)

πŸš€ Installation

1. Clone the Repository

git clone https://github.com/yourusername/discord-clone.git
cd discord-clone

2. Install Dependencies

npm install
# or
yarn install

3. Database Setup

Option A: Using Docker (Recommended)

# Start PostgreSQL container
docker-compose up -d

# The database will be available at:
# Host: localhost
# Port: 5432
# Database: discord_clone
# Username: discord_user
# Password: your_secure_password

Option B: Local PostgreSQL Installation

Ensure PostgreSQL is running and create a database:

CREATE DATABASE discord_clone;

4. Environment Variables

Create a .env.local file in the root directory:

# Database
DATABASE_URL="postgresql://discord_user:your_secure_password@localhost:5432/discord_clone"
DIRECT_URL="postgresql://discord_user:your_secure_password@localhost:5432/discord_clone"

# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/

# UploadThing
UPLOADTHING_SECRET=your_uploadthing_secret
UPLOADTHING_APP_ID=your_uploadthing_app_id

# Application
NEXT_PUBLIC_SITE_URL=http://localhost:3000

5. Database Migration

# Generate Prisma client
npx prisma generate

# Run database migrations
npx prisma db push

# (Optional) Seed the database
npx prisma db seed

6. Start the Development Server

npm run dev
# or
yarn dev

Open http://localhost:3000 in your browser to see the application.

πŸ—οΈ Development Workflow

Available Scripts

# Development server with Turbopack
npm run dev

# Production build
npm run build

# Start production server
npm run start

# Lint code
npm run lint

# Database operations
npx prisma studio          # Open Prisma Studio
npx prisma db push         # Push schema changes
npx prisma generate        # Generate Prisma client
npx prisma migrate dev     # Create and apply migrations

Development Server Features

  • Hot Reload - Changes are reflected instantly
  • Turbopack - Fast bundler for development
  • TypeScript - Real-time type checking
  • ESLint - Code quality and consistency

πŸ“ Project Structure

discord-clone/
β”œβ”€β”€ app/                          # Next.js App Router
β”‚   β”œβ”€β”€ (auth)/                  # Authentication routes (grouped)
β”‚   β”‚   β”œβ”€β”€ (routes)/           # Sign-in/Sign-up pages
β”‚   β”‚   └── layout.tsx          # Auth layout
β”‚   β”œβ”€β”€ (invite)/               # Server invite handling
β”‚   β”œβ”€β”€ (main)/                 # Main application routes
β”‚   β”‚   β”œβ”€β”€ (routes)/          # Server and channel pages
β”‚   β”‚   └── layout.tsx         # Main app layout
β”‚   β”œβ”€β”€ (setup)/               # Initial user setup
β”‚   β”œβ”€β”€ api/                   # API routes
β”‚   β”‚   β”œβ”€β”€ channels/          # Channel management
β”‚   β”‚   β”œβ”€β”€ members/           # Member management
β”‚   β”‚   β”œβ”€β”€ servers/           # Server operations
β”‚   β”‚   └── uploadthing/       # File upload handling
β”‚   β”œβ”€β”€ globals.css            # Global styles
β”‚   └── layout.tsx             # Root layout
β”œβ”€β”€ components/                   # React components
β”‚   β”œβ”€β”€ chat/                  # Chat-related components
β”‚   β”œβ”€β”€ modals/                # Modal dialogs
β”‚   β”œβ”€β”€ navigations/           # Navigation components
β”‚   β”œβ”€β”€ providers/             # Context providers
β”‚   β”œβ”€β”€ server/                # Server-specific UI
β”‚   └── ui/                    # Reusable UI components
β”œβ”€β”€ hooks/                       # Custom React hooks
β”œβ”€β”€ lib/                         # Utility libraries
β”‚   β”œβ”€β”€ db.ts                  # Database connection
β”‚   β”œβ”€β”€ utils.ts               # Helper functions
β”‚   └── uploadthing.ts         # File upload utilities
β”œβ”€β”€ pages/api/socket/            # Socket.IO API routes
β”œβ”€β”€ prisma/                      # Database schema and migrations
β”‚   β”œβ”€β”€ migrations/            # Database migrations
β”‚   └── schema.prisma          # Database schema
β”œβ”€β”€ public/                      # Static assets
└── types.ts                     # TypeScript type definitions

πŸ”§ Environment Variables

Required Environment Variables

Variable Description Example
DATABASE_URL PostgreSQL connection string postgresql://user:pass@localhost:5432/db
DIRECT_URL Direct database connection (for migrations) Same as DATABASE_URL
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY Clerk public key pk_test_...
CLERK_SECRET_KEY Clerk secret key sk_test_...
UPLOADTHING_SECRET UploadThing secret key sk_live_...
UPLOADTHING_APP_ID UploadThing application ID your-app-id
NEXT_PUBLIC_SITE_URL Application URL http://localhost:3000

Optional Environment Variables

Variable Description Default
NEXT_PUBLIC_CLERK_SIGN_IN_URL Sign-in page URL /sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL Sign-up page URL /sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL Redirect after sign-in /
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL Redirect after sign-up /

Setting Up External Services

Clerk Authentication

  1. Create account at clerk.com
  2. Create new application
  3. Copy API keys to your .env.local
  4. Configure redirect URLs in Clerk dashboard

UploadThing File Storage

  1. Create account at uploadthing.com
  2. Create new application
  3. Copy API keys to your .env.local
  4. Configure file size limits and allowed types

πŸš€ Deployment

Quick Deploy Options

Platform Database Setup
Vercel ⭐ Supabase Connect GitHub β†’ Add env vars β†’ Deploy
Railway Built-in PostgreSQL One-click deploy from GitHub
Netlify PlanetScale Build: npm run build, Dir: .next

Deployment Checklist

  1. Build locally: npm run build (ensure no errors)
  2. Environment variables: Copy all from .env.local to your platform
  3. Database: Set up PostgreSQL and run migrations
  4. Domain: Update NEXT_PUBLIC_SITE_URL to your production URL
  5. Test: Verify authentication and file uploads work

🀝 Contributing

We welcome contributions to the Discord Clone project! Here's how you can help:

Getting Started

  1. Fork the repository
  2. Clone your fork:
    git clone https://github.com/yourusername/discord-clone.git
  3. Create a feature branch:
    git checkout -b feature/amazing-feature
  4. Make your changes and commit:
    git commit -m 'Add some amazing feature'
  5. Push to your branch:
    git push origin feature/amazing-feature
  6. Open a Pull Request

Development Guidelines

  • Code Style: Follow the existing code style and use ESLint
  • TypeScript: Maintain type safety throughout the codebase
  • Testing: Add tests for new features (when test suite is available)
  • Documentation: Update documentation for significant changes
  • Commits: Use clear, descriptive commit messages

Areas for Contribution

  • 🎡 Voice/Video Chat - WebRTC integration for audio/video channels
  • πŸ”’ Advanced Permissions - Granular role-based permissions
  • 🎨 UI/UX Improvements - Enhanced user interface and experience
  • πŸ“± Mobile Optimization - Better mobile responsiveness
  • πŸ” Search Functionality - Message and server search
  • πŸ€– Bot Integration - Discord bot support
  • 🌐 Internationalization - Multi-language support
  • ⚑ Performance - Optimization and caching improvements

Reporting Issues

When reporting issues, please include:

  • Environment details (OS, Node.js version, browser)
  • Steps to reproduce the issue
  • Expected vs actual behavior
  • Screenshots if applicable
  • Error messages from console/logs

πŸ“„ License

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

Key points:

  • βœ… Commercial use allowed
  • βœ… Modification allowed
  • βœ… Distribution allowed
  • βœ… Private use allowed
  • ❌ No warranty provided
  • ❌ No liability assumed

πŸ“ž Support & Contact

Getting Help

  • πŸ“– Documentation: Check this README and inline code comments
  • πŸ› Issues: Report bugs and request features via GitHub Issues
  • πŸ’¬ Discussions: Ask questions and share ideas in GitHub Discussions
  • πŸ“š Code Examples: Review the codebase for implementation details

Community Resources

  • Stack Overflow: Tag your questions with discord-clone and nextjs
  • Next.js Community: Next.js Discord for framework-specific help
  • React Community: Reactiflux Discord for React questions

πŸ™ Acknowledgments

  • Discord - For the inspiration and design reference
  • Vercel - For the amazing Next.js framework and hosting
  • Clerk - For seamless authentication
  • Prisma - For the excellent database toolkit
  • Radix UI - For accessible component primitives
  • Tailwind CSS - For the utility-first CSS framework

Made with ❀️ by the Discord Clone team

Back to top

About

A discord clone made with Nextjs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published