Code Monkey home page Code Monkey logo

nidhish-nayak / trendz Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 508 KB

Trendz is a full-stack app with features like AI-moderation, realtime, infinite-scroll, CI/CD, Auth, image-upload, posts, comments, likes, follows, uploads, stories, profiles, and more.

Home Page: https://trend-z.vercel.app/

License: MIT License

TypeScript 68.81% JavaScript 0.90% HTML 0.86% SCSS 29.43%
jwt react-router-v6 context-api typescript tanstack-query zod file-upload auth express node postgresql react s3-bucket ai supabase infinite-scroll ci-cd-pipeline

trendz's Introduction

Trendz

The application is complete and production ready

Open in GitHub Codespaces

About the Project

Trendz is a full-stack app with features like AI-moderation, realtime, infinite-scroll, Auth, image-upload, posts, comments, likes, follows, uploads, stories, profiles and more. This project is built using Typescript, React, Express, React Query, PostgreSQL and so on. We will be implementing the features with Context APIs to maintain simplicity as much as possible so that anyone can understand the process.

preview

vercel ts

GitHub Language Count GitHub Top Language GitHub Issues GitHub Closed Issues GitHub Last Commit GitHub Commit Activity (Year)

How to navigate the Project ?

The project consists of two folders client and server. Both are responsible for handling frontend and backend features respectively. Below are the details on how the client and server folders are structured to better understand the architecture of the application.

Frontend folder structure:

Here's an overview of the project's frontend folder structure:

πŸ“‚client/
    β”œβ”€β”€ public/             # Public assets and HTML template
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ assets/         # Assets / files used in the application
    β”‚   β”œβ”€β”€ assets/         # All configs for endpoints
    β”‚   β”œβ”€β”€ components/     # Reusable React components
    β”‚   β”œβ”€β”€ hooks/          # Reusable custom hooks
    β”‚   β”œβ”€β”€ context/        # React context apis
    |   |   |
    |   β”‚   β”œβ”€β”€ darkModeContext.tsx   # Handles toggle for dark mode
    |   β”‚   └── authContext.tsx       # Handles authentication (Login)
    |   |
    β”‚   β”œβ”€β”€ pages/          # Top-level application pages
    |   β”œβ”€β”€ types/          # Custom and global types defined
    β”‚   β”œβ”€β”€ utils/          # Utility functions and constants
    β”‚   β”œβ”€β”€ App.css         # Styles for App.tsx
    β”‚   β”œβ”€β”€ App.tsx         # Main client-side application file
    β”‚   β”œβ”€β”€ index.css       # Global css file
    β”‚   └── main.tsx        # All Routes & protected routes are handled here
    └── index.html          # Root html file
    └── package.json        # Dependencies for the client-side
    └── tsconfig.json       # Typescript configuration
    └── ...

Backend folder structure:

Here's an overview of the project's backend folder structure:

πŸ“‚server/
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ __tests__/      # All test cases
    β”‚   β”œβ”€β”€ config/         # All endpoint configurations
    β”‚   β”œβ”€β”€ controllers/    # Controllers consists of logic for routes
    β”‚   β”œβ”€β”€ db/             # Database configuration and setup
    β”‚   β”œβ”€β”€ middlewares/    # Middleware configs and setup
    β”‚   β”œβ”€β”€ routes/         # Routes for all features
    β”‚   β”œβ”€β”€ utils/          # Utility files
    β”‚   β”œβ”€β”€ validations/    # Zod validations
    β”‚   └── main.ts         # root file for server
    β”‚
    └── .eslintrc           # eslint config
    └── .prettierrc         # prettier config
    └── .env                # environment variables
    └── package.json        # Dependencies for the server-side
    └── tsconfig.json       # Typescript configuration
    └── ...

Features ✨

  • User Authentication: Users can create accounts, log in, and securely access their personalized profiles. We have used JWT for user authentication feature.
  • Infinite-scroll: Using react-query, user will now be able to experience infinite scroll features on posts.
  • Responsive Design: Enjoy a consistent and visually appealing experience across various devices.
  • User Profile: User can manage their profile info and edit them.
  • Upload Posts: User can post their thoughts or memories with or without images attached. File upload managed through AWS S3 and Cloudfront.
  • Comments: User can comment on the posts made by their followers.
  • Likes: User can like any post.
  • Activities: Get realtime activity of users posting or commenting.
  • Moderator: This uses an AI-powered moderator to ban users related on content.
  • Follow: Users can follow others to view their posts.
  • Stories: Add weekly stories to your profile for other users to view. This will be auto-deleted post 1 week.
  • Image Upload: Images are supported upto 20MB for any uploads.
  • Ban System: This is directly connected to moderator. Once detected user will be added to banned records.
  • Realtime: This feature displays all the online friends available at the moment in realtime.

Installation πŸ’»

To make the whole application run locally on your computer, you have to run both client and server separately in the terminal simultaneously. You will also need to setup your own AWS S3, .env file and configure the endpoints in both client and server using config/config.ts file.

Project setup:

Follow the steps below to setup the project locally:

  1. Clone the repository:

    git clone https://github.com/nidhish-nayak/trendz.git
  2. Navigate to the project directory:

    cd trendz

You can use npm / yarn / pnpm. Just replace pnpm with npm or yarn for all the commands.

Frontend setup:

To run the client locally, follow the below steps:

  1. Navigate to the client directory:

    cd client
  2. Install the dependencies using pnpm / npm (make sure you have pnpm installed):

    pnpm install
  3. Start the development server for frontend:

    pnpm start
  4. Open your browser and visit http://localhost:5173/ to access the frontend of LinkX application.

Backend setup:

Setting up the server is similar to frontend setup given above. Follow the below steps:

  1. Navigate to the api directory:

    cd server
  2. Install the dependencies using npm:

    npm install
  3. Start the development server for backend:

    npm start
  4. Open your browser and visit http://localhost:3000/ to access the backend of LinkX application.

Note Make sure both client and server are running locally for the fullstack features to work.

Testing:

Testing your code if it runs as expected can be done using the below command for server. Integration and Unit tests cover almost all the functionalities that are critical for the application. Make sure to follow .env.example file to get all the test cases working.

  1. Navigate to server:

    cd server
  2. Run all test cases:

    npm test
  3. Run individual test cases based on the describe names:

    jest -t "<Any test case describe title here>"

Technologies Used πŸ”§

Frontend technologies:

  • Vite: Latest version of Vite is used for react frontend.
  • Typescript: TypeScript checks a program for errors before execution, ensures better developer experience.
  • React: JavaScript library for building user interfaces.
  • Axios: Promise-based HTTP client for making API requests.
  • SCSS: Sass is a preprocessor scripting language that is interpreted or compiled into Cascading Style Sheets.
  • React Router: react-router-dom V6 is used for the application routing.
  • React Query: Also knows as Tanstack query for better data fetching.
  • Context-API: Manage states across components with ease.
  • Themes: Both dark and light themes are included in the application using SCSS.

Backend technologies:

  • NodeJS: NodeJS for backend is a pretty popular choice.
  • Typescript: TypeScript checks a program for errors before execution.
  • Zod: Zod for consistent input validation, data structuring, and error handling.
  • ExpressJS: NodeJS framework for backend.
  • JWT: Authentication management.
  • Multer & AWS S3: For file upload and storage.
  • AWS Cloudfront: CDN for hosting images across the globe.
  • PostgreSQL: Supabase is used to manage our postgres database.
  • AWS Lambda: For running jobs on backend or DB cleanups.
  • AWS S3 Bucket: For storing images and connecting them to cloudfront.
  • AI Moderator: AI detects any unsafe images uploaded and bans the user based on results.
  • Jest: For complete coverage of integration and unit test cases.
  • Realtime: Manages realtime updates using websockets.

Contributing 🀝

We welcome open-source contributions to Trendz project ! If you would like to contribute, please follow the below steps:

  1. Fork the repository.
  2. Create a new branch for your feature/fix: git checkout -b feature-name.
  3. Make your changes and commit them: git commit -m 'Add some feature'.
  4. Push the changes to your forked repository: git push origin feature-name.
  5. Open a pull request to the main repository's main branch.

Contributors

License πŸ“

This project is licensed under the MIT License. Feel free to use, modify, and distribute the code as per the terms of the license.

Contact πŸ’¬

If you have any questions, suggestions, or feedback, please don't hesitate to reach out. You can contact the project maintainer at [email protected].


Made with 😎 by Nidhish Nayak.

trendz's People

Contributors

nidhish-nayak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

trendz's Issues

Implementing Redis or AWS SQS for Queuing moderator middleware

Why replace existing moderator feature with Redis or AWS SQS?

  • Currently application utilizes an asynchronous process which runs on a separate thread inside node.
  • This usually involves very ugly method where the async process runs in background and response is sent to the client regardless of the main process which might have already sent a response in the first place.
  • This usually causes client to receive more than one response for a HTTP request, which is not recommended.
  • After analyzing the scenario, first thing that comes up to mind is implementing a queue system to handle moderator middleware.
  • Most suited for the above scenario would be using Redis or AWS SQS.
  • This allows us to run a queue process separately and allows client to receive a separate response from moderator middleware.

Why is running moderator on a separate process required?

  • Moderator API used in the application uses AI to mark the image safe or unsafe.
  • It has a general latency of 3 seconds which impacts the user experience. (Loading screen on post takes > 3s).

What might be the preferred technology used here?

  • AWS SQS is the best choice since its cost effective & easy to implement. But hol-up.... There is a problem.
  • While it is easy to implement, not much can be learned while doing it this way.
  • Hence we are going to choose Redis, so that we get experience learning it.
  • We can also use BullMQ for client, but deciding not to. Since we can learn using redis client it provides with it.

Conclusion

  • New github branch must be created named "redis".
  • This branch will be developed separately and only merged once development is completed.

Documentation Update Needed

Many parts of the README.md is on previous version and the details need to be updated as per implementation of latest code changes.

User details are updated to another person's profile

The functionality stops working due to wrong cookie auth since user details from local storage are updated to something else.
This only occurs when user manually enters the /profile/{number} or refreshes the page on other's profile.

Migrate from supabase createClient to postgres direct connect

Currently the code base contains some queries which are written using supabase's API createClient(). This uses supabaseUrl and supabase ANON key. The second type of connection implemented recently contains direct connect using postgres() where user can write complex JOIN SQL statements.

The code base needs to be migrated from createClient() to postgres() method for all queries to maintain consistency. Otherwise it will be a pain to maintain in the future. This update will be completely backend related and will not require any frontend changes.

Points to be noted:

  • Maintain secure connection using pooling with postgres()
  • Implement various security measures for SQL injection and spams.

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.