MQ3120-2023 / group-project-wednesday-3pm-1

group-project-wednesday-3pm-1 created by GitHub Classroom
0 stars 1 forks source link

group-project-wednesday-3pm-1

group-project-wednesday-3pm-1 created by GitHub Classroom Calum, Ryan, Mifta, Ahmed

Project Description

Our project ReedMi is a user-focused discussion platform similar to Reddit that aims to create a network for 'geeky' users to talk and gain knowledge about tech-related topics. ReedMi will help create this network by offering a forum for tech enthusiasts to propose topics and publish content. All users can access these various postings and participate by leaving comments likes or dislikes. Users can search for topics using the side panel filter, which will lead them to thier favorite posts. Users can create new posts using the Navigation bar to add to the forum. Users can fetch news from a third party API through 'Tech News'. ReedMi uses MongoDB, as the datastore, more about this is found later in this document.

Our Vision for the future

If the project were to advance, the next phase of development would focus on augmenting the interactivity and user control within the ReedMi platform. This would include implementing functionality for users to express their opinions more dynamically by introducing the ability to like or dislike comments made by other users. This feature would add a layer of engagement and allow for a more nuanced reflection of user sentiment within discussions. Moreover, we would empower users with the ability to manage their digital footprint on the platform by granting them the capability to delete their own posts and any comments they have made. This step is critical for ensuring that users feel a sense of ownership and responsibility over their content and can adapt their contributions as their perspectives evolve or to correct any errors post-publication. Finally we would've enabled the reply system where users can engage with other users under posts.

Source Code Guide

AppRoutes.js

Route Definitions

AuthenticatedRoute.js:

This component acts as a protective wrapper around other components, ensuring that only authenticated users can access the wrapped content.

State Management

Functions

Effects and Data Fetching

Rendering

LoginPage.js: Login Page

This component provides a login interface for users.

State Management

Event Handlers

Rendering

Register.js: Registration Page

This component provides a registration interface for new users.

State Management

Event Handlers

Rendering

Navbar.js: Navigation Bar

This component provides navigation links across the application.

State Management

Effects and Data Fetching

Rendering

Home.js: Main Home Component

This component is the main page of the application. It displays a list of posts, along with a sidebar to filter the posts by topic.

State Management

Props

Effects

Rendering

Functionality

PostList.js: Displaying and Filtering Posts

This component renders a list of posts, allowing users to click on a post to navigate to its detailed view.

Props

State Management

Effects

Functionality

Rendering

Sidebar.js: Sidebar Component

This component displays a sidebar containing buttons for different topics and allows users to add new topics.

Props

State Management

Functionality

Rendering

SelectedPost.js: Selected Post View

This component is responsible for fetching and displaying a single post based on the postId parameter from the URL. Users can interact with the post by liking, disliking, or commenting.

State Management

Effects and Data Fetching

Interaction Handlers

Rendering

NewTopic.js:

NewPost.js: Creating a New Post Feature:

  1. User Interaction: The user enters information into the new post form on the front end, which includes a title, image, content, topic and optionally includes an image file.
  2. Form Submission: Upon submitting the form, the addPostToBackEnd function triggers, which prepares the form data to be sent to the express server. This function creates a FormData object containing the user's inputs and the image file, if provided.
  3. Making a POST Request to the Server: The front end sends the FormData to the server's /api/createNewPost endpoint via a POST request.
  4. Server Handling with Multer:
    • The server employs Multer as a middleware to handle the incoming file. Multer processes the file, storing it in the designated 'uploads' directory with a unique filename.
    • Alongside file handling, Multer makes the text fields available in req.body and the file information in req.file.
  5. Database Update:
    • New Post Creation: The server constructs a new post object with the received text data and generates an image URL using the stored file's path, if an image was uploaded.
    • Save Operation: This new post object is then saved to the database, which involves creating a new document in the posts collection.
  6. Server Response: The server sends back a JSON response containing the details of the newly created post to the front end.
  7. Frontend Update:
    • User Notification: The front end uses the server's response to display a success message, informing the user that the post has been added.
    • PostList Update: The list of posts is updated whenever a new post has been added successfully, by calling the fetchPosts() function.

TechNews.js & SingleArticle.js: TechNews Feature & Data Flow Documentation

The TechNews feature allows users to interact with a web application interface to request and display technology news articles. Here's the data flow detailed with state names and application behavior:

1. TechNews.js

2. User Interaction and Input

3. GET Request to the Backend Server in ./reedmi/server/controllers/api.js

5. GET Request to Third-party API

API Details: URL: https://newsapi.org/v2/everything Provides a list of news articles based on the supplied search parameters.

6. Receiving News Data from the Third-Party API

7. Frontend Data Handling

8. Display of Articles

9. Error Management

Use of MongoDB as our Data Store:

This part outlines how MongoDB is being used as the database for oue React application. It includes details on the initial setup, data ingestion, and all the schemas used in our database.

Initial Setup

Data Ingestion

Schemas Used: (Can be found at /reedmi/server/models)

Post Schema
User Schema

Holds user information:

Comment Schema

Represents comments on posts:

Reaction Schema

Tracks reactions to posts:

Topic Schema

Categorises posts:

Authentication and Security

ReedMi places an emphasis on user authentication and security. Here's how we've implemented these features:

Google Authentication:

OAuth 2.0: We use Google's OAuth 2.0 for user authentication. Passport.js: Passport.js, along with the GoogleStrategy, is used for authenticating users via Google. User Creation: On a user's first Google login, a new user profile is created using the email received from Google. A unique username is generated by appending a random four-digit number to the part of the email before '@'. Session Management: Passport.js serialises and deserialises user data to and from the session.

Local Authentication:

Username and Password: Users can also register and log in using a combination of username and email. Password Security: User passwords are hashed using bcrypt before being stored in the database. Passport.js: We use Passport.js with the LocalStrategy to authenticate users using a username and password. Authorisation Middleware:

ensureAuthenticated: This middleware function ensures that certain routes are protected and only accessible by authenticated users.

Logout:

Session Destruction: Upon logout, the user's session is destroyed and cookies are cleared, ensuring a secure logout. Cross-Origin Resource Sharing (CORS):

Security: Our application is configured to handle CORS, ensuring that only trusted domains have access to our APIs.

Authentication Routes

1. Google Authentication

GET /google

GET /google/callback

GET /oauth2/redirect/google

2. User Registration

POST /register

3. User Login

POST /login

4. User Logout

GET /logout

5. Fetch Current User

GET /current_user

6. Middleware: ensureAuthenticated

API Routes

1. Fetch All Posts

GET /api/posts

2. Fetch Single Post

GET /api/posts/:id

3. Comment on a Post

POST /api/posts/:postId/comment

4. React to a Post

POST /api/posts/:postId/reaction

5. Fetch Comments for a Post

GET /api/posts/:postId/comments

6. Create a New Post

POST /api/createNewPost

7. Fetch All Topics

GET /api/topics

8. Create a New Topic

POST /api/topics

9. Fetch Tech News

GET /api/techNews

Middleware

Summary of Main Roles

Mifta

Ryan

Calum

Ahmed:

Everyone:

Communications