Feed & Post Discovery
Relevant source files
The following files were used as context for generating this wiki page:
The Feed & Post Discovery system is the primary mechanism through which users interact with published content in RateGuru. It provides a highly interactive, filtered, and searchable interface for browsing posts, utilizing Laravel Livewire for real-time state management and specialized Query objects for efficient data retrieval.
Sources: app/Livewire/Feed/FeedPage.php, app/Queries/Feed/FeedQuery.php
Core Architecture
The discovery system is built on a layered architecture that separates state management, UI rendering, and database querying. The FeedPage component serves as the top-level container, orchestrating the interaction between the search/filter state and the nested PostFeed component.
Component Hierarchy
The FeedPage manages the overall layout and URL query parameters, while the PostFeed handles the actual pagination and rendering of the post list.
Sources: app/Livewire/Feed/FeedPage.php:19-45, resources/views/livewire/feed/feed-page.blade.php:87-109
Filtering and Search Logic
The discovery system supports multiple dimensions of filtering, including content type (Origin), categorization (Cuisine), and text-based search. Filters are synced with the URL to allow for shareable views.
Search Execution
The system implements a "minimum character" threshold for searching to prevent expensive queries on short strings. A search is only considered effective if it contains 3 or more characters.
Sources: app/Livewire/Feed/FeedPage.php:171-176, tests/Feature/Livewire/FeedPageTest.php:159-170
Filter Types and Mapping
| Filter | Description | Source Field |
|---|---|---|
| Search | Keywords in title or description | posts.title, posts.description |
| Category | Cuisine-based classification | posts.cuisine_truth |
| Origin | Source-based classification (e.g., Homemade) | posts.origin_truth, posts.category_option_id |
| Tag | Specific content tags | tags.slug |
| Sort | Ordering (Newest, Top, Hot) | Multiple |
Sources: app/Queries/Feed/FeedQuery.php:24-85
Query Engine (FeedQuery)
The FeedQuery class is the engine responsible for translating UI state into SQL queries. It handles complex sorting logic and multi-value filters.
Sorting Strategies
- Newest: Orders by
published_atandcreated_atdescending. - Top: Orders by the net score (
upvotes_count - downvotes_count). - Hot: Orders by a calculated
hot_score.
Sources: app/Queries/Feed/FeedQuery.php:87-92, tests/Feature/Queries/FeedQueryTest.php:57-89
Pagination and Clamping
The system enforces strict limits on pagination to ensure performance.
- Default: 12 items per page.
- Max: 50 items per page.
Sources: app/Queries/Feed/FeedQuery.php:156-167, tests/Feature/Queries/FeedQueryPaginationTest.php:1-60
User Interaction Flow
Users can select posts from the feed to view detailed information without leaving the page. This is handled via a split-grid layout or a drawer.
Split Mode Logic
The UI dynamically adjusts between a centered feed and a split view. If a post is selected and the application is not in overlayMode, the rg-feed-split-grid class is applied, and the detail column is rendered.
Sources: resources/views/livewire/feed/feed-page.blade.php:54-61
Implementation Details
Data Fetching
The PostFeed component uses the RatingVotingStateLoader to bulk-load voting results for all displayed posts in a single pass, preventing N+1 query issues during feed rendering.
Sources: app/Livewire/Feed/PostFeed.php:41-53
Dynamic Layout Scrolling
The system utilizes Alpine.js to manage smooth scrolling and layout adjustments when a post is selected. It includes logic to handle different screen sizes, ensuring the selected content is positioned correctly in the viewport.
Sources: resources/views/livewire/feed/feed-page.blade.php:12-51
Summary
Feed & Post Discovery provides the central navigation experience for the application. By combining the reactive state of Livewire with a robust Query object, the system delivers a fast, filterable, and mobile-responsive interface for content consumption and interaction. Participants in the feed include not only posts but also matched users, facilitating broader community discovery.
Sources: app/Livewire/Feed/FeedPage.php:178-189, resources/views/livewire/feed/feed-page.blade.php:68-85