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/)
| Endpoint | DB Function | Purpose | Priority |
|---|---|---|---|
GET /api/bookmarks | getUserBookmarks() | List user's saved facts | High |
DELETE /api/bookmarks/[factId] | removeBookmark() | Unsave a fact | High |
GET /api/topics | getActiveTopicCategories() | Browse-by-topic navigation | Medium |
GET /api/stats | getUserCumulativeScore() | Profile stats (score, streaks, mastered count) | Medium |
GET /api/search | (not implemented) | Full-text fact search | Low |
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.