Comments & Follow System
Relevant source files
The following files were used as context for generating this wiki page:
- app/Livewire/Comments/CommentsSection.php
- resources/views/livewire/comments/comments-section.blade.php
- resources/views/components/comments/comment-item.blade.php
- tests/Feature/Livewire/CommentsSectionTest.php
- resources/views/livewire/posts/post-show.blade.php
- app/Actions/Comments/DeleteCommentAction.php
- app/Actions/Comments/HideCommentAction.php
The Comments & Follow System in RateGuru provides a robust interactive layer for users to engage with shared posts. It facilitates threaded discussions through a multi-level commenting architecture and allows users to build a personalized feed by following specific authors. The system is built using the TALL stack (Tailwind, Alpine.js, Laravel, Livewire), adhering to a "thin component" architecture where business logic is offloaded to dedicated Action classes.
Sources: AGENTS.md:1-40, app/Livewire/Comments/CommentsSection.php:12-25
Commenting Architecture
The commenting system is primarily managed by the CommentsSection Livewire component. It supports top-level comments and one level of nested replies. Access is restricted based on authentication status and user roles (Admin, Moderator, or User).
Component Structure
- CommentsSection: The main container component that handles fetching, sorting, and paginating comments for a specific post.
- CommentItem: A Blade component responsible for rendering individual comments, including author details, timestamps, and action menus.
- CommentForm: A dedicated component for submitting new top-level comments.
Sources: app/Livewire/Comments/CommentsSection.php:14-16, resources/views/components/comments/comment-item.blade.php:1-5, resources/views/livewire/comments/comments-section.blade.php:40-42
Data Flow for Creating Replies
The following diagram illustrates the process of initiating and submitting a reply to an existing comment.
Sorting and Visibility
Comments are filtered by status and can be sorted dynamically by the user. Only comments with the Visible status are rendered to the public; Hidden or soft-deleted comments are excluded from the query.
Sorting Options
| Sort Key | Logic | Purpose |
|---|---|---|
top | (upvotes_count - downvotes_count) DESC | Ranks comments by highest net score. |
newest | created_at DESC | Shows the most recent comments first. |
hot | (upvotes_count + downvotes_count) DESC | Ranks comments by total engagement/activity. |
Sources: app/Livewire/Comments/CommentsSection.php:33-50, lang/en/ui.php:62-66
Visibility Logic
The component utilizes Eloquent scopes to ensure data integrity:
- Status Filter:
where('status', CommentStatus::Visible) - Parent Filter:
whereNull('parent_id')for the primary list to maintain the thread structure. - Eager Loading: Loads
userandreplies(also filtered for visibility) to prevent N+1 query issues.
Sources: app/Livewire/Comments/CommentsSection.php:36-42, tests/Feature/Livewire/CommentsSectionTest.php:23-44
Moderation and Management
The system implements strict authorization policies for managing existing comments. Actions like deleting or hiding comments are handled via dedicated Action classes to ensure business rules are applied consistently.
Comment Actions
| Action | Authorization | Description |
|---|---|---|
| Delete | Author or Admin | Soft-deletes the comment record. |
| Hide | Moderator or Admin | Updates comment status to Hidden to remove it from public view. |
| Report | Authenticated User | Dispatches a report modal for community moderation. |
Sources: app/Livewire/Comments/CommentsSection.php:185-225, resources/views/components/comments/comment-item.blade.php:50-80, tests/Feature/Filament/CommentResourceTest.php:11-40
Interaction Flow
Following System
The "Follow" functionality allows users to subscribe to specific authors, influencing the content served in their "Following" feed.
Implementation Details
- Trigger: Follow buttons are typically found on the
post-showpage andpost-drawercomponents. - Component:
livewire:follows.follow-button. - States: The state is managed via a
FollowStateMapto determine if a user is currently following an author. - Feed Integration: The "Following" navigation filter restricts the post feed to only those authors the authenticated user follows.
Sources: resources/views/livewire/posts/post-show.blade.php:58-62, resources/views/livewire/feed/post-drawer-content.blade.php:56-60, lang/en/ui.php:16-19
Technical Specifications
Rate Limiting
The system enforces rate limits on commenting to prevent spam. If a user exceeds the defined threshold, a validation error is returned via the CommentForm.
- Default Limit: Configurable in
rate_limits.comment. - Error Message: "You are commenting too quickly. Please try again later."
Sources: tests/Feature/Livewire/CommentFormTest.php:76-95
UI Components and Tokens
All comment and follow UI elements must adhere to the PlateRate design contract, utilizing specific Tailwind tokens:
- Card Surfaces:
bg-rg-card,bg-rg-card2. - Borders:
border-rg-border,border-rg-border2. - Interactions:
focus-visible:ring-rg-accent.
Sources: AGENTS.md:30-45, resources/views/dev/ui-kit.blade.php:230-250
Summary
The Comments & Follow System provides the social backbone of RateGuru. By leveraging Livewire for real-time state management and Laravel Actions for business logic, it ensures a responsive and secure environment for user interactions. The architecture supports complex features like nested threading, dynamic sorting, and role-based moderation while maintaining a clean separation of concerns.