Skip to content

samlambert/slacker-news

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slacker News

Hacker News–style demo app hosted on Cloudflare Workers, with PlanetScale via Hyperdrive. Local development runs entirely in Docker, including a local MySQL 8 container. Schema and VSchema are shard-ready to colocate each story with its comments.

Prerequisites

  • Docker and Docker Compose

Quick start (local MySQL mode)

  1. Copy env example and adjust if needed:

    cp .env.example .env
  2. Start containers (app + mysql):

    docker compose up --build

    The app listens on http://localhost:8787.

  3. Initialize schema:

    curl -X POST -H "Authorization: Bearer ${ADMIN_TOKEN:-devtoken}" http://localhost:8787/admin/migrate
  4. Generate fake data:

    curl -X POST -H "Authorization: Bearer ${ADMIN_TOKEN:-devtoken}" \
      -H "Content-Type: application/json" \
      -d '{"users":50,"stories":50,"commentsPerStory":10}' \
      http://localhost:8787/admin/loadgen
  5. Browse:

    • / top stories
    • /item/:id story detail with comments

Workers + Hyperdrive (integration mode)

  • Set DEV_MODE=workers (in .env or your shell) and ensure you have a Hyperdrive binding named HYPERDRIVE configured in your Cloudflare account pointing to a PlanetScale branch.
  • The app inside Docker runs wrangler dev --remote and uses the Hyperdrive connection string.

VSchema (Vitess) and sharding

  • vschema-slacker-news.json defines the unsharded keyspace with:
    • items_seq marked as a Vitess sequence table
    • Standard tables: items, users, votes
  • vschema-slacker-news-sharded.json defines the sharded keyspace with:
    • items and votes sharded by root_id (hash vindex) for comment colocation
    • items configured with auto_increment referencing slacker_news.items_seq
    • users as a reference table (replicated to all shards)
  • ID generation uses Vitess sequences (the proper Vitess-native approach):
    • Sequence table items_seq provides monotonically increasing IDs
    • Works identically in unsharded and sharded modes
    • Stories pre-fetch ID from sequence, then INSERT with root_id=id set correctly
    • Comments inherit root_id from parent story for shard colocation
  • The Hyperdrive connection uses database: "@primary" to enable automatic routing to the correct keyspace (sharded or unsharded)

Scripts

  • npm run dev:local — start Node server against local MySQL (Docker)
  • npm run dev:workers — run Workers dev (remote) against Hyperdrive
  • npm run deploy — deploy Worker

Configuration

  • .env controls local MySQL and ADMIN_TOKEN used for admin endpoints in local mode.
  • .dev.vars can be used if you prefer Worker dev secrets; not required for local mode.

Notes

  • No additional services are installed on your machine; everything runs inside Docker.
  • Dependencies kept minimal: hono, mysql2, and dev-only @hono/node-server.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published