API Gaps

Add missing API endpoints across the web and admin apps. The web app needs consumer-facing read APIs for features with DB queries but no route handlers. The admin app has zero fact engine API coverage — pages rely on direct Supabase queries with no REST layer.

Motivation

  • Web app has DB functions (getUserBookmarks(), getActiveTopicCategories(), etc.) with no route handlers
  • Admin dashboard uses direct DB queries — no API contract, no reuse outside server components
  • Operational health (queue depth, provider health, validation rates, AI costs) has no API surface
  • Many DB query functions already exist in packages/db/src/drizzle/fact-engine-queries.ts — just need routes

Key Deliverables

Web App (apps/web/app/api/)

EndpointDB FunctionPurposePriority
GET /api/bookmarksgetUserBookmarks()List user's saved factsHigh
DELETE /api/bookmarks/[factId]removeBookmark()Unsave a factHigh
GET /api/topicsgetActiveTopicCategories()Browse-by-topic navigationMedium
GET /api/statsgetUserCumulativeScore()Profile stats (score, streaks, mastered count)Medium
GET /api/search(not implemented)Full-text fact searchLow

Note: Bookmark add/remove currently happens via /api/cards/[slug]/interact with interactionType: "bookmark", but there's no dedicated list endpoint.

Admin App (apps/admin/app/api/)

18 endpoints across ingestion, facts, topics, schemas, seeds, and ops, plus 5 observability endpoints for queue status, provider health, quotas, validation stats, and cost tracking.

See TODO.md for the full endpoint list organized by wave.

Existing DB Functions (Ready to Wire)

  • getActiveTopicCategories(), getTopicCategoryById(), getTopicCategoryBySlug()
  • getRecentIngestionRunsByType(), getNewsProviderHealth()
  • insertFactRecord(), updateFactRecordStatus(), updateFactRecordImage()
  • getFactRecordById(), getFactRecordSchemaById()
  • getStuckPendingValidations(), getTopicFactCountToday()
  • getUserBookmarks(), removeBookmark()
  • getUserCumulativeScore()

Source

Derived from Gaps 1, 2, and 6 of the Fact Engine API Gaps audit.