Giter VIP home page Giter VIP logo

prayag2003 / tweet-tube-backend Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 138 KB

Production Grade Backend. Tweet-Tube is a platform where users can register, upload videos, and interact with other users' content.

JavaScript 99.62% Dockerfile 0.38%
backend data-modeling express middleware mongodb mongoose multer nodejs cloudinary cloudinary-integration aggregation-pipleline solid-principles

tweet-tube-backend's Introduction

Tweet-Tube Backend

Introduction

This repository contains the backend code for the Tweet-Tube project. Tweet-Tube is a platform where users can register, upload videos, and interact with other users' content.

Models

Table of Contents

Installation

To set up the project locally, follow these steps:

  1. Clone the repository:

      git clone https://github.com/your-username/tweet-tube-backend.git
  2. Install dependencies:

        cd tweet-tube-backend
        npm install
  3. Create a .env file in the root directory and add the following environment variables:

      PORT=8000
      MONGODB_URI=
      CORS_ORIGIN=*
    
      ACCESS_TOKEN_SECRET=
      ACCESS_TOKEN_EXPIRY=1d
    
      REFRESH_TOKEN_SECRET=
      REFRESH_TOKEN_EXPIRY=10d
    
      CLOUDINARY_CLOUD_NAME=
      CLOUDINARY_API_KEY=
      CLOUDINARY_API_SECRET=
  4. Start the server:

      npm run dev

Project Structure

The project follows a modular structure, dividing code into separate files for better organization and maintainability. Here's a brief overview of the main files and directories:

  • index.js: Entry point of the application. Sets up environment variables, connects to the database, and starts the server.
  • app.js: Configures Express application, sets up middleware, and defines routes.
  • db/conn.js: Connects to MongoDB using Mongoose.
  • routes/: Directory containing route files for different API endpoints.
  • controllers/: Contains controller functions to handle business logic.
  • middleware/: Directory for custom middleware functions such as authentication and file upload handling.
  • utils/: Utility functions and custom error classes.

Middleware

The project utilizes several middleware functions for handling various tasks such as CORS, JSON parsing, cookie parsing, authentication, and file upload handling. Notable middleware includes:

  • auth.middleware.js: Middleware for verifying JWT tokens and authenticating users.
  • multer.middleware.js: Middleware for handling file uploads using Multer.

Controllers

User Controller Functions Overview

Here's a brief overview of each function in the user.controller.js file along with an explanation of any standard development practices or SOLID Principles applied:

  • registerUser: Handles user registration, input validation, image upload, and database entry.
  • loginUser: Manages user login, credential validation, token generation, and secure cookie handling.
  • logoutUser: Logs out the user by clearing tokens and cookies.
  • refreshAccessToken: Refreshes user access tokens securely via cookies.
  • changeCurrentPassword: Allows users to change passwords securely.
  • getCurrentUser: Retrieves the current user's details.
  • updateAccountDetails: Updates user account details securely.
  • updateAvatar: Updates user avatar image securely.
  • updateCoverImage: Updates user cover image securely.
  • getUserChannelProfile: Fetches user channel profile with subscriber details.
  • getWatchHistory: Retrieves user watch history with video details.

Development Practices and SOLID Principles:

  • Separation of Concerns: Functions are focused on specific user-related operations.
  • Single Responsibility Principle (SRP): Each function has a single responsibility.
  • Validation: Input validation is implemented to ensure data integrity and security.
  • Error Handling: Errors are managed using custom error classes and middleware.
  • Modular Design: Functions are organized into a single file for modularity.
  • Asynchronous Handling: Asynchronous operations are handled using async/await.

Error Handling

Error handling is implemented using custom error classes and middleware. Notable files include:

  • ApiError.js: Custom error class for handling API errors with customizable status codes and messages.
  • utils/asyncHandler.js: Middleware to handle asynchronous functions and catch errors.

Routes

API routes are defined in separate files inside the routes/ directory. Notable routes include:

  • user.router.js: Defines routes for user-related operations such as registration, login, profile updates, and password management.

Contributing

Contributions to the project are welcome. To contribute, fork the repository, make your changes, and submit a pull request with a detailed description of the changes.

tweet-tube-backend's People

Contributors

prayag2003 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.