Code Monkey home page Code Monkey logo

twitter_backend's Introduction

Twitify ๐Ÿ“ฑโœจ

Welcome to Twitify, a social media application built on a Monolith architecture! In Twitify, users can post tweets with images, comment on tweets, reply to comments, like tweets or comments, and filter tweets by hashtags.

Features ๐ŸŒŸ

  • Post tweets with images ๐Ÿ“ธ
  • Comment on tweets ๐Ÿ’ฌ
  • Reply to comments ๐Ÿ—จ๏ธ
  • Like tweets and comments โค๏ธ
  • Filter tweets by hashtags ๐Ÿ”

Getting Started ๐Ÿš€

Prerequisites ๐Ÿ“‹

  • Node.js
  • MongoDB
  • Cloudinary account for media storage

Installation ๐Ÿ”ง

  1. Clone the repository:
    git clone https://github.com/yourusername/twitify.git
    cd twitify
    
  2. Install dependencies:
    npm install
    
  3. Environment Variables:
    • Create a .env file in the root directory and add the following:
      DATABASE_URL=mongodb://127.0.0.1:27017/[your database name]
      PORT=3000
      JWT_SECRET=[Your JWT Secret]
      CLOUD_NAME=[Your Cloudinary Cloud Name]
      API_KEY=[Your Cloudinary API Key]
      API_SECRET=[Your Cloudinary API Secret]
      MAIL_HOST=[Your Mail Host]
      MAIL_USER=[Your Mail User]
      MAIL_PASS=[Your Mail Password]  
    
  4. Run the Server:
    npm start
    

API Endpoints ๐Ÿ“ก

Authentication ๐Ÿ”‘

Sign Up

  • POST /api/v1/signup
    • Create a new user account.
    • Request Body:
      {
        "email": "[email protected]",
        "password": "yourpassword",
        "name": "Your Name"
      }

Login

  • POST /api/v1/login
    • Log in with existing credentials.
    • Request Body:
      {
        "email": "[email protected]",
        "password": "yourpassword"
      }
    • You will get a Bearer Token in response, whose expiry time is 1 hr
    • Use this token to authenticate yourself to make tweets, comments.

Tweets ๐Ÿฆ

Create Tweet

  • POST /api/v1/tweets
    • Create a new tweet (requires authentication).
    • Request Body:
      {
        "content": "Your tweet",
        "image": "image_url"
      }

Get All Tweets

  • GET /api/v1/tweets
    • You have to pass tweetID in params
    • Retrieve all tweets.

Comments ๐Ÿ’ฌ

Create Comment

  • POST /api/v1/comments
    • Create a new comment on a tweet (requires authentication).
    • Request Body:
      {
        "content": "Your comment",
      }
    • Pass modelId(tweet_or_comment_id) and modelType(Tweet/Comment) in query params

Likes โค๏ธ

Toggle Like

  • POST /api/v1/likes/toggle
    • Toggle like on a tweet or comment.
    • Request Body:
      {
        "likeableId": "tweet_or_comment_id",
        "onModel": "Tweet/Comment"
      }

Models ๐Ÿ—‚

User ๐Ÿง‘โ€๐Ÿ’ป

Field Type Description
email String, required, unique User's email address.
password String, required User's password (hashed).
name String, required User's name.
timestamps Boolean Automatically managed timestamps.

Tweet ๐Ÿฆ

Field Type Description
content String, required, max 250 Content of the tweet.
user ObjectId, ref: 'User', required User who posted the tweet.
likes Array of ObjectId, ref: 'Like' Likes received by the tweet.
comments Array of ObjectId, ref: 'Comment' Comments posted on the tweet.
image String URL of the image attached to the tweet.
timestamps Boolean Automatically managed timestamps.

Comment ๐Ÿ’ฌ

Field Type Description
content String, required Content of the comment.
userId ObjectId, ref: 'User', required User who posted the comment.
onModel String, enum: ['Tweet', 'Comment'], required Type of parent entity (tweet or comment).
commentable ObjectId, refPath: 'onModel', required ID of the parent entity (tweet or comment).
comments Array of ObjectId, ref: 'Comment' Replies to the comment.
timestamps Boolean Automatically managed timestamps.

Like โค๏ธ

Field Type Description
onModel String, enum: ['Tweet', 'Comment'], required Type of entity being liked (tweet or comment).
likeable ObjectId, refPath: 'onModel', required ID of the entity being liked.
user ObjectId, ref: 'User', required User who liked the entity.
timestamps Boolean Automatically managed timestamps.

๐Ÿ“ฌ Contact

Feel free to reach out to me at [email protected] or connect with me on LinkedIn.

Thank you for checking out Twitify! If you have any feedback or suggestions, feel free to open an issue or make a pull request.

Happy coding! ๐Ÿ˜Š

twitter_backend's People

Contributors

himanshu07-debug 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.