Skip to content

This project is a backend application for a social network platform where users can share their thoughts, react to friends' thoughts, and create a friend list. Utilizing MongoDB, an Express.js server, and the Mongoose ODM, it's designed to handle large amounts of unstructured data efficiently.

License

Notifications You must be signed in to change notification settings

naturuplift/SocialNetworkAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Social Network API


Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports Node.js and Deno (alpha) MongoDB is a general purpose, document-based, distributed NoSQL database built for web application developers in the cloud era. It’s one of the most popular database choices for modern applications. MongoDB Compass is an interactive tool for querying, optimizing, and analyzing MongoDB data. express-session - A session middleware for Express.js, used for handling user sessions Node.js - A JavaScript runtime built on Chrome's V8 JavaScript engine, used for building fast and scalable network applications Express.js - A minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications dotenv NPM JavaScript - ES6 GitHub (for repository hosting and project management) - Provides hosting for software development and version control using Git Git (for version control) - A free and open-source distributed version control system University of New Brunswick The MIT License


Description

This project is a backend application for a social network platform where users can share their thoughts, react to friends' thoughts, and create a friend list. Utilizing MongoDB, an Express.js server, and the Mongoose ODM, it's designed to handle large amounts of unstructured data efficiently.

Table of Contents

Demo Video

Open Demo video of Social Network API

Features

The Social Network API is a backend application designed to power social networking features for web and mobile applications. This API provides robust support for a wide range of social networking functionalities, including:

  • User Management: Users can create accounts, update their information, and delete their accounts. Each user's profile includes a unique username, email address, and the ability to have friends and share thoughts.

  • Thoughts Sharing: Users can post thoughts, allowing them to share text-based content with others. Each thought includes the content of the thought, the creator's username, and timestamps for when the thought was created.

  • Reactions to Thoughts: Other users can react to thoughts, enabling a dynamic and interactive experience. Reactions are nested within thoughts and include a reaction body, the reacting user's username, and a timestamp.

  • Friend Lists: Users can maintain a friend list within the network. The API supports adding and removing friends, enabling users to connect and interact with others.

  • Real-time Updates: The application is designed to support real-time updates, ensuring that users can see the latest thoughts and reactions as they happen.

  • Scalable and Flexible: Built on MongoDB, a NoSQL database, the API is designed to efficiently handle large volumes of unstructured data. This makes it scalable and adaptable to the needs of growing social networks.

  • Timestamp Formatting: Utilizes customized timestamp formatting to present dates and times in a user-friendly manner, adapted to the local timezone of the user.

Schema Virtuals

  • Friend Count: A virtual attribute on the User model that dynamically calculates the number of friends a user has.

  • Reaction Count: A virtual attribute on the Thought model that provides the count of reactions a thought has received.

Bonus Features

  • Cascading Deletes: When a user is deleted, all associated thoughts and reactions are automatically removed from the database, ensuring data integrity and cleanliness.

Installation

  1. Ensure you have Node.js and MongoDB installed on your machine.

  2. Clone the repository to your local machine:

git clone https://github.com/naturuplift/SocialNetworkAPI.git
  1. Navigate to the project directory and install dependencies:
cd social-network-api
npm install
  1. Seed the database:
npm run seed
  1. Start the server:
npm start

Usage

Once the server is running, you can use an API client like Insomnia to test the API routes.

  • /api/users routes for users display data in a formatted JSON.

image

  • /api/thoughts routes for thoughts display data in a formatted JSON.

image

  • /api/thoughts/:thoughtId/reactions routes for reactions display data in a formatted JSON.

image

  • /api/users/:userId/friends/:friendId routes for friends display data in a formatted JSON.

image

Application Functionality

Below are sample screenshots showcasing the application routes functionality.

GET Find All Users:

image

GET Find a User (by Id):

image

GET Find All Thoughts:

image

GET Find Thoughts (by Id):

image

POST CREATE a New User:

image

POST CREATE a Thought:

image

POST CREATE Reaction:

image

POST Add Friend:

image

PUT Update a User (by Id):

image

PUT Update a Thought (by Id):

image

DELETE Delete a User (by Id):

image

DELETE Delete a Thought (by Id):

image

DELETE Remove Reaction (by Id):

image

DELETE Remove Friend (by Id):

image

Database Models

User

  • username: Unique, required, trimmed string.
  • email: Unique, required string that must match a valid email address.
  • thoughts: Array of _id values referencing the Thought model.
  • friends: Array of _id values referencing the User model (self-reference).

Schema Settings

  • A virtual called friendCount retrieves the length of the user's friends array field on query.

Thought

  • thoughtText: Required string between 1 and 280 characters.
  • createdAt: Date with a default value to the current timestamp. A getter method formats the timestamp on query.
  • username: Required string indicating the user that created the thought.
  • reactions: Array of nested documents created with the reactionSchema.

Schema Settings

  • A virtual called reactionCount retrieves the length of the thought's reactions array field on query.

Reaction (SCHEMA ONLY)

  • reactionId: Uses Mongoose's ObjectId data type with a default value set to a new ObjectId. reactionBody: Required string with a 280 character maximum. username: Required string. createdAt: Date with a default value to the current timestamp. A getter method formats the timestamp on query.

API Routes

/api/users

  • GET all users
  • GET a single user by its _id and populated thought and friend data
  • POST a new user
  • PUT to update a user by its _id
  • DELETE to remove user by its _id

/api/users/:userId/friends/:friendId

  • POST to add a new friend to a user's friend list
  • DELETE to remove a friend from a user's friend list

/api/thoughts

  • GET to get all thoughts
  • GET to get a single thought by its _id
  • POST to create a new thought
  • PUT to update a thought by its _id
  • DELETE to remove a thought by its _id

/api/thoughts/:thoughtId/reactions

  • POST to create a reaction stored in a single thought's reactions array field
  • DELETE to pull and remove a reaction by the reaction's reactionId value

Structure

Your directory may have the following structure:

SocialNetworkAPI/
├── config/
   └── connection.js          # Configures Mongoose connection to MongoDB
├── controllers/
   ├── thoughtController.js   # Contains controllers for thought operations
   └── userController.js      # Contains controllers for user operations
├── models/
   ├── Thought.js             # Defines the Thought model and schema
   ├── User.js                # Defines the User model and schema
   └── Reaction.js            # Defines the Reaction schema (used within Thought)
├── routes/
   ├── api/
      ├── thoughtRoutes.js   # Routes for thought operations
      ├── userRoutes.js      # Routes for user operations
      └── index.js           # Aggregates and exports API routes
   └── index.js               # Central entry point for routing
├── seeds/
   └── seed.js                # Contains seed data for the database
├── .gitignore                 # Specifies intentionally untracked files to ignore
├── package.json               # Defines project and its dependencies
├── README.md                  # Project description and guidelines
└── server.js  

Contributing

To contribute to this project, please create a pull request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

This project is a backend application for a social network platform where users can share their thoughts, react to friends' thoughts, and create a friend list. Utilizing MongoDB, an Express.js server, and the Mongoose ODM, it's designed to handle large amounts of unstructured data efficiently.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published