|
| 1 | +# Backend API Project |
| 2 | + |
| 3 | +This repository contains the backend code for a **video-sharing and social media platform**. |
| 4 | +It is built with **Node.js, Express.js, and MongoDB**, and provides **RESTful APIs** for user management, video uploads, comments, likes, playlists, subscriptions, tweets, and email validation. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +- **User Management** – Registration, authentication (JWT), profile management |
| 11 | +- **Video Uploads** – Upload, stream, and manage videos (**Multer + Cloudinary**) |
| 12 | +- **Comments & Likes** – Add comments and likes to videos |
| 13 | +- **Playlists** – Create and manage playlists |
| 14 | +- **Subscriptions** – Subscribe/unsubscribe to channels |
| 15 | +- **Tweets** – Post and manage short tweets |
| 16 | +- **File Uploads** – Handled via Multer middleware |
| 17 | +- **Cloud Storage** – Integrated with Cloudinary |
| 18 | +- **Email Validation** – Validates email addresses using [Abstract API](https://mailmeteor.com/tools/email-reputation) |
| 19 | + ```js |
| 20 | + https://emailreputation.abstractapi.com/v1/?api_key=${ABSTRACT_API_KEY}&email=${email} |
| 21 | + ``` |
| 22 | +- **Error Handling** – Custom ApiError and ApiResponse classes |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## Project Structure |
| 27 | + |
| 28 | +``` |
| 29 | +src/ |
| 30 | + app.js # Main Express app setup |
| 31 | + constants.js # Application constants |
| 32 | + index.js # Entry point |
| 33 | + controllers/ # Route controllers for each feature |
| 34 | + comment.controller.js |
| 35 | + like.controller.js |
| 36 | + playlist.controller.js |
| 37 | + subscription.controller.js |
| 38 | + tweet.controller.js |
| 39 | + user.controller.js |
| 40 | + video.controller.js |
| 41 | + db/ |
| 42 | + index.js # Database connection setup |
| 43 | + middlewares/ # Custom Express middlewares |
| 44 | + auth.middleware.js |
| 45 | + emailValidator.middleware.js |
| 46 | + multer.middleware.js |
| 47 | + models/ # Mongoose models for MongoDB |
| 48 | + comment.model.js |
| 49 | + like.model.js |
| 50 | + playlist.model.js |
| 51 | + subscription.model.js |
| 52 | + tweet.model.js |
| 53 | + user.model.js |
| 54 | + video.model.js |
| 55 | + routes/ # API route definitions |
| 56 | + comment.routes.js |
| 57 | + like.routes.js |
| 58 | + playlist.routes.js |
| 59 | + subscription.routes.js |
| 60 | + tweet.routes.js |
| 61 | + user.routes.js |
| 62 | + video.routes.js |
| 63 | + utils/ # Utility classes and functions |
| 64 | + ApiError.js |
| 65 | + ApiResponse.js |
| 66 | + asyncHandler.js |
| 67 | + Cloudinary.js |
| 68 | +public/ |
| 69 | + temp/ # Temporary files (e.g., uploads) |
| 70 | +``` |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Technologies Used |
| 75 | + |
| 76 | +- **Node.js** (JavaScript runtime) |
| 77 | +- **Express.js** (backend framework) |
| 78 | +- **MongoDB + Mongoose** (database & ORM) |
| 79 | +- **Multer** (file upload handling) |
| 80 | +- **Cloudinary** (media storage) |
| 81 | +- **JWT** (authentication & authorization) |
| 82 | +- **Bcrypt** (password hashing) |
| 83 | +- **Dotenv** (environment variable management) |
| 84 | +- **Nodemon** (development server auto-restart) |
| 85 | +- **mailmeteor** (email validation) |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## Installation & Setup |
| 90 | + |
| 91 | +### 1. Clone the repository |
| 92 | + |
| 93 | +```sh |
| 94 | +git clone https://github.com/rahul-vyas-dev/social-media-Backend-Project |
| 95 | +cd social-media-Backend-Project |
| 96 | +``` |
| 97 | + |
| 98 | +### 2. Install dependencies |
| 99 | + |
| 100 | +```sh |
| 101 | +npm install |
| 102 | +``` |
| 103 | + |
| 104 | +> You don’t need to run `npm init` since this project already includes a `package.json` with `"type": "module"` set. |
| 105 | +
|
| 106 | +### 3. Environment Configuration |
| 107 | + |
| 108 | +You must create a `.env` file in the root directory. |
| 109 | +A sample configuration is provided in **`.env.sample`**. |
| 110 | + |
| 111 | +### 4. Run the server |
| 112 | + |
| 113 | +Development mode (auto-reload with nodemon): |
| 114 | + |
| 115 | +```sh |
| 116 | +npm run dev |
| 117 | +``` |
| 118 | + |
| 119 | +Production mode: |
| 120 | + |
| 121 | +```sh |
| 122 | +node src/index.js |
| 123 | +``` |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## API Endpoints |
| 128 | + |
| 129 | +**Base URL:** `http://localhost:5000/api/v1` |
| 130 | + |
| 131 | +| Endpoint | Description | |
| 132 | +| ------------------------ | ------------------------------------------ | |
| 133 | +| `/api/v1/users` | User operations (register, login, profile) | |
| 134 | +| `/api/v1/videos` | Video upload & management | |
| 135 | +| `/api/v1/comments` | Comment operations | |
| 136 | +| `/api/v1/likes` | Like/unlike videos | |
| 137 | +| `/api/v1/playlists` | Playlist CRUD | |
| 138 | +| `/api/v1/subscriptions` | Subscribe/unsubscribe users | |
| 139 | +| `/api/v1/tweets` | Tweet CRUD | |
| 140 | +| `/api/v1/email/validate` | Validate email addresses | |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +## Development Scripts |
| 145 | + |
| 146 | +From `package.json`: |
| 147 | + |
| 148 | +```sh |
| 149 | +npm run dev # Start backend in development mode with nodemon |
| 150 | +npm start # Start normally with Node.js (if added) |
| 151 | +``` |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## Contributing |
| 156 | + |
| 157 | +1. Fork the repo |
| 158 | +2. Create a new branch (`feature/your-feature`) |
| 159 | +3. Commit your changes |
| 160 | +4. Push to your fork |
| 161 | +5. Create a Pull Request |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## License |
| 166 | + |
| 167 | +This project is licensed under the **MIT License**. |
| 168 | + |
| 169 | +--- |
| 170 | + |
| 171 | +## Quick Start |
| 172 | + |
| 173 | +Now anyone can: |
| 174 | + |
| 175 | +1. **Clone** → `git clone` |
| 176 | +2. **Install** → `npm install` |
| 177 | +3. **Configure** → `.env` (check `.env.sample` for reference) |
| 178 | +4. **Run** → `npm run dev` or `node src/index.js` |
| 179 | + |
| 180 | +### Developer Notes |
| 181 | + |
| 182 | +This project took me a good amount of time and effort to build. During development, I: |
| 183 | + |
| 184 | +- Carefully structured the backend from scratch. |
| 185 | +- Implemented and tested **every route** one by one. |
| 186 | +- Learned a lot about Node.js, Express, MongoDB, and integrations like Cloudinary and Abstract API. |
| 187 | +- Focused on **clean error handling** and modular code organization. |
| 188 | + |
| 189 | +I’m proud of the learning journey this project represents |
0 commit comments