// ============================================================================ // Project : anomaly-atlas // File : web/server.js // Purpose : Public atlas platform — routes and pages (English, light) // Author : Simon-Pierre Boucher // Contact : contact@spboucher.ai // Data src : hfmarketdata.io (sole data source) // Created : 2026-08-12 // Modified : 2026-08-12 // Platform : macOS / Apple Silicon (arm64) — Node.js (deployed on MacLustr) // License : All rights reserved (research code) // ============================================================================ "use strict"; const fs = require("fs"); const os = require("os"); const path = require("path"); const express = require("express"); const C = require("./lib/content"); const R = require("./lib/render"); const charts = require("./lib/charts"); const app = express(); const PORT = process.env.PORT || 8150; // Comments live OUTSIDE the deploy directory so rsync --delete redeploys // never erase them. const COMMENTS_PATH = process.env.COMMENTS_PATH || path.join(os.homedir(), ".anomaly-atlas", "comments.json"); app.use("/static", express.static(path.join(__dirname, "public"), { maxAge: "1h" })); app.use(express.urlencoded({ extended: false, limit: "16kb" })); function page(res, opts) { res.send(R.layout({ ...opts, buildInfo: C.buildInfo() })); } function metaChips(data) { if (!data || !Object.keys(data).length) return ""; const fields = ["document", "author", "created", "modified", "status"]; const chips = fields .filter((f) => data[f]) .map((f) => `${f}${R.esc(data[f])}`) .join(""); return chips ? `
${chips}
` : ""; } // ---------------------------------------------------------------- home app.get("/", (req, res) => { const s = C.stats(); const log = C.parseLogEntries().slice(-3).reverse(); const phases = [ ["Phase 0.5 — Data reality check (Experiment A)", C.exists("research/data_source_profile.md") && (C.readText("research/data_source_profile.md") || "").length > 1200 ? "done" : "pending", "what hfmarketdata.io actually provides"], ["Phase 1 — Literature research (§4.1–4.6)", s.notes ? "in progress" : "pending", `${s.notes} theme notes · ${s.sources} sources`], ["Phase 2 — State-of-the-art map", (C.readText("research/state_of_the_art.md") || "").length > 1200 ? "done" : "pending", "per-anomaly epistemic status"], ["Phase 3 — Research gaps", s.gaps ? "done" : "pending", `${s.gaps || "≥20 target"} testable hypotheses with constructable artifact nulls`], ["Phase 4 — Candidate ranking", (C.readText("research/candidate_ranking.md") || "").length > 1200 ? "done" : "pending", "10-axis scoring, 3–5 candidates"], ["Phases 5–6 — Framework & micro-experiments A–H", s.experimentsDone ? "in progress" : "pending", `${s.experimentsDone}/${s.experiments} experiments completed`], ["Phases 7–11 — Candidates → methodology → atlas → novelty", "pending", "evidence-driven"], ]; const phaseHtml = phases .map( ([name, st, detail]) => `
  • ${name}${detail}
    ${st}
  • ` ) .join(""); const logHtml = log .map((e) => { const [when, ...rest] = e.title.split(" — "); const excerpt = R.markdownToHtml(e.body.split("\n").slice(0, 6).join("\n"), "research/LOG.md").html; return `

    ${R.esc(rest.join(" — ") || when)}

    ${excerpt}
    `; }) .join(""); const body = `

    Independent statistics + market-microstructure research · Apple Silicon · hfmarketdata.io

    Which market "anomalies" are real —
    and which are artifacts?

    A systematic, reproducible atlas of statistical regularities in open high-frequency market data — mean-reversion, lead-lag, calendar effects — where every claim survives (or visibly fails) out-of-sample testing, multiple-comparison correction, artifact nulls, and realistic transaction costs. Negative results are first-class findings.

    detectable in-sample ≠ reproducible out-of-sample ≠ robust to artifacts ≠ meaningful after costs

    ${s.sources}sources reviewed
    ${s.gaps}hypotheses registered
    ${s.experimentsDone}/${s.experiments}experiments completed
    ${s.findings}atlas findings (Level ≥ 1)

    The confidence taxonomy

    A finding only advances one level at a time, and only Level ≥ 1 is ever published. A large in-sample effect with zero out-of-sample survival is a negative result — published as one.

    Browse the atlas →

    Research phases

    Latest from the research log

    Full research log →
    ${logHtml}
    `; const homeFig = charts.homeFigure(C); const figSection = homeFig ? `

    Latest measured figure

    ${homeFig.experiment} →
    ${homeFig.html}
    ` : ""; page(res, { title: "Home", active: "Home", body: body + figSection }); }); // ---------------------------------------------------------------- atlas app.get("/atlas", (req, res) => { const findings = C.listFindings(); const published = findings.filter((f) => f.level >= 1); const cards = published .map( (f) => `

    ${R.esc(f.title)}${f.negative ? ' negative result' : ""}

    ${R.esc(f.summary)}

    ${R.levelBadge(f.level)}
    ` ) .join(""); const empty = `

    No findings yet — and that is the point

    The atlas publishes only Level ≥ 1 findings: effects that survive multiple-testing correction and a clean out-of-sample split with the artifact null subtracted. Nothing has earned that yet — the framework is being built so that nothing can enter without earning it. The artifact taxonomy and the validation methodology are primary deliverables in their own right.

    `; const body = `

    The atlas

    Confidence-labeled statistical regularities (and non-regularities) in hfmarketdata.io data. Every entry carries provenance — commit, config, data-manifest hash, hardware — and the exact command that regenerates it. Negative results are first-class entries.

    ${published.length ? `
    ${cards}
    ` : empty}

    Foundations

    Artifact taxonomy

    The catalogue of artifacts in this dataset that masquerade as anomalies — often the most useful output.

    Validation methodology

    The pre-registered protocol that turns a hypothesis into a confidence-labeled entry.

    `; page(res, { title: "Atlas", active: "Atlas", body }); }); app.get("/atlas/:id/:version", (req, res) => { const f = C.listFindings().find((x) => x.id === req.params.id && x.version === req.params.version); if (!f) return notFound(res); const prov = C.readJson(path.posix.join(f.rel, "provenance.json")) || {}; const conf = C.readMarkdown(path.posix.join(f.rel, "confidence.md")); const provRows = Object.entries(prov) .map(([k, v]) => `${R.esc(k)}${R.esc(typeof v === "string" ? v : JSON.stringify(v))}`) .join(""); const body = `

    Atlas / ${R.esc(f.id)} / ${R.esc(f.version)}

    ${R.esc(f.title)}

    ${R.levelBadge(f.level)}${f.negative ? ' negative result' : ""}

    ${R.esc(f.summary)}

    ${conf ? `

    Confidence evidence

    ${R.markdownToHtml(conf.content, path.posix.join(f.rel, "confidence.md")).html}
    ` : ""}

    Finding payload

    ${R.highlightFile(JSON.stringify(f.finding, null, 2), "x.json")}

    Provenance

    ${provRows}

    Past statistical regularity does not imply future returns. Not investment advice.

    `; page(res, { title: f.title, active: "Atlas", body }); }); // ---------------------------------------------------------------- publications function listPublications() { return (C.listDir("research/publications") || []) .filter((f) => f.name.endsWith(".md") && f.name !== "README.md") .map((f) => { const md = C.readMarkdown(f.rel); return md ? { rel: f.rel, slug: f.name.replace(/\.md$/, ""), data: md.data, content: md.content } : null; }) .filter(Boolean) .sort((a, b) => String(b.data.created).localeCompare(String(a.data.created))); } app.get("/publications", (req, res) => { const pubs = listPublications(); const cards = pubs.map((p) => ` ${R.esc(p.data.pub_id || "")} · ${R.esc(String(p.data.created || ""))} · v${R.esc(String(p.data.version || "1"))}

    ${R.esc(p.data.title || p.slug)}

    ${p.data.subtitle ? `

    ${R.esc(p.data.subtitle)}

    ` : ""}

    ${R.esc(p.data.abstract ? String(p.data.abstract).slice(0, 260) + "…" : "")}

    ${R.esc(p.data.status || "draft")}
    `).join(""); const body = `

    Publications

    Formal write-ups of the project's results, versioned in the repository like everything else. Every number is regenerated from committed results.json files and every figure is rendered live from them — nothing is hand-typed. Each publication states its evidence level; negative results are published with the same care as positive ones.

    ${cards || '

    No publications yet.

    '}
    `; page(res, { title: "Publications", active: "Publications", body }); }); app.get("/publications/:slug", (req, res) => { const pub = listPublications().find((p) => p.slug === req.params.slug); if (!pub) return notFound(res); let { html, toc } = R.markdownToHtml(pub.content, pub.rel); // live figures: {{figure:experiment_id}} tokens -> server-rendered SVG html = html.replace(/

    \s*\{\{figure:([\w-]+)\}\}\s*<\/p>|\{\{figure:([\w-]+)\}\}/g, (m, a, b) => charts.figuresFor(a || b, C) || ""); const d = pub.data; const body = `

    ${R.esc(d.pub_id || "")} · version ${R.esc(String(d.version || "1"))} · ${R.esc(String(d.created || ""))}

    ${R.esc(d.title || pub.slug)}

    ${d.subtitle ? `

    ${R.esc(d.subtitle)}

    ` : ""}

    ${R.esc(d.author || "")} · ${R.esc(d.contact || "")} · data: hfmarketdata.io ${R.esc(d.status || "draft")}

    ${d.abstract ? `
    Abstract

    ${R.esc(d.abstract)}

    ` : ""}
    ${R.tocHtml(toc)}
    ${html}
    `; page(res, { title: d.title || pub.slug, active: "Publications", body }); }); // ---------------------------------------------------------------- research index app.get("/research", (req, res) => { const docs = [ ["research/LOG.md", "Research log", "Append-only, auditable record of every question, experiment, result, and decision."], ["research/data_source_profile.md", "Data source profile", "Phase 0.5 — what hfmarketdata.io actually provides, established empirically."], ["research/state_of_the_art.md", "State of the art", "Phase 2 — per-anomaly map with epistemic status: robust / decayed / disputed / likely-artifact."], ["research/artifact_taxonomy.md", "Artifact taxonomy", "The living catalogue of dataset artifacts that masquerade as anomalies (Q4)."], ["research/research_gaps.md", "Research gaps", "Phase 3 — ≥20 testable hypotheses, each with a constructable artifact null."], ["research/candidate_ranking.md", "Candidate ranking", "Phase 4 — 10-axis scoring and selected prototype candidates."], ["research/methodology.md", "Validation methodology", "Phase 9 — the pre-registered protocol behind every atlas entry."], ["research/bibliography.md", "Bibliography", "Every consulted source with URL and access date."], ["research/novelty_check.md", "Novelty check", "Phase 11 — assume not novel until evidence says otherwise (written last)."], ]; const cards = docs .map(([rel, title, desc]) => { const ok = C.exists(rel); const thin = ok && (C.readText(rel) || "").length < 1200; return `

    ${title}

    ${desc}

    ${!ok ? 'not yet written' : thin ? 'placeholder' : ""}
    `; }) .join(""); const notes = (C.listDir("research/notes") || []) .filter((f) => f.name.endsWith(".md") && f.name !== "README.md") .map((f) => { const md = C.readMarkdown(f.rel); const sources = md ? (md.content.match(/^- .*http/gm) || []).length : 0; const lines = md ? md.content.split("\n").length : 0; return `

    ${R.esc(f.name.replace(".md", "").replace(/_/g, " "))}

    Phase 1 literature notes — ${lines} lines.

    ${sources} sources
    `; }) .join(""); const body = `

    Research documents

    ${cards}
    ${notes ? `

    Phase 1 literature notes

    ${notes}
    ` : ""}

    The project charter itself is public: read the full research charter.

    `; page(res, { title: "Research", active: "Research", body }); }); // ---------------------------------------------------------------- markdown viewer app.get(/^\/doc\/(.+)$/, (req, res) => { const rel = req.params[0]; const md = rel.endsWith(".md") ? C.readMarkdown(rel) : null; if (!md) return notFound(res); const crumb = `

    Research / ${R.esc(rel)}

    `; if (rel === "research/LOG.md") { const entries = C.parseLogEntries(); const body = `${crumb} ${R.docHeader({ ...md.data, document: "Research log" }, rel)}

    Append-only, newest first — every question, experiment, result, interpretation, and decision, as required by the charter (§12). ${entries.length} entries.

    ${R.logTimeline(entries, rel)}`; return page(res, { title: "Research log", active: "Research", body }); } const { html, toc } = R.markdownToHtml(md.content, rel); const tocBox = R.tocHtml(toc); const body = `${crumb}${R.docHeader(md.data, rel)}
    ${tocBox}
    ${html}
    `; page(res, { title: md.data.document || rel, active: "Research", body }); }); // ---------------------------------------------------------------- experiments app.get("/experiments", (req, res) => { const exps = C.listExperiments(); const cards = exps .map( (e) => `

    ${R.esc(e.id)}

    ${R.esc(e.purpose)}

    ${e.status} ${e.runs ? `${e.runs} result run${e.runs > 1 ? "s" : ""}` : ""}
    ` ) .join(""); const body = `

    Experiments

    Every experiment carries a registered hypothesis with an explicit falsification criterion and its artifact null(s), a benchmark implementation, raw results, and an analysis. Detectors must first pass the synthetic-series tests — a detector that finds anomalies in a random walk is broken. Negative results are kept.

    ${cards}
    `; page(res, { title: "Experiments", active: "Experiments", body }); }); app.get("/experiments/:id", (req, res) => { const exps = C.listExperiments(); const exp = exps.find((e) => e.id === req.params.id); if (!exp) return notFound(res); const sections = []; for (const [file, title] of [["hypothesis.md", "Hypothesis"], ["analysis.md", "Analysis"], ["README.md", "README"]]) { const md = C.readMarkdown(path.posix.join(exp.rel, file)); if (md && md.content.trim().length > 40) { sections.push(`

    ${title}

    ${metaChips(md.data)}
    ${R.markdownToHtml(md.content, path.posix.join(exp.rel, file)).html}
    `); } } const runs = C.listResultRuns().filter((r) => r.experiment === exp.id); const runsHtml = runs.length ? `

    Result runs

    ` : ""; const codeLink = C.exists(path.posix.join(exp.rel, "benchmark.py")) ? `

    View benchmark implementation (benchmark.py) →

    ` : ""; const figures = charts.figuresFor(exp.id, C); const figuresHtml = figures ? `

    Figures

    Generated server-side from the latest committed results.json — never hand-typed.

    ${figures}
    ` : ""; const body = `

    Experiments / ${R.esc(exp.id)}

    ${R.esc(exp.id)}

    ${R.esc(exp.purpose)}

    ${codeLink}${figuresHtml}${sections.join("")}${runsHtml}`; page(res, { title: exp.id, active: "Experiments", body }); }); // ---------------------------------------------------------------- results app.get("/results", (req, res) => { const runs = C.listResultRuns(); const rows = runs .map( (r) => `${r.experiment} ${r.timestamp} ${r.files.map((f) => `${f.name}`).join(" · ")}` ) .join(""); const body = `

    Raw results

    Every result is reproducible from commit hash + config + data-manifest index + seed + hardware manifest, and each JSON embeds the manifest of the exact machine that produced it.

    ${rows || ''}
    ExperimentRun (UTC)Files
    No result runs yet.
    `; page(res, { title: "Results", active: "Results", body }); }); app.get(/^\/results\/(.+)$/, (req, res) => { const rel = req.params[0].startsWith("results/") ? req.params[0] : "results/" + req.params[0]; const raw = C.readText(rel); if (raw === null) return notFound(res); let bodyContent; if (rel.endsWith(".json")) { const obj = C.readJson(rel); bodyContent = `
    ${R.highlightFile(JSON.stringify(obj, null, 2), "x.json")}
    `; } else { bodyContent = `
    ${R.esc(raw.slice(0, 200000))}
    `; } const body = `

    Results / ${R.esc(rel)}

    ${bodyContent}
    `; page(res, { title: rel, active: "Results", body }); }); // ---------------------------------------------------------------- code browser const CODE_ROOTS = ["src", "tools", "benchmarks", "experiments", "Makefile", "pyproject.toml", "CITATION.cff"]; app.get("/code", (req, res) => { const sections = CODE_ROOTS.map((root) => { if (!C.exists(root)) return ""; const st = C.listDir(root); if (st === null) { return `
  • ${root}
  • `; } const files = C.walk(root, (f) => C.isTextFile(f.rel) && !f.rel.includes("results/")); return `
  • ${root}/
  • `; }).join(""); const body = `

    Code

    Core library (src/anomaly_atlas/) — including the single hf_client every byte of data flows through — tooling, benchmark harness, and experiment implementations. Every file carries the project's author header and the hfmarketdata.io data-source attribution.

    `; page(res, { title: "Code", active: "Code", body }); }); app.get(/^\/file\/(.+)$/, (req, res) => { const rel = req.params[0]; if (!C.isTextFile(rel)) return notFound(res); const raw = C.readText(rel); if (raw === null) return notFound(res); const name = rel.split("/").pop(); const body = `

    Code / ${R.esc(rel)}

    ${R.esc(rel)} ${raw.split("\n").length} lines
    ${R.highlightFile(raw.slice(0, 400000), name)}
    `; page(res, { title: name, active: "Code", body }); }); // ---------------------------------------------------------------- about app.get("/about", (req, res) => { const body = `

    About this project

    anomaly-atlas is an independent research project by Simon-Pierre Boucher (contact@spboucher.ai) that asks: given only open high-frequency market data from hfmarketdata.io (the sole data source), which statistical regularities — mean-reversion, lead-lag relationships, calendar/seasonal effects — are real, and which are artifacts of bid-ask bounce, stale or non-synchronized timestamps, survivorship, look-ahead, or microstructure noise?

    The methodology is deliberately strict: pre-specified hypotheses and splits, artifact nulls that every detector must beat, mandatory multiple-testing correction, a holdout touched exactly once, realistic transaction-cost models, an append-only research log, hardware manifests embedded in every result, and no result reported from an uncommitted tree. Detectors are validated on synthetic series first — a detector that finds anomalies in a pure random walk is broken. The full methodology is codified in the research charter.

    What counts as a real result

    What this is not

    Not a trading system, not trading advice, not a claim of arbitrage or "free money". The honest answer "nothing survives" is an acceptable — and publishable — outcome. Do not assume Level-3 findings exist; the research establishes the truth either way.

    Platform

    Everything runs on a consumer Apple Silicon Mac: DuckDB + parquet on the internal NVMe for out-of-core columnar queries, NumPy/Accelerate for the math. This site is generated from the repository itself — no hand-typed numbers.

    `; page(res, { title: "About", active: "About", body }); }); // ---------------------------------------------------------------- comments function loadComments() { try { return JSON.parse(fs.readFileSync(COMMENTS_PATH, "utf8")); } catch { return []; } } function saveComment(entry) { fs.mkdirSync(path.dirname(COMMENTS_PATH), { recursive: true }); const all = loadComments(); all.push(entry); fs.writeFileSync(COMMENTS_PATH, JSON.stringify(all, null, 2)); } const lastPostByIp = new Map(); // ip -> epoch ms (simple anti-flood) function commentsBody(flash) { const comments = loadComments().slice().reverse(); const list = comments .map( (c) => `
    ${R.esc(c.name)} ${c.page ? `on ${R.esc(c.page)}` : ""}
    ${R.esc(c.message)}
    ` ) .join(""); return `

    Comments

    Questions, methodological objections, artifact reports, pointers to literature — all welcome. The most valuable comment here is "your effect is explained by X". Comments are public. Nothing on this page (or this site) is investment advice.

    Leave a comment

    ${flash || ""}

    Plain text only. One comment per 30 seconds. Abusive or promotional content is removed.

    ${list || '

    No comments yet — be the first.

    '}
    `; } app.get("/comments", (req, res) => { let flash = ""; if (req.query.ok) flash = `

    Comment posted — thank you.

    `; else if (req.query.err) flash = `

    ${R.esc(String(req.query.err))}

    `; page(res, { title: "Comments", active: "Comments", body: commentsBody(flash) }); }); app.post("/comments", (req, res) => { const ip = req.headers["x-forwarded-for"] || req.socket.remoteAddress || "?"; const now = Date.now(); const err = (msg) => res.redirect(303, "/comments?err=" + encodeURIComponent(msg)); if (now - (lastPostByIp.get(ip) || 0) < 30_000) return err("Please wait 30 seconds between comments."); const { name = "", message = "", page: pageRef = "", website = "" } = req.body || {}; if (website.trim() !== "") return err("Submission rejected."); const cleanName = String(name).trim().slice(0, 60); const cleanMsg = String(message).trim().slice(0, 2000); const cleanPage = String(pageRef).trim().slice(0, 120); if (cleanName.length < 1) return err("Name is required."); if (cleanMsg.length < 3) return err("Comment is too short."); lastPostByIp.set(ip, now); saveComment({ name: cleanName, message: cleanMsg, page: cleanPage || null, ts: new Date().toISOString(), }); res.redirect(303, "/comments?ok=1"); }); // ---------------------------------------------------------------- misc app.get("/health", (req, res) => res.json({ ok: true, app: "anomaly-atlas-web", author: "Simon-Pierre Boucher", data_source: "hfmarketdata.io" })); function notFound(res) { res.status(404); page(res, { title: "Not found", active: "", body: `

    404

    That page does not exist. Back to home.

    ` }); } app.use((req, res) => notFound(res)); app.listen(PORT, () => console.log(`anomaly-atlas-web listening on :${PORT}`));