Skip to content

feat: add GET /api/stats public endpoint and CityStatsBar UI component (#992) - #1273

Open
Rakshak05 wants to merge 15 commits into
Ixotic27:mainfrom
Rakshak05:issue-#992
Open

feat: add GET /api/stats public endpoint and CityStatsBar UI component (#992)#1273
Rakshak05 wants to merge 15 commits into
Ixotic27:mainfrom
Rakshak05:issue-#992

Conversation

@Rakshak05

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds a public GET /api/stats endpoint and a client-side CityStatsBar HUD component for displaying aggregate city statistics on the homepage:

  • Backend (src/app/api/stats/route.ts): Returns total developers count, claimed buildings, total problem solves (easy + medium + hard), tallest building username & hard solved count, and timestamp (generatedAt) with Cache-Control headers.
  • Frontend (src/components/CityStatsBar.tsx): Implements a sleek glassmorphic HUD bar showcasing developers, claimed buildings, total solves, and tallest building using useSWR with 5-minute auto-refresh.
  • Homepage Integration (src/app/page.tsx): Integrates <CityStatsBar /> in the top HUD overlay layer.
  • Unit Tests (src/app/api/stats/route.test.ts): Unit test suite validating endpoint output structure, status 200, calculations, and caching headers.

Related issue

Fixes #992

Screenshots

N/A (HUD overlay stats bar rendered cleanly above the 3D canvas on the main homepage)

Checklist

  • npm run lint passes
  • Tested locally
  • No secrets or .env values committed
  • I acknowledge that an automated AI Reviewer will perform a preliminary review of this PR.
  • I have starred this repository! (We prioritize PRs and assignments for stargazers)

Copilot AI review requested due to automatic review settings August 2, 2026 09:44
@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the ixotic27-8245's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

📋 GSSoC Label Validation Report

All label requirements met. This PR passes the pre-merge label check.


📖 Label Reference
Category Valid Labels Rules
Approval gssoc:approved Required to score and merge
Difficulty level:beginner / intermediate / advanced / critical Exactly one is required
Quality quality:clean / quality:exceptional Optional (max one); exceptional requires reviewer comment
Type type:bug, type:feature, type:docs, type:testing, type:refactor, type:design, type:accessibility, type:performance, type:devops, type:security At least one is required
Blocking gssoc:invalid, gssoc:spam, gssoc:ai-slop Excludes PR from scoring and blocks merge

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Security Scan: Clean

No suspicious patterns detected. The official Copilot bot will provide detailed AI feedback shortly.

If you enjoyed contributing, please consider starring the repository!

@github-actions github-actions Bot added backend Backend/API related good first issue Good for newcomers Gssoc 26 Part of GirlScript Summer of Code 2026 gssoc:approved Approved GSSoC contribution level:beginner Beginner difficulty level type:feature New features, additions, or enhancements labels Aug 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

The client fetcher and API route currently risk treating backend failures as successful responses (and therefore caching/displaying misleading “valid” stats) without surfacing an error state.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Adds a public aggregate stats API and a homepage HUD component to display city-wide metrics (developers, claimed buildings, solves, tallest building), enabling at-a-glance “social proof” on the main experience.

Changes:

  • Adds GET /api/stats endpoint returning aggregate city statistics with caching headers.
  • Introduces CityStatsBar client component that polls /api/stats via SWR and renders a HUD overlay on the homepage.
  • Updates homepage overlay stack to render the new stats bar (and reintroduces useGLTF import needed by AtmosphereCycleManager).
File summaries
File Description
src/components/CityStatsBar.tsx New SWR-powered HUD component to display aggregate city metrics.
src/components/AtmosphereCycleManager.tsx Re-adds useGLTF import to support GLTF usage in the component.
src/app/page.tsx Integrates CityStatsBar into the homepage overlay layer.
src/app/api/stats/route.ts Implements the new public aggregate stats endpoint with caching headers.
src/app/api/stats/route.test.ts Adds unit test coverage for the new stats endpoint response shape and calculations.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 4
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread src/components/CityStatsBar.tsx Outdated
import useSWR from "swr";
import { HiUsers, HiBuildingOffice2, HiCheckCircle, HiTrophy } from "react-icons/hi2";

const fetcher = (url: string) => fetch(url).then((r) => r.json());
Comment thread src/components/CityStatsBar.tsx Outdated
Comment on lines +73 to +79
{stats.map((s, idx) => {
const Icon = s.icon;
return (
<div
key={idx}
className="flex items-center space-x-2 px-2 py-1 transition-transform hover:scale-105"
>
Comment on lines +74 to +79
expect(json.tallestBuilding).toEqual({
username: "top-coder",
hardSolved: 30,
});
expect(json.totalSolves).toBe(60); // (10+5+2) + (20+15+8) = 60

Comment on lines +13 to 24
const [totalResult, claimedResult, tallestResult, solveResult] = await Promise.all([
sb.from("developers").select("id", { count: "exact", head: true }),
sb.from("developers").select("id", { count: "exact", head: true }).eq("claimed", true),
sb
.from("developers")
.select("github_login, easy_solved, medium_solved, hard_solved")
.order("hard_solved", { ascending: false })
.limit(1)
.maybeSingle(),
sb.from("developers").select("easy_solved, medium_solved, hard_solved"),
]);

@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Aug 2, 2026
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

🚨 Hey @Rakshak05, the CI Pipeline is failing on this PR and it has been marked as status:blocked.

🔍 What failed:

  • Production Build failed at step(s): Run Production Build

📋 Error Details (first 2):

Please fix the issues before this can be reviewed. Here's how:

1. Run checks locally before pushing:

npm run lint           # Run ESLint
npm run build          # Verify production build passes

2. Auto-fix common issues:

npm run lint -- --fix  # Auto-fix lint errors where possible

3. Check the full failure log here:
👉 View CI Run

Once you push a fix and the CI passes, the status:blocked label will be removed automatically. 💪

@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label Aug 2, 2026
@Ixotic27 Ixotic27 added the quality:clean Code is clean, well-tested, and adheres to all guidelines. label Aug 5, 2026

@Ixotic27 Ixotic27 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM! Verified and approved. Great contribution!

@Ixotic27

Ixotic27 commented Aug 5, 2026

Copy link
Copy Markdown
Owner

@Rakshak05 Hi! This PR currently has merge conflicts with main. Please rebase against main and resolve the conflicts so it can be merged.

@github-actions github-actions Bot added the needs-rebase This PR has merge conflicts and needs a rebase. label Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

⚠️ Hey @Rakshak05, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

1 similar comment
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

⚠️ Hey @Rakshak05, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

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

Labels

backend Backend/API related good first issue Good for newcomers gssoc:approved Approved GSSoC contribution Gssoc 26 Part of GirlScript Summer of Code 2026 level:beginner Beginner difficulty level needs-rebase This PR has merge conflicts and needs a rebase. quality:clean Code is clean, well-tested, and adheres to all guidelines. type:feature New features, additions, or enhancements

Projects

None yet

3 participants