Under the Hood. Age Safe® SafetyX

How It Works.
The Tech Stack.

A short walkthrough of how 382 articles get indexed, searched, and ranked — from raw WordPress export to AI-curated answer.

Tech Overview

Architecture & Flow

Tech

  1. Processed Age Safe® America's WordPress library → markdown (wp-to-md.php).
  2. Loaded every post into a local SQLite DB with Full-Text Search index (seed-db.py / seed-db.php → contentx.db).
  3. Wrote index.php as the single front-end + API.

What index.php does

  • Two SQLite connections: contentx.db (read-only post library) and cache.db (auto-created answer cache).
  • ?api=count — returns total post count.
  • ?api=ask (POST {question, topic}) is the core flow:
    1. Hash question+topic → check cache.db. Hit = return instantly.
    2. ftsSearch() runs a Full-Text Search MATCH query against posts_fts, filtered by topic slug if one is picked. Pads to 15 candidates with recent posts if too few hits.
    3. Builds a numbered catalog of candidates and sends it to Claude Haiku 4.5 via api.anthropic.com/v1/messages, asking it to pick the best 5–7 and return strict JSON.
    4. Merges each AI pick with the real title / url / topics from the candidate list, caches the JSON, returns it.
  • HTML/JS below renders the hero, topic tabs, preset questions, search box, and result cards. JS just calls ?api=ask and paints the response.
Summary
Full-Text Search narrows the haystack cheaply, Claude does the ranking + reasoning, cache makes repeats free.
Home →