A full-stack Twitter clone built with Next.js 13, React, Tailwind CSS, Prisma, and MongoDB. This application replicates core features of Twitter, allowing users to register, create posts (tweets), follow other users, comment on posts, and receive notifications.
- User Authentication: Secure credential-based login and registration system.
- Profile Management: Users can edit their profile, including changing their bio, profile image, cover image, name, and username.
- Image Uploads: Base64 image upload functionality using
react-dropzonefor avatars and cover photos.
- Follow System: Users can follow and unfollow other users.
- Tweeting: Create text-based posts (tweets).
- Interactions:
- Like and unlike posts.
- Reply to posts with comments.
- Notifications: Real-time notification system. Users receive notifications when someone follows them, likes their post, or replies to their post.
- Responsive Design: Fully responsive layout that looks great on mobile, tablet, and desktop devices.
- Modals: Custom modals for Login, Register, and Edit Profile actions to ensure a seamless user experience.
- Toast Notifications: Interactive toast notifications for user feedback (success/error messages) using
react-hot-toast. - Loading States: Spinners and loading states for data fetching and mutations.
- Framework: Next.js 13 (React Framework)
- Styling: Tailwind CSS
- Database: MongoDB (NoSQL Database)
- ORM: Prisma
- Authentication: NextAuth.js
- State Management: Zustand
- Data Fetching: SWR
- Icons: React Icons
- Date Formatting:
date-fns - Password Hashing:
bcrypt
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher)
- npm or yarn
- A MongoDB database URL (You can set up a free cluster on MongoDB Atlas)
-
Clone the repository (if applicable) or download the source code.
git clone <repository-url> cd twitter-next13
-
Install dependencies
npm install # or yarn install -
Set up Environment Variables Create a
.envfile in the root directory and add the following variables:DATABASE_URL="your_mongodb_connection_string" NEXTAUTH_JWT_SECRET="your_jwt_secret" NEXTAUTH_SECRET="your_nextauth_secret"
Note: You can generate a random string for the secrets using
openssl rand -base64 32or any password generator. -
Initialize Prisma Push the Prisma schema to your MongoDB database to sync the structure:
npx prisma db push
-
Run the Development Server
npm run dev # or yarn devOpen http://localhost:3000 with your browser to see the result.
The project uses the following core entities via Prisma:
- User: Stores user details (username, email, bio, images) and tracks relationships like following/followers, posts, comments, and notifications.
- Post: Represents a tweet. Contains the content (
body), timestamp, the author (userId), and an array oflikedIds. - Comment: Represents a reply to a post. Linked to both a
Userand aPost. - Notification: Stores notifications for users regarding interactions (likes, follows, replies).
This project is open-source and available for educational purposes.