A full-stack social media application built with React.js and Node.js that replicates core Twitter functionality.
- User Authentication: Secure signup, login, and logout with JWT tokens
- Profile Management: Edit profile information, bio, and profile pictures
- Posts & Feed: Create, view, and interact with posts
- Real-time Notifications: Get notified about likes, follows, and mentions
- Image Upload: Upload and manage images using Cloudinary
- Responsive Design: Mobile-first design with Tailwind CSS
- Follow System: Follow/unfollow other users
- Protected Routes: Secure API endpoints with middleware
- React.js - UI library
- Vite - Build tool
- Tailwind CSS - Styling
- DaisyUI - UI components
- TanStack Query - Data fetching and state management
- React Router DOM - Client-side routing
- React Hot Toast - Notifications
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM for MongoDB
- JWT - Authentication tokens
- bcryptjs - Password hashing
- Cloudinary - Image storage and management
- Cookie Parser - Cookie handling
Twitter-Clone/
βββ backend/
β βββ controllers/
β β βββ authentication_controller.js
β β βββ user_controller.js
β β βββ post_controller.js
β β βββ notification_controller.js
β βββ middleware/
β β βββ protectRoute.js
β βββ models/
β β βββ user_module.js
β β βββ post_model.js
β β βββ notification_model.js
β βββ routes/
β β βββ authentication_route.js
β β βββ user_route.js
β β βββ post_route.js
β β βββ notification_route.js
β βββ db/
β β βββ connectMongoDB.js
β βββ lib/
β β βββ utils/
β β βββ generate_Token.js
β βββ server.js
βββ frontend/
βββ src/
β βββ components/
β β βββ common/
β β βββ skeletons/
β β βββ svgs/
β βββ pages/
β β βββ authentication/
β β βββ home/
β β βββ notification/
β β βββ profile/
β βββ hooks/
β βββ utils/
βββ public/
βββ package.json
- Node.js (v14 or higher)
- MongoDB
- Cloudinary account
-
Clone the repository
git clone https://github.com/yourusername/twitter-clone.git cd Twitter-Clone -
Backend Setup
cd backend npm install -
Frontend Setup
cd frontend npm install -
Environment Variables
Create a
.envfile in the backend directory:PORT=5000 MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key NODE_ENV=development # Cloudinary Configuration CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name CLOUDINARY_API_KEY=your_cloudinary_api_key CLOUDINARY_API_SECRET=your_cloudinary_api_secret
-
Run the Application
Backend (from backend directory):
npm start # or for development with nodemon npm run devFrontend (from frontend directory):
npm run dev
The application will be available at:
- Frontend:
http://localhost:3000 - Backend:
http://localhost:5000
- Frontend:
POST /signup- User registrationPOST /login- User loginPOST /logout- User logoutGET /me- Get current authenticated user
GET /profile/:username- Get user profilePOST /follow/:id- Follow/unfollow userGET /suggested- Get suggested usersPOST /update- Update user profile
GET /all- Get all postsGET /following- Get posts from followed usersGET /likes/:id- Get user's liked postsGET /user/:username- Get user's postsPOST /create- Create new postPOST /like/:id- Like/unlike postPOST /comment/:id- Comment on postDELETE /:id- Delete post
GET /- Get user notificationsDELETE /- Delete all notifications
User Model
{
username: String (unique),
fullName: String,
password: String (hashed),
email: String (unique),
followers: [ObjectId],
following: [ObjectId],
profileImg: String,
coverImg: String,
bio: String,
link: String,
likedPosts: [ObjectId]
}Post Model
{
user: ObjectId,
text: String,
img: String,
likes: [ObjectId],
comments: [{
text: String,
user: ObjectId
}]
}Notification Model
{
from: ObjectId,
to: ObjectId,
type: String (follow, like),
read: Boolean
}- Sidebar: Navigation menu with user profile
- Posts: Feed display with like/comment functionality
- Profile Page: User profile with edit capabilities
- Notifications: Real-time notification system
- Authentication: Login and signup forms
- Loading Spinners: Enhanced UX during data fetching
- JWT Authentication: Secure token-based authentication
- Protected Routes: Middleware for route protection
- Image Upload: Cloudinary integration for image handling
- Password Security: bcrypt hashing for passwords
- Error Handling: Comprehensive error management
- JWT token authentication with HTTP-only cookies
- Password hashing with bcryptjs
- Protected API routes with middleware
- Input validation and sanitization
- CORS configuration
- Rate limiting on requests (5MB limit)
- Secure cookie settings for production
- Set
NODE_ENV=productionin environment variables - Configure production MongoDB URI
- Set secure cookie options
- Deploy to platforms like:
- Heroku
- Railway
- DigitalOcean
- AWS EC2
- Build the frontend:
cd frontend npm run build - Deploy to platforms like:
- Vercel
- Netlify
- AWS S3 + CloudFront
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit changes:
git commit -m 'Add some feature' - Push to branch:
git push origin feature-name - Submit a pull request
{
"start": "node server.js",
"dev": "nodemon server.js"
}{
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}- Profile updates may require a page refresh in some cases
- Image uploads are limited to 5MB
- Real-time features require manual refresh
This project is licensed under the MIT License - see the LICENSE file for details.
- Icons from React Icons library
- UI components inspired by Twitter's design
- Image handling powered by Cloudinary
- Authentication patterns from JWT best practices
If you have any questions or suggestions, feel free to reach out!
- GitHub: @yourusername
- Email: your.email@example.com