This repository contains the backend of the full-stack social media platform developed as part of the CodeAlpha Full Stack Development Internship (Task 2: Social Media Platform). It provides secure user authentication, Google Sign-In, JWT-based security, posts, comments, likes, follows, stories, and media upload support with MongoDB integration.
- Project Overview
- Core Objectives
- Tech Stack
- Project Structure
- Configuration
- Installation
- API Documentation
- Contact
- License
- Acknowledgments
- Built with Love
The CodeAlpha Social Media Platform Backend supports the frontend application by providing APIs for user authentication, Google Sign-In, creating and managing posts, comments, likes, follows, stories visible for 24 hours, and media uploads using Cloudinary. The backend uses Node.js, Express, and MongoDB, with JWT for secure authentication and role-based access control where necessary.
- Implement secure user authentication and Google Sign-In
- Enable creation, editing, and deletion of posts and comments
- Allow likes, follows, and story sharing (24-hour visibility)
- Provide media upload endpoints for avatars, cover images, and posts
- Support a scalable and maintainable backend architecture
- Runtime & Framework: Node.js + Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT + Google OAuth
- Media Storage: Cloudinary integration
- Testing & API: Postman / Thunder Client
- Development Tools: Git + GitHub, ESLint, Prettier
CodeAlpha_SocialmediaApp_Backend/
│
├── src/
│ ├── config/
│ │ ├── db.js
│ │ └── cloudinary.js
│ │
│ ├── models/
│ │ ├── userModel.js
│ │ ├── postModel.js
│ │ ├── commentModel.js
│ │ └── StoryModel.js
│ │
│ ├── controllers/
│ │ ├── auth/
│ │ │ ├── auth.register.js
│ │ │ ├── auth.login.js
│ │ │ ├── auth.logout.js
│ │ │ └── auth.google.js
│ │ │
│ │ ├── users/
│ │ │ ├── userProfile.controller.js
│ │ │ ├── userSettings.controller.js
│ │ │ └── follow.controller.js
│ │ │
│ │ ├── posts/
│ │ │ ├── post.controller.js
│ │ │ ├── uploadMedia.controller.js
│ │ │ ├── comment.controller.js
│ │ │ └── like.controller.js
│ │
│ ├── services/
│ │ ├── authService.js
│ │ ├── googleAuthService.js
│ │ ├── userService.js
│ │ ├── postService.js
│ │ ├── commentService.js
│ │ ├── likeService.js
│ │ └── followService.js
│ │
│ ├── routes/
│ │ ├── authRoutes.js
│ │ ├── userRoutes.js
│ │ ├── postRoutes.js
│ │ ├── mediaRoutes.js
│ │ ├── followRoutes.js
│ │ ├── commentRoutes.js
│ │ └── likeRoutes.js
│ │
│ ├── middlewares/
│ │ ├── authMiddleware.js
│ │ ├── errorMiddleware.js
│ │ └── uploadMiddleware.js
│ │
│ ├── utils/
│ │ ├── generateToken.js
│ │ └── asyncHandler.js
│ │
│ ├── app.js
│ └── server.js
│
├── .env
├── .gitignore
├── package.json
├── package-lock.json
└── README.md
# Clone the repository
git clone https://github.com/Leta-Kasahun/CodeAlpha_SocialmediaApp_Backend.git
cd CodeAlpha_SocialmediaApp_Backend
# Install backend dependencies
npm install express mongoose dotenv bcrypt jsonwebtoken nodemailer cloudinary multer cors cookie-parser google-auth-library
# Development tools
npm install --save-dev nodemon eslint prettier
# Start development server
npm run devAll endpoints are prefixed with /api. Base URL (local development): http://localhost:7000
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
User registration |
| POST | /api/auth/login |
User login |
| POST | /api/auth/logout |
User logout |
| POST | /api/auth/forgot-password |
Request password reset |
| POST | /api/auth/reset-password |
Reset password |
| GET | /api/auth/google |
Google OAuth login |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/users/:userId/follow |
Follow or unfollow a user |
| GET | /api/users/:userId/followers |
Get list of followers |
| GET | /api/users/:userId/following |
Get list of following |
| GET | /api/users/profile/:userId |
Get user profile |
| PUT | /api/users/profile |
Update user profile info |
| POST | /api/users/avatar |
Upload user avatar |
| POST | /api/users/cover |
Upload cover image |
| POST | /api/users/story |
Upload 24-hour story |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/posts |
Create a new post |
| GET | /api/posts |
Get all posts |
| GET | /api/posts/:id |
Get a single post |
| PUT | /api/posts/:id |
Update a post |
| DELETE | /api/posts/:id |
Delete a post |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/comments/:postId |
Add comment to a post |
| GET | /api/comments/post/:postId |
Get all comments for a post |
| GET | /api/comments/:commentId/replies |
Get replies to a comment |
| DELETE | /api/comments/:commentId |
Delete a comment |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/likes/post/:postId |
Like or unlike a post |
| POST | /api/likes/comment/:commentId |
Like or unlike a comment |
| GET | /api/likes/post/:postId |
Get all likes for a post |
| GET | /api/likes/comment/:commentId |
Get all likes for a comment |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/media/upload |
Upload media file (image/video) |
All endpoints support JSON request/response format.
Use Postman, Thunder Client, or similar API tools to test endpoints locally athttp://localhost:7000/api.
Leta Kasahun
💌 Email: letakasahun77@gmail.com
🐦 Twitter: @LKashun
- CodeAlpha for the internship opportunity and guidance
- Mentors and peers for continuous support
- Open-source community for libraries and tools used in this project
- Cloudinary for media handling
- MongoDB Atlas for database services
Crafted with ❤️ by Leta Kasahun for the CodeAlpha Full Stack Development Internship.
This project demonstrates practical full-stack development skills in a social media platform.