π Social Media API is a backend system for a simplified Twitter-like platform. It allows users to π post tweets with hashtags, π follow/unfollow users, and π view a personalized feed. Built with Express.js and PostgreSQL, it utilizes advanced SQL queries for hashtag detection and feed generation.
Build a scalable and efficient backend for a social media platform with essential features like user interactions, feeds, and hashtags.
- π Post tweets with hashtags.
- π Follow/unfollow users.
- π Feed showing tweets from followed users.
- π Hashtag detection using LIKE queries.
- π Optimized SQL queries for better performance.
1οΈβ£ Database Setup: Create tables for users
, tweets
, hashtags
, and follows
.
2οΈβ£ Followers System: Add a followers
join table (follower_id
, followed_id
).
3οΈβ£ Hashtag Detection: Implement LIKE
queries to detect hashtags (e.g., #express
).
4οΈβ£ Feed Generation: Use complex SQL queries to fetch tweets from followed users.
5οΈβ£ Real-Time Updates (Optional): Implement WebSockets for live tweet updates.
- Backend Framework: Express.js
- Database: PostgreSQL
- Authentication: JWT
- WebSockets (Optional for real-time updates)
social-media-api/
βββ config/
β βββ db.js # PostgreSQL connection
βββ routes/
β βββ auth.js # User registration/login
β βββ tweets.js # Tweet CRUD, hashtag extraction
β βββ users.js # Follow/unfollow, profile
β βββ feed.js # User feed logic
βββ controllers/
β βββ authController.js
β βββ tweetController.js
β βββ userController.js
β βββ feedController.js
βββ models/
β βββ User.js # User schema/queries
β βββ Tweet.js # Tweet schema/queries
β βββ Hashtag.js # Hashtag schema/queries
β βββ Follow.js # Follow schema/queries
βββ middleware/
β βββ auth.js # Authentication
β βββ errorHandler.js # Global error handling
βββ app.js
β‘ Method | π Endpoint | π Description |
---|---|---|
POST | /auth/register | π User registration |
POST | /auth/login | π User login |
POST | /tweets | π Create a tweet |
GET | /tweets/:id | π View a tweet |
GET | /feed | π Get user feed |
POST | /users/:id/follow | π Follow a user |
POST | /users/:id/unfollow | β Unfollow a user |
- π Advanced SQL queries for efficient data retrieval.
- π Feed algorithms to generate personalized timelines.
- π Real-time updates (with WebSockets, optional).
Contributions are welcome! Open an issue or submit a pull request.
This project is licensed under the MIT License.