A robust Express.js backend server for the X social media platform, handling authentication, posts, likes, and image uploads.
-
Authentication System
- JWT-based authentication
- Google OAuth integration
- Password reset functionality
- Session management
- Token refresh mechanism
-
Posts Management
- CRUD operations for posts
- Multiple image upload support (up to 3 images)
- Like/unlike functionality
- User-specific post retrieval
-
User Management
- Profile updates
- Password management
- Image upload for profile pictures
- User settings
- Express.js
- JWT Authentication
- Passport.js for OAuth
- MongoDB (Database)
- Joi for input validation
- Multer for image handling
- Navigate to the server directory:
cd server2
- Install dependencies:
npm install
- Create a
.env
file with the following variables:
JWT_SECRET=your_jwt_secret
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
MONGODB_URI=your_mongodb_connection_string
- Start the development server:
npm start
server2/
├── Controllers/ # Route controllers
│ ├── authController.js # Authentication logic
│ ├── postsController.js # Posts management
│ ├── usersController.js # User management
│ └── likesController.js # Likes functionality
├── Middlewares/ # Custom middlewares
│ └── authMiddleware.js # Authentication middleware
├── Routes/ # API routes
│ ├── authRoutes.js # Authentication routes
│ ├── postsRoutes.js # Posts routes
│ ├── usersRoutes.js # User routes
│ └── likesRoutes.js # Likes routes
├── utils/ # Utility functions
│ └── images.js # Image handling utilities
└── validation/ # Input validation schemas
├── userValidation.js
└── postValidation.js
POST /api/auth/signup
- Register new userPOST /api/auth/login
- User loginPOST /api/auth/refresh
- Refresh authentication tokenPOST /api/auth/forgotPassword
- Request password resetPATCH /api/auth/resetPassword/:token
- Reset passwordGET /api/auth/google
- Google OAuth loginGET /api/auth/google/callback
- Google OAuth callback
GET /api/users/me
- Get current user profilePATCH /api/users/updateMe
- Update user profilePATCH /api/users/updateMyPassword
- Update password
GET /api/posts
- Get all postsPOST /api/posts
- Create new postGET /api/posts/:id
- Get specific postPATCH /api/posts/:id
- Update postDELETE /api/posts/:id
- Delete postGET /api/posts/me
- Get user's posts
GET /api/posts/:postId/likes
- Get post likesPOST /api/posts/:postId/likes
- Add likeDELETE /api/posts/:postId/likes
- Remove like
- JWT-based authentication
- Password hashing
- Input validation
- Protected routes
- Secure cookie handling
- OAuth 2.0 implementation
-
Performance Optimization
- Add rate limiting
- Optimize database queries
- Add request compression
-
Additional Features
- Comments system
- User following/followers
- Direct messaging
- Real-time notifications
- Comments
-
Security Improvements
- Add request validation
- Implement API key management
- Add request logging
- Enhance error handling
-
Monitoring & Analytics
- Add logging system
- Implement performance monitoring
- Add user analytics
- Track API usage
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.