Skip to content

Leta-Kasahun/CodeAlpha_SocialMediaApp_Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌐 CodeAlpha Social Media Platform - Backend

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.


📋 Table of Contents


🎯 Project Overview

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.


🎯 Core Objectives

  • 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

🛠️ Tech Stack

  • 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

📁 Project Structure

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

🗝️ Configuration & Installation

# 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 dev

📚 API Documentation

All endpoints are prefixed with /api. Base URL (local development): http://localhost:7000


Authentication

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

Users

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

Posts

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

Comments

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

Likes

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

Media

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 at http://localhost:7000/api.


📞 Contact

Project Developer

Leta Kasahun
💌 Email: letakasahun77@gmail.com
🐦 Twitter: @LKashun


🙏 Acknowledgments

  • 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

💝 Built with Love

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.

About

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 includes user authentication, Google login, JWT-based security, posts, comments, likes, follows, Cloudinary image uploads, and MongoDB integration.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors