How to create followers/following functionality in Strapi

Hey everyone, so I am primarily a frontend dev, I am planning to do a social media app (similar to instagram) and I am using Strapi in the backend to create API’s.

So my question is, I wanted to create a followers/following type of functionality and I’m stuck on how to implement the relationships and stuffs! So can someone please explain me how to do it

Check out youtubes about basic strapi. When you start new strapi you basically have almost all you need. You have collection type “users” all you have to do is add new relation back to “users” and select one-to-many/relations. You do that 2 times ones for followers once for following.

Firstly, you’ll need two tables, say ‘Followers’ and ‘Following’. Both tables will have ‘UserID’ and ‘FollowerID’ or ‘FollowingID’ columns. When a user follows another, you insert a row into each table to create the relationship.

For real-time functionality, consider implementing a socket or a pub/sub pattern. This will make it easier to notify users instantly when someone follows them.

If you want to automatically boost the visibility of posts to new followers, you could also consider integrating a feature like auto-likes, similar to how you can Buy Tik Tok auto likes. By automatically liking new posts, you could drive more engagement and make the platform more appealing for your users.

User Model:
Ensure you have a user model in Strapi to represent users. If you don’t have one, you may need to create it. You can include fields like username, email, and any other relevant user information.

Follower/Following Model:
Create a new model for managing the follower/following relationships. This model should have two fields, one for the follower (a reference to the User model) and another for the user being followed (another reference to the User model).

Create APIs:
Generate APIs for your User and Follower/Following models in Strap. These APIs will provide the necessary endpoints for interacting with user data and managing relationships.

User Registration and Authentication:
Implement user registration and authentication functionality. Strap offers user authentication and registration features out of the box. Make sure your users are authenticated before they can follow or be followed.

i don’t understand :smiling_face_with_tear:

Your approach is optimal from a data normalization point of view, but the main problem occurring here is, that we can get pagination data of followers but not following, so if the front-end guy needs pagination for following then it’s a bad choice.

That’s a good choice however we are storing twice the data. So is there any alternative approach?