A RESTful backend API built with Node.js, Express, and MongoDB. This API powers a social media application with users, posts, comments, replies, and private messaging.
Social-API REST is a scalable and secure REST API designed to handle the core features of a social platform. It follows best practices in API design, authentication, data modeling, and middleware usage.
The API is frontend-agnostic and can be consumed by any client (React, Flutter, mobile apps, etc.).
- Secure registration and login with JWT
- Password hashing with bcrypt
- Profile updates
- Create, read, update, delete posts
- Comments and threaded replies
- Likes system (optional)
- Send private messages
- Real-time notifications with Socket.io
- Mark messages as read
- Count unread messages
- Update and delete messages
- Track user notifications
- Mark notifications as read
- JWT authentication
- Middleware for protected routes
- Input validation
- Environment variables for sensitive data
- Modular project structure
- Clean code with controllers, middleware, and routes
- Ready for deployment (Heroku, Render, Railway, etc.)
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT (JSON Web Tokens)
- bcrypt
- dotenv
- cors
backend/
├── config/
│ └── db.js # MongoDB connection
│
├── controllers/
│ ├── auth.controller.js # Authentication logic
│ ├── user.controller.js # User-related actions
│ ├── post.controller.js # Posts logic
│ ├── notification.controller.js # Notification logic
│ ├── message.controller.js # Messaging logic
│
├── middleware/
│ ├── auth.middleware.js # JWT authentication
│ ├── upload.middleware.js # Config upload file
│
├── models/
│ ├── user.model.js # user shema
│ ├── notification.model.js # notification shema
│ ├── message.model.js # message shema
│
├── routes/
│ ├── auth.routes.js
│ ├── notification.routes.js
│ ├── post.routes.js
│
├── utils/
│ └──createNotification.js
│
├── server.js # App entry point
├── package.json
└── .env
- Node.js (v18 or higher)
- MongoDB (local instance or MongoDB Atlas)
- Clone the repository:
git clone https://github.com/fetrafanevacontent-api-backend.git cd backend - Install dependencies:
cd backend npm install - Configure environment variables:
- Create
.envin/server:PORT=your_port MONGO_URI=your_mongodb_URI JWT_SECRET=your_secure_jwt_secret
- Start the application:
npm run server (with nodemon)
| Method | Endpoint | Description | Authentication Required |
|---|---|---|---|
| POST | /api/auth/register |
Register a new user | No |
| POST | /api/auth/login |
User login | No |
| GET | /api/auth/logout |
User logout | yes |
| Method | Endpoint | Description | Authentication Required |
|---|---|---|---|
| POST | /api/post |
Create post | yes |
| GET | /api/post |
Get all post | yes |
| PUT | /api/post/:id |
Update post | yes |
| DELETE | /api/auth/:id |
Delete post | yes |
| Method | Endpoint | Description | Authentication Required |
|---|---|---|---|
| POST | /api/post/:id/comment |
Get message | yes |
| POST | /api/post/:postId/comment/:commentId/reply |
Reply to comment | yes |
| PATCH | /api/post/:postId/comment/:commentId/reply/:replyId |
Uptdate reply | yes |
| DELETE | /api/post/:postId/comment/:commentId/reply/:replyId |
Delete reply | yes |
| Method | Endpoint | Description | Authentication Required |
|---|---|---|---|
| POST | /api/message/ |
Send message | yes |
| GET | /api/message/inbox |
Comment a post | yes |
| GET | /api/message/unread/count |
Count unread message | yes |
| GET | /api/message/conversations |
GET all conversations | yes |
| GET | /api/message/conversation/:userId |
Get users conversation | yes |
| PATCH | /api/message/conversations/:userId/read |
Mark conversation as read | yes |
| PATCH | /api/message/:id/read |
Mark message as read | yes |
| PUT | /api/message/:id |
Update message | yes |
| DELETE | /api/message/:id |
Delete message | yes |
| Method | Endpoint | Description | Authentication Required |
|---|---|---|---|
| GET | /api/notification/ |
Get notification | yes |
| PATCH | /api/notification/:id/read |
Mark notiication as read | yes |
- Passwords hashed with bcrypt
- JWT authentication with middleware
- Protected routes for sensitive actions
- Input validation on backend
- Environment variables for sensitive keys
- CORS configuration for frontend only
- Use Postman or Insomnia to test endpoints
- Use Postman or Insomnia to test endpoints
Contributions are welcome! Please fork the repository and submit a pull request.
If this project helps you, consider starring the repository!