Skip to main content
The For You Page (FYP) is Mirage’s personalized social feed that combines content from users you follow, global posts, and trending topics to create an engaging discovery experience.

How the Feed Works

Mirage’s algorithm creates a personalized feed by intelligently mixing different types of content.

Feed Composition

Your For You Page combines three content sources:
  1. Recent posts from followed users (up to 20 posts)
  2. Global posts from users you don’t follow (up to 20 posts)
  3. Older/random posts for discovery (up to 100 posts)
All combined, shuffled, and limited to 30 posts for optimal browsing.

Feed Algorithm

app/routes/feed.py:11-118
@feed_bp.route('/api/fyp',methods=['GET'])
def fyp():
    token = request.headers.get('Authorization')
    if not token:
        return jsonify({'error':'invalid token , please login again'}),401
    
    # Authenticate user
    c.execute('SELECT username FROM users WHERE token=?',(token,))
    user = c.fetchone()
    username = user[0]
    
    # Get list of followed users
    c.execute('SELECT following FROM following WHERE follower=?',(username,))
    followed = c.fetchall()
    if followed:
        followed_users = [f[0] for f in followed]
    else:
        return jsonify({'message':'no users being followed , yet'}),200
    
    # Get recent posts from followed users
    placeholders = ','.join(['?'] * len(followed_users))
    query = '''SELECT id, username, content, created_at, upvotes, downvotes 
               FROM posts 
               WHERE username IN ({}) 
               ORDER BY created_at DESC 
               LIMIT 20'''.format(placeholders)
    c.execute(query, followed_users)
    recent_posts = c.fetchall()
1

Collect Followed Content

Fetch the 20 most recent posts from users you follow, ordered by creation date
2

Add Global Discovery

Include 20 recent posts from users you don’t follow to help you discover new creators
3

Mix in Random Posts

Add up to 100 older posts for serendipitous content discovery
4

Shuffle & Limit

Randomize the combined feed and cap at 30 posts for a fresh experience each time

Content Types

Posts from people you follow get priority in your feed:
app/routes/feed.py:36-57
recent_posts_data = []
for row in recent_posts:
    post_data = {
        'id': row[0],
        'username': row[1],
        'content': row[2],
        'created_at': row[3],
        'upvotes': row[4],
        'downvotes': row[5]
    }
    recent_posts_data.append(post_data)

Feed Personalization

The algorithm combines all three content sources and shuffles them:
app/routes/feed.py:96-101
# Combine and shuffle the posts
combined_posts = recent_posts_data + global_posts_data + old_posts_data
random.shuffle(combined_posts)

# Limit to 30 posts
combined_posts = combined_posts[:30]
Your feed is directly influenced by who you follow:
  • Follow more users = more personalized content
  • Follow fewer users = more discovery content
  • No follows = empty feed (encourages network building)
Random shuffling ensures your feed looks different every time you refresh, keeping the experience fresh and engaging.
Discover what’s hot on Mirage with real-time trending hashtags.

Trending Algorithm

Mirage analyzes hashtags from recent global posts to identify the top 3 trending topics on the platform.

Hashtag Extraction

app/routes/feed.py:103-118
# Extract hashtags from recent global posts
hashtags = []
for post in global_posts_data:
    if 'content' in post:
        found_hashtags = re.findall(r'#(\w+)', post['content'])
        hashtags.extend(found_hashtags)
        
# Get top 3 trending hashtags
hashtag_counts = Counter(hashtags)
trending_hashtags = hashtag_counts.most_common(3)
trending_topics = [f'#{tag}' for tag, count in trending_hashtags]

return jsonify({
    'posts': combined_posts,
    'trending_topics': trending_topics
}), 200
1

Scan Global Posts

Analyze all recent global posts for hashtag patterns
2

Extract Hashtags

Use regex #(\w+) to find all hashtags in post content
3

Count Occurrences

Use Python’s Counter to tally hashtag frequency
4

Surface Top 3

Return the three most commonly used hashtags as trending topics
Regex Pattern: The pattern r'#(\w+)' matches hashtags starting with # followed by word characters (letters, numbers, underscores).

Post Interactions

Engage with feed content through various interaction types.

Upvotes & Downvotes

Vote on posts to show support or disagreement. Each post displays vote counts:
'upvotes': row[4],
'downvotes': row[5]

Replies

Comment on posts to start conversations. Replies are accessible from the feed.

User Profiles

Click any username to view their full profile with all posts and stats

Follow Users

Follow interesting creators directly from their feed posts to see more of their content

First-Time User Experience

Empty Feed: If you’re not following anyone yet, your feed will be empty. Start building your network by:
  • Exploring trending topics
  • Visiting user profiles
  • Following interesting creators
app/routes/feed.py:31-33
if not followed:
    return jsonify({'message':'no users being followed , yet'}),200

Post Structure

Each post in the feed includes comprehensive metadata:
{
  "id": 123,
  "username": "creator_username",
  "content": "Post text with #hashtags",
  "created_at": "2026-03-03T12:00:00",
  "upvotes": 42,
  "downvotes": 3
}

Feed Response Format

The FYP endpoint returns both posts and trending topics:
{
  "posts": [
    {
      "id": 1,
      "username": "alice",
      "content": "Just joined #Mirage! Loving the vibe here 🌟",
      "created_at": "2026-03-03T15:30:00",
      "upvotes": 15,
      "downvotes": 1
    },
    // ... more posts
  ],
  "trending_topics": [
    "#Mirage",
    "#Welcome",
    "#NewUser"
  ]
}

Building Your Network

1

Start Following

Visit user profiles and follow creators whose content interests you
2

Engage with Content

Upvote posts you like, reply to start conversations, and share your thoughts
3

Create Your Own Posts

Post original content to appear in your followers’ feeds
4

Watch Your Feed Grow

As you follow more people, your feed becomes increasingly personalized

Creating Posts

Learn how to publish your own content

Following Users

Build your network by following creators

Post Voting

Engage with content through voting

Algorithm Benefits

Content from followed users ensures your feed reflects your interests and connections
Global posts and random content help you find new creators and diverse perspectives
Random shuffling and mixed content sources prevent feed staleness
Smart limits (20/20/100 → shuffle → 30) balance content diversity with load times
The For You Page requires authentication. All feed requests must include a valid session token in the Authorization header.

Build docs developers (and LLMs) love