Skip to content

Add activity feed API #1081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MervinPraison
Copy link
Owner

@MervinPraison MervinPraison commented Aug 19, 2025

PR Type

Enhancement


Description

  • Add Express.js server with activity feed endpoint

  • Create /feed API route returning JSON data

  • Include sample activity data for testing


Diagram Walkthrough

flowchart LR
  A["Express Server"] --> B["/feed endpoint"]
  B --> C["JSON Activity Data"]
  C --> D["Sample Activities"]
Loading

File Walkthrough

Relevant files
Enhancement
server.js
Create Express server with activity feed API                         

graphite-demo/server.js

  • Create new Express.js server on port 3000
  • Add /feed GET endpoint returning activity data
  • Include sample activity feed with user interactions
  • Set up basic server listening and logging
+30/-0   

Summary by CodeRabbit

  • New Features
    • Introduced a lightweight local HTTP server for demo/testing that serves a sample activity feed.
    • Added a GET /feed endpoint returning a static list of activities (id, title, body) in JSON.
    • Server starts on port 3000 and logs a startup message for quick verification.

Copy link
Contributor

coderabbitai bot commented Aug 19, 2025

Walkthrough

Introduces a new Express HTTP server at graphite-demo/server.js. It starts on port 3000, defines an in-memory activityFeed with three items, and exposes a single GET /feed endpoint that returns the array as JSON. Logs a startup message. No additional routes, errors, or exports.

Changes

Cohort / File(s) Summary of Changes
Express server setup
graphite-demo/server.js
Added Express app listening on port 3000 with a single route GET /feed returning a static in-memory activityFeed array as JSON; logs startup message.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Client
    participant App as Express App
    participant Route as GET /feed Handler

    Client->>App: HTTP GET /feed
    App->>Route: Route dispatch
    Note over Route: Read in-memory activityFeed
    Route-->>App: res.json(activityFeed)
    App-->>Client: 200 OK + JSON array
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my whiskers, server awake—
Port 3000 hums, no errors to make.
A feed of three, so tidy and neat,
Hop to /feed for a JSON treat.
Logs are crisp, routes are few—
Carrot-approved: ship it, woohoo! 🥕🚀

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 08-19-demo_6fec5aae_add_activity_feed_api

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@MervinPraison
Copy link
Owner Author

@claude review this pull request and do a detailed analysis and fix this if the existing code doesn't have the solution implemented. Making sure it has backward compatibility, no existing features removed. After making those changes, again review the applied changes. Use @web to search if you dont know any information or to find the latest documentation or to find the latest version. Run the code if you think you need to run it to test it. Minimal code change to start with if required any changes. MAINLY IT SHOULD NOT IMPACT ON THE CURRENT SPEED OF EXECUTION of existing features, not increasing the overhead.

Copy link
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

github-actions bot commented Aug 19, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

@MervinPraison MervinPraison marked this pull request as ready for review August 19, 2025 17:30
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Hardcoded Port

The server port is hardcoded to 3000, which may conflict in shared environments and isn't configurable. Consider using an environment variable with a sensible default.

const port = 3000;
Data Shape Consistency

Activity IDs mix large and small values and are not consistently typed or ordered; ensure clients relying on sorting or uniqueness are accounted for and consider stable ordering.

const activityFeed = [
  {
    id: 1000,
    title: 'New Photo Uploaded',
    body: 'Alice uploaded a new photo to her album.'
  },
  {
    id: 2000,
    title: 'Comment on Post',
    body: "Bob commented on Charlie's post."
  },
  {
    id: 13,
    title: 'Status Update',
    body: 'Charlie updated their status: "Excited about the new project!"'
  }
];
Missing Error Handling

The /feed route directly returns data without try/catch or validation; add basic error handling and response codes for robustness and future data sources.

app.get('/feed', (req, res) => {
  res.json(activityFeed);
});

Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Use configurable server port

Make the port configurable via environment variables to avoid hard-coding and
prevent binding conflicts in different environments. Fallback to 3000 if not
provided.

graphite-demo/server.js [3]

-const port = 3000;
+const port = process.env.PORT ? Number(process.env.PORT) : 3000;
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: This is a valuable suggestion that improves the application's flexibility and adherence to best practices by using environment variables for configuration instead of hardcoding the port.

Medium
Use string IDs consistently

Normalize ID types to be consistent; mixing large numbers and small integers can
cause issues if clients expect strings. Use strings for IDs to avoid precision
or parsing problems.

graphite-demo/server.js [6-22]

 const activityFeed = [
   {
-    id: 1000,
+    id: '1000',
     title: 'New Photo Uploaded',
     body: 'Alice uploaded a new photo to her album.'
   },
   {
-    id: 2000,
+    id: '2000',
     title: 'Comment on Post',
     body: "Bob commented on Charlie's post."
   },
   {
-    id: 13,
+    id: '13',
     title: 'Status Update',
     body: 'Charlie updated their status: "Excited about the new project!"'
   }
 ];
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: This is a good suggestion for data modeling, as using string IDs improves consistency and prevents potential precision or parsing issues, making the application more robust.

Low
Add basic error handling

Wrap the handler with basic error handling to ensure the server returns a proper
status on unexpected failures. This prevents unhandled exceptions from crashing
the process.

graphite-demo/server.js [24-26]

 app.get('/feed', (req, res) => {
-  res.json(activityFeed);
+  try {
+    res.json(activityFeed);
+  } catch (err) {
+    console.error('Failed to fetch feed:', err);
+    res.status(500).json({ error: 'Failed to fetch feed' });
+  }
 });
  • Apply / Chat
Suggestion importance[1-10]: 3

__

Why: While adding error handling is generally good practice, the try...catch block is not necessary here as res.json() with a constant in-memory object is highly unlikely to throw a synchronous error.

Low
  • More

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
graphite-demo/server.js (4)

1-3: Use env-configurable port and hide Express fingerprint

  • Binding to a fixed port can clash with other services or PaaS environments that inject PORT.
  • Disabling the X-Powered-By header avoids leaking the Express stack in responses.

Apply this diff:

 const express = require('express');
 const app = express();
-const port = 3000;
+// Hide framework signature
+app.disable('x-powered-by');
+// Prefer env PORT with a dev fallback
+const port = process.env.PORT || 3000;

24-26: Add minimal pagination + no-store cache header (backward-compatible)

Keeps default behavior the same but allows clients to request a limited number of items and ensures clients don’t cache dynamic feeds.

-app.get('/feed', (req, res) => {
-  res.json(activityFeed);
-});
+app.get('/feed', (req, res) => {
+  const limitParam = Number.parseInt(req.query.limit ?? '', 10);
+  const limit =
+    Number.isFinite(limitParam) && limitParam > 0
+      ? Math.min(limitParam, activityFeed.length)
+      : activityFeed.length;
+  const items = activityFeed.slice(0, limit);
+  res.set('Cache-Control', 'no-store');
+  res.json(items);
+});

28-30: Guard server startup and export app for tests/reuse

Wrapping listen avoids side-effects on import and enables integration tests or embedding in a larger app.

-app.listen(port, () => {
-  console.log(`Server running on port ${port}`);
-});
+if (require.main === module) {
+  app.listen(port, () => {
+    console.log(`Server running on port ${port}`);
+  });
+}
+
+module.exports = app;

5-22: Optional: enrich feed items with metadata (type, createdAt) for clients

Adding a minimal schema (e.g., type and createdAt ISO timestamp) helps clients sort/filter and render appropriately without guessing. Not required for this PR, but consider for follow-ups if this is more than a demo.

I can provide a follow-up patch adding type/createdAt while preserving current fields and order.

Do you want me to draft that?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 993ae07 and d901ef7.

📒 Files selected for processing (1)
  • graphite-demo/server.js (1 hunks)

Comment on lines +1 to +30
const express = require('express');
const app = express();
const port = 3000;

// Fake data for the activity feed
const activityFeed = [
{
id: 1000,
title: 'New Photo Uploaded',
body: 'Alice uploaded a new photo to her album.'
},
{
id: 2000,
title: 'Comment on Post',
body: "Bob commented on Charlie's post."
},
{
id: 13,
title: 'Status Update',
body: 'Charlie updated their status: "Excited about the new project!"'
}
];

app.get('/feed', (req, res) => {
res.json(activityFeed);
});

app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify repo dependencies and potential port conflicts

Ensure express is declared and check for other listeners on port 3000 to avoid collisions when running the demo.

Run this script from the repo root:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "== Checking for package.json files and express dependency =="
fd -a -t f -g package.json | while read -r pkg; do
  echo "---- $pkg ----"
  if jq -e '.dependencies.express // .devDependencies.express' "$pkg" >/dev/null 2>&1; then
    echo "express declared:" "$(jq -r '.dependencies.express // .devDependencies.express' "$pkg")"
  else
    echo "express not declared in this package.json"
  fi
done

echo
echo "== Searching for other servers that call listen(...) or use port 3000 =="
# Look for listen() calls (avoid node_modules)
rg -n -C2 -g '!**/node_modules/**' -P '\blisten\s*\(\s*(process\.env\.PORT|\d+)' || true

# Explicit port 3000 occurrences (outside node_modules)
rg -n -C2 -g '!**/node_modules/**' -P '\b3000\b' || true

echo
echo "== If express is missing, install with =="
echo "npm install express"

Length of output: 58521


Ensure Express is declared and make the port configurable to avoid collisions

• Add an explicit package.json in graphite-demo/ (or update the existing one) with Express as a dependency, e.g.:

{
  "name": "graphite-demo",
  "version": "1.0.0",
  "dependencies": {
    "express": "^4.18.2"
  }
}

• In graphite-demo/server.js, replace the hard-coded port with an environment-override:

- const port = 3000;
+ const port = process.env.PORT || 3000;

• Note that other components (e.g. Langtrace agents in src/praisonai-agents) default to localhost:3000. If you run both services locally, pick different ports or override via PORT to prevent conflicts.

🤖 Prompt for AI Agents
In graphite-demo/server.js lines 1 to 30, make the port configurable and ensure
express is declared properly: keep the existing require('express') but replace
the hard-coded port with a value read from process.env.PORT (e.g. const port =
process.env.PORT || 3000) so callers can override it to avoid collisions;
additionally add or update graphite-demo/package.json at the project root to
declare express as a dependency (name, version and "express": "^4.18.2") so npm
install will install Express.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant