A modern, scalable backend for a social networking platform built with cutting-edge technologies.
- User Authentication & Authorization - Secure JWT-based authentication
- User Profiles - Customizable user profiles with bio, avatar, and personal information
- Posts & Content - Create, edit, delete, and share posts with media support
- Social Interactions - Like, comment, and share functionality
- Follow System - Follow/unfollow users and build your network
- Real-time Messaging - Direct messaging between users
- News Feed - Personalized feed algorithm based on connections and interests
- Notifications - Real-time notifications for interactions and updates
- Media Upload - Image and video upload with cloud storage integration
- Search & Discovery - Find users, posts, and content with advanced search
- Privacy Controls - Granular privacy settings for posts and profile visibility
- Content Moderation - Automated and manual content moderation tools
- Analytics - User engagement and platform analytics
- API Rate Limiting - Protection against abuse and spam
- Node.js - Runtime environment
- Express.js - Web application framework
- MongoDB - Primary database for user data and posts
- Mongoose - MongoDB object modeling
- JWT - JSON Web Tokens for authentication
- bcrypt - Password hashing
- Helmet - Security middleware
- CORS - Cross-origin resource sharing
- Cloudinary - Image processing and optimization
- Socket.io - Real-time messaging and notifications
- WebSocket - Live updates and notifications
Before running this project, make sure you have:
- Node.js
- MongoDB
- npm or yarn package manager
git clone https://github.com/DevDad-Main/Knect-Backend.git
cd Knect-Backendnpm install
# or
yarn installCreate a .env file in the root directory:
ACCESS_TOKEN_EXPIRY="24h"
ACCESS_TOKEN_SECRET="tokensecretgoeshere"
CORS_ORIGIN="your cors origin here"
FRONTEND_URL="your frontend url here"
IMAGEKIT_ID=""
IMAGEKIT_PRIVATE_KEY=""
IMAGEKIT_PUBLIC_KEY=""
INNGEST_EVENT_KEY=""
INNGEST_SIGNING_KEY=""
MONGODB_URL=""
PORT="5000"
REFRESH_TOKEN_EXPIRY="24h"
REFRESH_TOKEN_SECRET="tokensecretgoeshere"
SENDER_EMAIL=""
SMTP_PASS=""
SMTP_USER=""npm run dev
# or
yarn devThe server will start on http://localhost:5000
export const verifyJWT = async (req, _, next) => {
const token =
req.cookies.accessToken ||
req.header("Authorization")?.replace("Bearer ", "");
if (!token) {
throw new ApiError(401, "Unauthorized");
}
try {
const decodedToken = jwt.verify(token, process.env.ACCESS_TOKEN_SECRET);
const user = await User.findById(decodedToken?._id).select(
"username refreshToken",
);
if (!user) {
throw new ApiError(401, "Unauthorized");
}
next();
} catch (error) {
throw new ApiError(401, error?.message || "Invalid access token");
}
};POST /api/vi/user/register - Register new user
POST /api/v1/user/login - User login
POST /api/v1/user/logout - User logout
GET /api/v1/user/profile/:id - Get user profile
POST /api/v1/user/update-user - Update user profile
POST /api/v1/user/follow - Follow user
POST /api/v1/user/unfollow - Unfollow user
POST /api/v1/user/discover - Discover users
GET /api/v1/user/connections - Get connections
GET /api/v1/post/feed - Get posts feed
POST /api/v1/post/add - Create new post
GET /api/v1/post/:postId - Get post by ID
DELETE /api/v1/post/:postId - Delete post
POST /api/v1/post/like - Like/unlike post
GET /api/v1/message/get/:to_user_id - Get conversation
POST /api/v1/message/send - Send message
GET /api/v1/message/recent-messages - Get conversation
PUT /api/v1/message/mark-as-seen - Mark as read
Knect-Backend/
βββ src/
β βββ controllers/ # Route controllers
β βββ db/ # MongoDB connection
β βββ models/ # Database models
β βββ routes/ # API routes
β βββ middlewares/ # Custom middleware
β βββ utils/ # Utility functions
βββ .env.example # Environment variables template
βββ package.json
βββ README.md
npm run build
npm start- Development - Local development with hot reload
- Production - Optimized production deployment
- Database Indexing - Optimized queries with proper indexing
- Image Optimization - Automatic image compression and resizing
- Input Validation - Express-Validator validation for all inputs
- XSS Protection - Content sanitization
- CSRF Protection - Cross-site request forgery prevention
- Helmet.js - Security headers
- Data Encryption - Sensitive data encryption at rest
We welcome contributions! 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 MIT License - see the LICENSE file for details.
- DevDad-Main - Lead Developer & Project Maintainer - softwaredevdad@gmail.com
- Initial release with core social networking features
- User authentication and profile management
- Post creation and social interactions
- Real-time messaging system
- Basic notification system