A modern Next.js application designed to scrape and display top chess players' ratings and profile details from the official FIDE website, using Cloudflare Pages, Cloudflare D1 (SQLite), and Drizzle ORM.
- Framework: Next.js 16 (App Router)
- Deployment & Hosting: Cloudflare Pages
- Database: Cloudflare D1 (SQLite)
- ORM: Drizzle ORM
- Styling: Tailwind CSS v4, shadcn & base-ui primitives
- Package Manager: pnpm
The application is structured into modular client-side React components and page routes:
ThemeProvider.tsx: Handles theme context state, storage persistence, and early SSR injection.ThemeSwitcher.tsx: Stylized theme switcher placed in the header to easily swap layouts.Header.tsx: Exposes app branding, page navigation, responsive search input, and theme controllers.RankingList.tsx: Rankings categories selection, cache metadata sync, and standard ranking tables.PlayerProfileCard.tsx: Display for standard, rapid, and blitz ratings, ranks, and sync utility.HistoryChart.tsx: Ratings progress chart over time powered by Recharts.StatsCard.tsx: Game statistics split by White vs Black, support standard, rapid, blitz filters.
- Homepage (
/): Displays the rankings category selector, player search, and the selected player's Profile Details (name, country, rating numbers, FIDE ranks). - Player Details (
/player/[id]): Dynamic route displaying the player's full profile cards, their Rating History Chart, and their White/Black Game Statistics.
The dashboard includes support for 6 theme variants:
- Light Theme: Standard clean light layout.
- Dark Theme: Sleek dark interface.
- Catppuccin Latte: Warm light pastel theme.
- Catppuccin Frappé: Soft dark pastel variant.
- Catppuccin Macchiato: Medium dark pastel variant.
- Catppuccin Mocha: Deep dark pastel variant.
Themes use CSS variables dynamically mapped in app/globals.css, ensuring Tailwind utilities adapt immediately on theme toggles.
Make sure you have Node.js and pnpm installed.
Install dependencies:
pnpm install- Generate type definitions for Cloudflare bindings:
pnpm cf-typegen
- Apply migrations to your local D1 database:
(Confirm with
pnpm exec wrangler d1 migrations apply fide-db --localywhen prompted)
This initializes your local SQLite database structure in .wrangler/state.
Start the local Next.js development server:
pnpm devOpen http://localhost:3000 with your browser to view the application.
- The application uses
initOpenNextCloudflareForDev()insidenext.config.tsto expose the local D1 database bindings. - Database access is lazily initialized via a request-scoped Proxy wrapper in
lib/db.ts. - The local server dynamically updates and hot-reloads as files change.
To create database schema migrations:
- Generate a new SQL migration file:
pnpm exec wrangler d1 migrations create fide-db <migration_name>
- Write your SQL statements in the newly created migration file in the
migrations/directory. - Apply the migration to the local D1 database:
pnpm exec wrangler d1 migrations apply fide-db --local
To build and preview the compiled application locally in an environment simulating the Cloudflare Worker runtime (workerd):
pnpm previewTo build and deploy the application manually live onto Cloudflare Pages:
pnpm deployTo apply your migrations manually to the production Cloudflare D1 database:
pnpm exec wrangler d1 migrations apply fide-db --remoteThis project includes a pre-configured GitHub Actions deployment workflow. Every push to the main branch automatically triggers a runner to:
- Setup Node.js (v20) and pnpm (v9) with dependency caching.
- Compile and package the Next.js application for Cloudflare using OpenNext.
- Automatically execute any pending database migrations on the remote Cloudflare D1 instance.
- Deploy the compiled assets and worker script to Cloudflare.
To enable automated deployments, configure the following secrets in your repository settings (Settings > Secrets and variables > Actions):
CLOUDFLARE_API_TOKEN: A Cloudflare API Token with permissions to edit Workers/Pages and D1 Databases.CLOUDFLARE_ACCOUNT_ID: Your Cloudflare Account ID.
- Interactive API Documentation: /docs (powered by Scalar API Reference UI)
- OpenAPI 3.1 JSON Specification: /openapi.json
All endpoints support database cache hits. If forceUpdate=true is provided, the backend scrapes fresh data from FIDE and updates D1 cache tables.
- Get Top Player List:
/api/list?list=open&forceUpdate=false - Get Player Profile (Consolidated):
/api/profile?id={fideId}&forceUpdate=false - Get Player Rating History (Legacy):
/api/profile/history?id={fideId}&forceUpdate=false - Get Player Game Statistics (Legacy):
/api/profile/stats?id={fideId}&forceUpdate=false