A full-stack Twitter/X clone built with the MERN stack featuring real-time posts, notifications, user profiles, and social interactions.
- Features
- Tech Stack
- Architecture
- Getting Started
- Project Structure
- API Endpoints
- Contributing
- License
- π 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
- πΌοΈ 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
| 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 |
| 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 |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT (React) β
β βββββββββββ ββββββββββββ ββββββββββββ ββββββββββββββ β
β β Pages β βComponentsβ β Hooks β β Utils β β
β β β β β β(React β β β β
β β β β β β Query) β β β β
β ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ βββββββ¬βββββββ β
β ββββββββββββββββ΄ββββββββββββββ΄ββββββββββββββββ β
β β β
β Axios + React Query β
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SERVER (Express) β
β ββββββββββββ βββββββββββββ ββββββββββββ βββββββββββββ β
β β Routes β βControllersβ βMiddlewareβ β Lib β β
β ββββββ¬ββββββ βββββββ¬ββββββ ββββββ¬ββββββ βββββββ¬ββββββ β
β ββββββββββββββββ΄ββββββββββββββ΄ββββββββββββββββ β
β β β
β ββββββββββββββ΄βββββββββββββ β
β βΌ βΌ β
β ββββββββββββββββββββ ββββββββββββββββββββ β
β β MongoDB β β Cloudinary β β
β β (Database) β β (Image Storage) β β
β ββββββββββββββββββββ ββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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)
-
Clone the repository
git clone https://github.com/KaizenPrad/Twitter-Clone.git cd Twitter-Clone -
Install root dependencies
npm install
-
Install backend dependencies
cd backend npm install -
Install frontend dependencies
cd ../frontend npm install -
Set up environment variables (see below)
-
Start the development servers
In one terminal (backend):
cd backend npm run devIn another terminal (frontend):
cd frontend npm run dev -
Open your browser
Frontend: http://localhost:5173 Backend: http://localhost:5000
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:5173Twitter-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
| 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 |
| 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 |
| 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 |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/notifications |
Get notifications | Authenticated |
| DELETE | /api/notifications |
Clear notifications | Authenticated |
Add screenshots of your application here
[Home Feed] [Create Post] [User Profile] [Notifications]
| Command | Description |
|---|---|
npm install |
Install all dependencies |
| Command | Description |
|---|---|
npm run dev |
Start with nodemon (hot reload) |
npm start |
Start production server |
| 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 |
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m 'Add amazing feature' - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
Pradyumn Dwivedi
- GitHub: @KaizenPrad
- LinkedIn: Pradyumn Dwivedi
- Express.js Documentation
- React Documentation
- Tailwind CSS Documentation
- MongoDB Documentation
- DaisyUI Documentation
β Star this repository if you found it helpful! β