EndlessWiki is a tiny Go service that renders AI-generated Wikipedia-style pages on demand. Pages are persisted in MySQL, and every internal link triggers generation of a new page the first time it is visited.
- Normalize the requested slug (case fold, replace spaces with underscores, strip unsafe characters).
- Look for an existing row in the
pagestable. - If found, render the stored HTML.
- If missing, call Groq to synthesize page content, persist the new row, then render.
pages table:
slug(PK, varchar) — normalized slug.content(MEDIUMTEXT) — rendered HTML for the requested slug.created_at(TIMESTAMP) — defaultCURRENT_TIMESTAMP.
Bootstrap SQL lives in db/migrations/001_create_pages.sql.
- Prompt Groq (initial target:
moonshotai/kimi-k2-instruct-0905) with the slug and instructions to emit HTML. The specialmain_pageslug renders a handcrafted EndlessWiki overview instead of calling the model. New slugs are only minted when navigated from an existing page that explicitly links to them. - Output contains a
<h1>heading and a<div class="endlesswiki-body">wrapping the body. - Prompt nudges the model to include 3–6 internal wiki links using
<a href="/wiki/...">anchors. - If
GROQ_API_KEYis missing, a deterministic stub generator returns placeholder content for local development. - A lightweight search endpoint (
/search?q=) surfaces previously generated pages via a simple MySQLLIKEquery. - A constellation exporter (
go run ./cmd/constellation) snapshots the wiki link graph intostatic/constellation.jsonfor visualisation.
# set up a MySQL instance and export a DSN the Go driver understands
export MYSQL_DSN="user:pass@tcp(127.0.0.1:3306)/endlesswiki?parseTime=true"
export GROQ_API_KEY="sk_your_groq_key" # optional; stub content without it
export PORT=8080
# run the server
GOCACHE=$(pwd)/.gocache go run ./cmd/endlesswikiOpen http://localhost:8080/wiki/main_page (or hit /, which redirects there) and follow internal links to generate pages. The chrome exposes search, random (/random), most-recent (/recent), and the constellation map (/constellation) once a snapshot has been generated.
# produce static/constellation.json
scripts/constellation.sh
# optional: choose a different destination
scripts/constellation.sh -out /tmp/constellation.jsonRun the exporter before building/deploying to refresh static/constellation.json. The /constellation page serves static/constellation.html, which visualises the generated snapshot directly in the browser.
- Railway typically exposes
PORTautomatically. - Set
DATABASE_URLto Railway's MySQL connection string (the loader accepts both driver DSNs andmysql://URLs) and storeGROQ_API_KEYas a secret. - Use
go build ./cmd/endlesswikifor deployment or rely on Railway’s Go buildpack. - Make sure migrations run once — e.g. via a Railway job running the SQL in
db/migrations/001_create_pages.sql.
404for invalid slugs,500for DB/Groq failures.- JSON logging can be layered in later; currently plain-text logs capture key errors.
- TODO: metrics endpoint or structured logging for production visibility.
- Rate limiting per IP to prevent abuse.
- Cache Groq responses across instances (e.g. Redis-backed singleflight) and track generation latency metrics.
- Serve shared CSS and assets via static file handler.