Skip to content

Latest commit

Β 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐦 Twitter Clone

A full-stack Twitter/X clone built with the MERN stack featuring real-time posts, notifications, user profiles, and social interactions.

React Node.js Express MongoDB Tailwind CSS DaisyUI


πŸ“‹ Table of Contents


✨ Features

Core Features

  • πŸ” User Authentication - Secure signup/login with JWT tokens
  • πŸ“ Create Posts - Tweet with text and images
  • ❀️ Like & Retweet - Engage with content
  • πŸ‘₯ Follow System - Follow/unfollow users
  • πŸ“° Home Feed - See posts from followed users
  • πŸ”” Notifications - Real-time notification system
  • πŸ‘€ User Profiles - Customizable profile with bio and avatar

Advanced Features

  • πŸ–ΌοΈ Image Upload - Share images with your tweets
  • πŸ” Explore - Discover new content and trending topics
  • πŸ“± Responsive Design - Perfect on desktop and mobile
  • 🎨 Modern UI - Twitter-like interface with DaisyUI
  • ⚑ React Query - Optimistic updates and caching
  • πŸ”„ Real-time Updates - Instant feed refresh

πŸ› οΈ Tech Stack

Backend

Technology Purpose
Node.js Runtime environment
Express.js Web framework
MongoDB NoSQL database
Mongoose ODM for MongoDB
JWT Authentication tokens
bcryptjs Password hashing
Cloudinary Image storage & optimization
Cookie Parser Cookie handling
CORS Cross-origin resource sharing

Frontend

Technology Purpose
React 19 UI library
Vite Build tool & dev server
Tailwind CSS Utility-first CSS framework
DaisyUI Tailwind component library
React Query Server state management
React Router Client-side routing
Axios HTTP client
React Icons Icon library
React Hot Toast Notifications

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      CLIENT (React)                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Pages   β”‚  β”‚Componentsβ”‚  β”‚  Hooks   β”‚  β”‚   Utils    β”‚  β”‚
β”‚  β”‚          β”‚  β”‚          β”‚  β”‚(React    β”‚  β”‚            β”‚  β”‚
β”‚  β”‚          β”‚  β”‚          β”‚  β”‚ Query)   β”‚  β”‚            β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                           β”‚                                  β”‚
β”‚                       Axios + React Query                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    SERVER (Express)                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Routes   β”‚  β”‚Controllersβ”‚  β”‚Middlewareβ”‚  β”‚   Lib     β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β”‚
β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                           β”‚                                  β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”‚
β”‚              β–Ό                         β–Ό                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚  β”‚     MongoDB      β”‚      β”‚    Cloudinary     β”‚            β”‚
β”‚  β”‚    (Database)    β”‚      β”‚  (Image Storage)  β”‚            β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18.0.0 or higher)
  • npm (v9.0.0 or higher)
  • MongoDB (local instance or MongoDB Atlas account)
  • Cloudinary account (for image storage)

Installation

  1. Clone the repository

    git clone https://github.com/KaizenPrad/Twitter-Clone.git
    cd Twitter-Clone
  2. Install root dependencies

    npm install
  3. Install backend dependencies

    cd backend
    npm install
  4. Install frontend dependencies

    cd ../frontend
    npm install
  5. Set up environment variables (see below)

  6. Start the development servers

    In one terminal (backend):

    cd backend
    npm run dev

    In another terminal (frontend):

    cd frontend
    npm run dev
  7. Open your browser

    Frontend: http://localhost:5173
    Backend:  http://localhost:5000
    

Environment Variables

Create a .env file in the backend directory:

# Server Configuration
PORT=5000
NODE_ENV=development

# MongoDB Connection
MONGODB_URI=mongodb://localhost:27017/twitter-clone

# JWT Secrets
ACCESS_TOKEN_SECRET=your_access_token_secret_here
REFRESH_TOKEN_SECRET=your_refresh_token_secret_here

# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

# Client URL (for CORS)
CLIENT_URL=http://localhost:5173

πŸ“ Project Structure

Twitter-Clone/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ controllers/         # Request handlers
β”‚   β”‚   β”œβ”€β”€ auth.controller.js
β”‚   β”‚   β”œβ”€β”€ notification.controller.js
β”‚   β”‚   β”œβ”€β”€ post.controller.js
β”‚   β”‚   └── user.controller.js
β”‚   β”œβ”€β”€ db/                  # Database connection
β”‚   β”œβ”€β”€ lib/utils/           # Utility functions
β”‚   β”œβ”€β”€ middleware/           # Custom middleware (auth)
β”‚   β”œβ”€β”€ models/              # Mongoose data models
β”‚   β”‚   β”œβ”€β”€ notification.model.js
β”‚   β”‚   β”œβ”€β”€ post.model.js
β”‚   β”‚   └── user.model.js
β”‚   β”œβ”€β”€ routes/              # API route definitions
β”‚   └── server.js            # Entry point
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/      # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ hooks/           # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ lib/             # Utility functions
β”‚   β”‚   β”œβ”€β”€ pages/           # Route-level components
β”‚   β”‚   β”œβ”€β”€ utils/           # Helper utilities
β”‚   β”‚   β”œβ”€β”€ App.jsx          # Main app with routing
β”‚   β”‚   β”œβ”€β”€ index.css        # Global styles
β”‚   β”‚   └── main.jsx         # Entry point
β”‚   β”œβ”€β”€ public/              # Static assets
β”‚   β”œβ”€β”€ index.html           # HTML template
β”‚   β”œβ”€β”€ vite.config.js       # Vite configuration
β”‚   β”œβ”€β”€ tailwind.config.js   # Tailwind configuration
β”‚   └── package.json
β”‚
β”œβ”€β”€ .gitignore
β”œβ”€β”€ package.json             # Root package.json
└── README.md

πŸ“‘ API Endpoints

Authentication

Method Endpoint Description Access
POST /api/auth/signup Register new user Public
POST /api/auth/login Login user Public
POST /api/auth/logout Logout user Authenticated
GET /api/auth/me Get current user Authenticated

Users

Method Endpoint Description Access
GET /api/users/profile/:username Get user profile Public
PUT /api/users/update Update profile Authenticated
POST /api/users/follow/:userId Follow user Authenticated
POST /api/users/unfollow/:userId Unfollow user Authenticated
GET /api/users/suggested Get suggested users Authenticated

Posts

Method Endpoint Description Access
GET /api/posts/feed Get home feed Authenticated
GET /api/posts/user/:username Get user posts Public
GET /api/posts/:postId Get single post Public
POST /api/posts/create Create new post Authenticated
DELETE /api/posts/:postId Delete post Owner
POST /api/posts/like/:postId Like post Authenticated
POST /api/posts/unlike/:postId Unlike post Authenticated
POST /api/posts/retweet/:postId Retweet post Authenticated

Notifications

Method Endpoint Description Access
GET /api/notifications Get notifications Authenticated
DELETE /api/notifications Clear notifications Authenticated

🎨 Screenshots

Add screenshots of your application here

[Home Feed]  [Create Post]  [User Profile]  [Notifications]

πŸ”§ Available Scripts

Root

Command Description
npm install Install all dependencies

Backend

Command Description
npm run dev Start with nodemon (hot reload)
npm start Start production server

Frontend

Command Description
npm run dev Start Vite dev server
npm run build Build for production
npm run preview Preview production build
npm run lint Run ESLint

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Commit your changes
    git commit -m 'Add 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 ISC License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Pradyumn Dwivedi


πŸ™ Acknowledgments


⭐ Star this repository if you found it helpful! ⭐

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages