This repo is a Vite React frontend with Vercel-ready Serverless API routes for querying the Affine production PostgreSQL database (read-only). It implements the simplest, quickest deployment path: Vercel serverless functions under the /api directory.
- Serverless API routes (Vercel) with
pgconnection pooling:GET /api/leaderboard— Top 20 miners by average score (Query A)GET /api/activity— Last 10 rollouts (Query B)GET /api/performance-by-env— Performance grouped by environment (Query C)GET /api/results-over-time— Aggregated by day for last 30d (Query D)GET /api/daily-rollouts-by-model— Daily counts for top 5 models, last 7d (Query E)
- Shared DB pool helper:
api/_db.js(SSL required, usesDATABASE_URL) - Frontend typed client:
src/services/api.ts(fetch helpers for all routes) - Vite React app (currently using mock data; you can wire components to API when ready)
Use the following connection string as a single DATABASE_URL value:
postgresql://app_reader:ca35a0d8bd31d0d5@database-1.clo608s4ivev.us-east-1.rds.amazonaws.com:5432/postgres
Notes:
- SSL is required and enforced by
api/_db.jsviassl: { rejectUnauthorized: false }. - The DB user (
app_reader) is read-only.
All queries are executed against public.affine_results:
- Leaderboard (A)
- File:
api/leaderboard.js - Fields:
hotkey,last_seen_uid,model,total_rollouts,average_score,success_rate_percent,avg_latency
- File:
- Activity (B)
- File:
api/activity.js - Fields:
ingested_at,hotkey,uid,model,env_name,score,success
- File:
- Performance by Environment (C)
- File:
api/performance-by-env.js - Fields:
env_name,total_rollouts,average_score,success_rate_percent
- File:
- Results over Time (D)
- File:
api/results-over-time.js - Fields:
period(day),total_rollouts,average_score
- File:
- Daily Rollouts per Model (E)
- File:
api/daily-rollouts-by-model.js - Fields:
day,model,daily_rollouts
- File:
Each file contains the exact SQL from the provided spec.
You have two options:
- Use Vercel Dev (recommended so
/apiroutes work locally)
- Prereqs:
- Node.js 18+ (or 20+)
- Vercel CLI:
npm i -g vercel(orpnpm add -g vercel)
- Create a local env file
.env.localat repo root:DATABASE_URL=postgresql://app_reader:ca35a0d8bd31d0d5@database-1.clo68s4ivev.us-east-1.rds.amazonaws.com:5432/postgres - Start the full stack locally (frontend + API):
This serves both the Vite app and the
vercel dev/api/*endpoints on the same origin.
- Run Vite only (frontend only; API will 404)
- If you just run
npm run dev, the/api/*endpoints are not served. - Use this only for UI work that doesn't call the backend, or set up a proxy to a remote deployment.
- Push this repo to GitHub.
- In Vercel:
- Import the repo as a new Project.
- In Project > Settings > Environment Variables, add:
- Name:
DATABASE_URL - Value:
postgresql://app_reader:ca35a0d8bd31d0d5@database-1.clo68s4ivev.us-east-1.rds.amazonaws.com:5432/postgres
- Name:
- Redeploy to apply env vars.
After deploy, your API will be available at:
https://<your-project>.vercel.app/api/leaderboard
https://<your-project>.vercel.app/api/activity
https://<your-project>.vercel.app/api/performance-by-env
https://<your-project>.vercel.app/api/results-over-time
https://<your-project>.vercel.app/api/daily-rollouts-by-model
Optional region optimization:
- The database is in us-east-1. You can set Vercel Serverless region to a nearby US region (e.g., IAD) via a
vercel.jsonlater to reduce latency. - Not required for functionality.
A typed client for the endpoints is provided:
src/services/api.tsfetchLeaderboard()fetchActivity()fetchPerformanceByEnv()fetchResultsOverTime()fetchDailyRolloutsByModel()
Example:
import { useEffect, useState } from 'react';
import { fetchLeaderboard, type LeaderboardRow } from './services/api';
export function Example() {
const [rows, setRows] = useState<LeaderboardRow[]>([]);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
fetchLeaderboard()
.then(setRows)
.catch((e) => setError(e.message));
}, []);
if (error) return <div>Error: {error}</div>;
return (
<ul>
{rows.map((r) => (
<li key={`${r.hotkey}-${r.model}`}>{r.hotkey} — {r.model}: {r.average_score.toFixed(3)}</li>
))}
</ul>
);
}Note: To have /api available during local development, run vercel dev.
Once running (locally with vercel dev or on Vercel):
curl http://localhost:3000/api/leaderboard
curl http://localhost:3000/api/activity
curl http://localhost:3000/api/performance-by-env
curl http://localhost:3000/api/results-over-time
curl http://localhost:3000/api/daily-rollouts-by-model
Replace localhost:3000 with your deployed domain on Vercel to test in production.
- Do not commit secrets.
DATABASE_URLmust be set via Vercel Project Settings or.env.localfor local development. - The DB user here is read-only (
app_reader).
npm run dev— Vite dev server (frontend only)npm run build— Build frontendnpm run preview— Preview built frontend- For full-stack local dev (frontend + API):
vercel dev
- Vercel Serverless Functions under
api/ - Node.js +
pgv8 - React 18 + Vite + Tailwind