A comprehensive social media backend API built with Node.js and Express, designed for college communities with features including posts, loops (communities), events, messaging, and real-time notifications.
- Runtime: Node.js
- Framework: Express.js 4.18
- Database: PostgreSQL (Google Cloud SQL)
- ORM: Sequelize 6.37
- Authentication: Firebase Admin SDK
- File Storage: AWS S3 (via AWS SDK)
- File Upload: Multer
- Scheduling: node-cron
- Additional: CORS, dotenv, axios, cheerio
The project follows an MVC (Model-View-Controller) pattern with a service layer:
src/
├── controllers/ # Request handlers and route logic
├── services/ # Business logic layer
├── models/ # Sequelize database models and associations
├── utils/ # Utilities (error handling, tokens, helpers)
└── router.js # Route definitions
- Async Error Handling: Custom
catchAsyncwrapper for promise-based error handling - Custom Error Classes:
APIErrorutility for standardized error responses - Service Layer: Business logic separated from controllers
- Database Associations: Complex Sequelize relationships between users, posts, loops, events, and more
- User Management: Registration, profiles, search, follow/unfollow, blocking
- Posts: Create, like, comment, polls with voting, college-specific feeds
- Loops: Community groups with membership, admin roles, join requests, announcements, and group chats
- Events: Create, join/leave, attendee management, automated notifications
- Comments & Replies: Nested comments with like functionality
- Direct Messaging: Thread-based messaging between users
- Notifications: Real-time notifications with read/unread status
- Media Uploads: Image uploads via AWS S3 (10MB limit)
- College Management: University/college association and filtering
- Database Cleanup: Daily cron job removes events older than 7 days and notifications older than 7 days
- Event Notifications: Hourly and daily checks for upcoming events with automated attendee notifications
- System Posts: Automatic welcome posts for college feeds
Key models and relationships:
- Users (
torus_users): Core user profiles with college associations - Posts: User-generated content with loop/college associations, polls, and likes
- Loops: Community groups with members, admins, join requests, and announcements
- Events: Scheduled events with attendee tracking
- Comments & Replies: Nested comment system with likes
- Followings: User-to-user follow relationships
- Blocked Users: User blocking functionality
- Notifications: In-app notification system
- Votes: Poll voting system
GET /api/user- Get current userGET /api/user/:USERNAME- Get user by usernamePOST /api/user/register- Register new userPOST /api/user/update/:FIELD- Update user fieldGET /api/users- Search usersGET /api/user/:USERNAME/followers- Get user followersGET /api/user/:USERNAME/following- Get user followingPOST /api/user/:USERNAME/follow- Follow userPOST /api/user/:USERNAME/unfollow- Unfollow userPOST /api/user/:USERNAME/block- Block user
GET /api/posts/get/:POSTID- Get post by IDGET /api/posts/user/:USERNAME- Get user postsGET /api/posts/following- Get posts from followed usersGET /api/posts/loop/:LOOPID- Get loop postsGET /api/posts/college- Get college postsPOST /api/posts/add- Create postPOST /api/posts/like- Like postPOST /api/posts/unlike- Unlike postPOST /api/posts/vote- Vote on pollDELETE /api/posts/delete/:POSTID- Delete post
GET /api/loops- Discover loopsGET /api/loops/joined- Get joined loopsGET /api/loops/:LOOPID- Get loop detailsPOST /api/loops/add- Create loopPOST /api/loops/:LOOPID/join- Join loopPOST /api/loops/:LOOPID/leave- Leave loopGET /api/loops/:LOOPID/members- Get loop membersPOST /api/loops/:LOOPID/announcement- Create announcementGET /api/loops/:LOOPID/messages- Get loop messages
POST /api/events/create- Create eventGET /api/events/get/:EVENTID- Get eventGET /api/events/get- Get public eventsPOST /api/events/:EVENTID/join- Join eventPOST /api/events/:EVENTID/leave- Leave eventDELETE /api/events/:EVENTID/delete- Delete event
POST /api/comments/add- Create commentPOST /api/comments/reply- Create replyGET /api/comments/post/:POSTID- Get post commentsPOST /api/comments/:COMMENTID/like- Like commentDELETE /api/comments/:COMMENTID/delete- Delete comment
POST /api/upload- Upload media (multipart/form-data)GET /api/notifications/get- Get notificationsPOST /api/messages/add- Send messageGET /api/messages/threads- Get message threadsGET /api/colleges- Search colleges
The application uses Google Cloud SQL Connector for secure database connections. In development mode, it automatically configures the connection with the provided instance connection name.
- Custom
APIErrorclass for standardized error responses catchAsyncwrapper for automatic error catching in async route handlers- Centralized error handling via
handleErrorutility
- Firebase Admin SDK for authentication token verification
- CORS enabled for cross-origin requests
- File upload size limits (10MB)
- User blocking and content reporting features
- Requires
firebasekey.jsonin the root directory for Firebase authentication - Database models are auto-loaded from the
models/directory - Sequelize associations are configured in
models/index.js - Automated cron jobs run for database cleanup and event notifications