Overview
TrackGeek provides a comprehensive social platform that enables users to connect, interact, and share their media experiences. The social system includes user relationships, contextual comments, emoji reactions, and activity feeds.User Relationships
Following System
TrackGeek uses a unidirectional following model where users can follow others without requiring mutual approval. Following Model (prisma/schema.prisma:149-162):
Relationship Terminology
Follower
A user who follows another user. They see the followed user’s activity in their feed.
Following
A user being followed. Their activity appears in their followers’ feeds.
Unique Constraints
The@@unique([followerId, followingId]) constraint ensures:
- No duplicate follow relationships
- One follow record per user pair
- Clean unfollowing (simple delete)
Indexing Strategy
Follower Index
Follower Index
@@index([followerId]) enables efficient queries:- “Who is this user following?”
- “Get all users followed by X”
- Feed generation (find followed users’ activity)
Following Index
Following Index
@@index([followingId]) enables efficient queries:- “Who follows this user?”
- “Get all followers of X”
- Follower count aggregation
User Model Relations
User Relationship Fields (prisma/schema.prisma:34-35):
Comment System
Comment Types
Comments can be attached to any media type or user profile: CommentType Enum (prisma/schema.prisma:164-172):
Comment Model
Comment Schema (prisma/schema.prisma:174-206):
Polymorphic Association
Comments use a polymorphic pattern with:typefield indicating the comment target- Optional foreign keys for each media type
- Exactly one foreign key populated per comment
The multiple unique constraints ensure each user can only leave one comment per media item or profile.
Comment Creation
Example from CommentService (src/modules/comment/comment.service.ts:14-27):
item object contains the appropriate foreign key:
Comment Retrieval
Example from CommentService (src/modules/comment/comment.service.ts:43-132):
Comments include reactions preview (first 3) for efficient rendering without additional queries.
Comment Deletion
Example from CommentService (src/modules/comment/comment.service.ts:29-41):
Deletion requires user authorization - only comment authors can delete their comments.
Reaction System
Reaction Types
Reactions can be added to comments or feed events: ReactionType Enum (prisma/schema.prisma:208-211):
Reaction Model
Reaction Schema (prisma/schema.prisma:213-228):
Emoji Reactions
Reactions use emoji strings for flexible expression:Common Emoji Reactions
Common Emoji Reactions
- 👍 Like/Approve
- ❤️ Love
- 😂 Funny
- 😮 Surprised
- 😢 Sad
- 🔥 Fire/Awesome
- 🎉 Celebrate
- 👏 Applause
- 💯 Perfect
- 🤔 Thinking
Unique Constraints
Reactions enforce one emoji per user per target:@@unique([userId, commentId]): One reaction per user per comment@@unique([userId, feedEventId]): One reaction per user per feed event
Users can change their reaction by deleting and creating a new one, but cannot have multiple reactions on the same target.
Reaction Creation
Example from ReactionService (src/modules/reaction/reaction.service.ts:14-27):
Reaction Retrieval
Example from ReactionService (src/modules/reaction/reaction.service.ts:43-72):
Reaction Deletion
Example from ReactionService (src/modules/reaction/reaction.service.ts:29-41):
Reaction Aggregation
Reactions can be grouped by emoji for display:Feed System
Feed Event Types
Feed events track various user activities: FeedEventType Enum (prisma/schema.prisma:230-238):
- Content Events
- Progress Events
Feed Event Model
FeedEvent Schema (prisma/schema.prisma:240-251):
Metadata Field
Themetadata JSON field stores event-specific data:
NewReview Metadata
NewReview Metadata
NewProgress Metadata
NewProgress Metadata
NewFollower Metadata
NewFollower Metadata
Feed Event Creation
Example from FeedEventService (src/modules/feed-event/feed-event.service.ts:14-24):
Feed events are typically created asynchronously via a queue system to avoid blocking user operations.
Personalized Feed Generation
Example from FeedEventService (src/modules/feed-event/feed-event.service.ts:26-76):
Feed Algorithm
- Get Following List: Query users the current user follows
- Include Self: Add current user’s ID to include their own activity
- Filter Events: Get feed events where
userId IN (following + self) - Sort by Time: Order by
createdAtdescending (newest first) - Include Reactions: Preload reaction counts and preview
- Paginate: Return cursor-based pagination
Feed Indexing
Composite Index (prisma/schema.prisma:250):
- Filtering by user ID
- Sorting by creation time
- Range queries (get events after timestamp)
Social Analytics
The social system enables rich analytics:Follower Count
Total followers per user
Following Count
Total users followed
Comment Count
Total comments per media/user
Reaction Count
Total reactions per comment/event
Engagement Rate
Reactions + comments per feed event
Popular Content
Media with most comments/reactions
Active Users
Users with most feed events
Network Size
Follower + following counts
Feed Activity
Events per day/week/month
Best Practices
Cascade Deletes
All social relationships cascade delete when users are removed
Authorization
Always verify user ownership before deletion
Pagination
Use cursor-based pagination for feeds and comments
Reaction Preview
Include reaction previews to reduce client queries
Async Events
Create feed events asynchronously via queue
Index Optimization
Leverage composite indexes for feed queries