Follow Object
The Follow object represents a one-way relationship between users in the Replyke social features framework. Unlike connections, follows do not require mutual agreement and establish an immediate relationship similar to Twitter/X follows.
Properties
Property | Type | Description |
---|---|---|
id | string | Unique identifier for the follow relationship (UUID) |
projectId | string | Identifier of the associated project (UUID) |
followerId | string | ID of the user who initiated the follow |
followedId | string | ID of the user being followed |
createdAt | Date | Timestamp when the follow relationship was created |
Characteristics
One-Way Relationship
- Immediate Effect: No approval workflow required
- Unidirectional: Following someone doesn’t create a mutual relationship
- Public: Follow relationships are typically visible to others
- Content Access: Following grants access to user’s content feed
Database Constraints
- Unique Constraint: Prevents duplicate follows between same users
- Self-Follow Prevention: Users cannot follow themselves
- Cascade Deletion: Follow relationships are deleted when users are removed
User Model Associations
The Follow model creates two associations with the User model:
// User hasMany Follow as "following" (as follower)
User.hasMany(Follow, {
foreignKey: "followerId",
as: "following",
onDelete: "CASCADE"
});
// User hasMany Follow as "followers" (as followed user)
User.hasMany(Follow, {
foreignKey: "followedId",
as: "followers",
onDelete: "CASCADE"
});
API Endpoints
User-Centric Operations
POST /users/:userId/follow
- Follow a userGET /users/:userId/follow
- Check follow status with userDELETE /users/:userId/follow
- Unfollow a userGET /users/:userId/followers
- Get followers of specific userGET /users/:userId/followers-count
- Get followers count for specific userGET /users/:userId/following
- Get who specific user followsGET /users/:userId/following-count
- Get following count for specific user
Follow-Centric Operations
GET /follows/following
- List accounts I followGET /follows/followers
- List accounts that follow meGET /follows/following-count
- Get my following countGET /follows/followers-count
- Get my followers countDELETE /follows/:followId
- Unfollow by follow ID
Usage Examples
Following a User
POST /users/user-123/follow
→ Creates Follow record with followerId=current-user, followedId=user-123
Checking Follow Status
GET /users/user-123/follow
→ Returns: { "isFollowing": true, "followId": "follow-uuid", "followedAt": "..." }
Getting User’s Followers
GET /users/user-123/followers
→ Returns paginated list of users following user-123
Business Rules
- No Self-Following: Users cannot follow themselves
- Unique Relationships: Only one follow record between any two users
- Immediate Effect: Follow relationships are created instantly
- Public Visibility: Follow relationships are generally public
- No Approval Required: Unlike connections, follows don’t need acceptance
Performance Considerations
- Indexes: Optimized for queries by followerId, followedId, and projectId
- Pagination: All list endpoints support pagination
- Rate Limiting: Follow actions limited to 75 requests per 5 minutes
- Caching: Consider caching follower/following counts for popular users
Related Models
- User: The users involved in the follow relationship
- Connection: Bidirectional relationship alternative that requires mutual agreement
- AppNotification: Notifications can be triggered for new follows