Files
ai-news-writer/docs/BIT-5284-INTEGRATION-PLAN.md
Test be5e0b7fa5 docs(analytics): BIT-5284 Integration Plan — Real backend discovery and path to Phase 2
Discovered that real analytics backend (BIT-5307-BIT-5311) was already
implemented on task/BIT-4619-gitea-actions-secrets branch (April 18),
5 days before Phase 1 dashboard UI work.

This document outlines:
- Current state of Phase 1 (dashboard UI with mock API - complete)
- Real backend implementation already available
- API contract analysis (perfect match for dashboard expectations)
- Three integration approaches with pros/cons
- Recommended: Approach A (clean rebase + cherry-pick)
- Detailed merge conflict analysis
- Step-by-step integration plan for Phase 2
- Testing strategy for real database integration
- Files to add/delete/update

Next action: Execute Approach A rebase when approved.
Effort: 2-3 hours for full integration + testing.
Result: Single coherent branch ready for main merge.
2026-04-23 19:28:29 +00:00

7.8 KiB

BIT-5284: Dashboard UI → Real Backend Integration Plan

Status: Phase 1 (mock API + dashboard UI) complete on task/BIT-5284-analytics-dashboard Discovery: Real analytics backend (BIT-5307-BIT-5311) already implemented on task/BIT-4619-gitea-actions-secrets (April 18) Action Required: Integrate real backend into dashboard UI


Current State

Phase 1 (Completed Today)

  • Branch: task/BIT-5284-analytics-dashboard
  • Commits: a7a2fe4 (2026-04-23)
  • Deliverables:
    • Mock analytics API (src/http/analytics-api.js)
    • Dashboard page (/ui/analytics) - responsive, accessible
    • CSV export endpoint (/api/analytics/export/csv)
    • Implementation plan (docs/ANALYTICS_DASHBOARD_PLAN.md)

Real Backend (Already Implemented)

  • Branch: task/BIT-4619-gitea-actions-secrets
  • Commits: 57510a6 - 62cca34 (2026-04-18)
  • Deliverables:
    • BIT-5307: Engagement event collector (WordPress REST API integration)
    • BIT-5308: Aggregation jobs scheduler
    • BIT-5309: Analytics API routes integration
    • BIT-5310: CSV export endpoint
    • BIT-5311: Integration test suite

Real Backend API Routes

// From src/analytics/routes.js on task/BIT-4619-gitea-actions-secrets

GET /api/analytics/articles/:postId/engagement
  // Time-series engagement data for article
  // Response: { post_id, slug, title, category, data: [{date, views, shares, comments}] }

GET /api/analytics/category/:category/benchmarks?date=ISO_DATE
  // Category benchmark statistics
  // Response: { category, date, benchmarks: {views: {avg, p50, p75, p90, articles}, ...} }

GET /api/analytics/top-articles?limit=N&days=N
  // Top performing articles
  // Response: { articles: [{post_id, title, views, shares, comments, category}] }

GET /api/analytics/export?format=csv&start=DATE&end=DATE
  // CSV export endpoint

Integration Strategy: 3 Approaches

  1. Hard reset to task/BIT-4619-gitea-actions-secrets
  2. Cherry-pick Phase 1 dashboard UI commits on top
  3. Update dashboard code to use real API routes instead of mocks
  4. Remove src/http/analytics-api.js (mock layer)
  5. Result: Single coherent branch with both backend + UI

Pros: Clean history, resolves merge conflicts proactively Cons: Loses Phase 1 commit history (recoverable in git reflog) Effort: 2-3 hours

Approach B: Selective Cherry-Pick

  1. Stay on current branch
  2. Cherry-pick analytics/* files from other branch
  3. Update dashboard routes to call real APIs
  4. Remove mock analytics-api.js
  5. Add database migrations and dependencies

Pros: Keeps current Phase 1 work, modular approach Cons: May have subtle merge conflicts Effort: 1-2 hours

Approach C: Plan & Coordinate

  1. Document integration requirements
  2. Leave both branches as-is for now
  3. Set up parallel validation
  4. Schedule dedicated integration run after approval

Pros: Zero risk, full visibility Cons: Delayed delivery Effort: 0.5 hours (planning only)


Merge Conflict Analysis

Attempted merge of task/BIT-4619-gitea-actions-secrets into task/BIT-5284-analytics-dashboard shows conflicts in:

  • package.json (dependencies: pg, csv exports)
  • .gitignore (database files)
  • .nycrc.json (test coverage config)
  • src/index.js (app initialization)
  • src/http/status-server.js (route mounting)
  • src/http/ui-handlers.js (dashboard routes)
  • src/store/article-log.js (metadata storage)
  • .gitea/workflows/test.yml (CI configuration)

Why conflicts exist: Both branches extended the same files with different features:

  • Real backend adds: database, migrations, analytics modules
  • Dashboard UI adds: new routes, mock APIs

Real Backend Files to Integrate

From task/BIT-4619-gitea-actions-secrets:

src/analytics/
├── MIGRATIONS.md
├── collector.js              # Engagement event collection
├── collector.test.js
├── csv-export.js             # CSV formatting
├── index.js                  # Module exports
├── integration.test.js       # Full pipeline tests
├── jobs.js                   # Aggregation scheduler
├── jobs.test.js
├── migrations/               # Database DDL
│   └── 001-schema.sql
├── routes.js                 # API route handlers
└── aggregation.js (likely)   # Data aggregation logic

src/store/
├── engagement-store.js       # Engagement event queries
├── article-store.js          # Article metadata queries
├── benchmark-store.js        # Category benchmark queries

package.json additions:
  - "pg": "^8.x"             # PostgreSQL driver
  - csv export dependencies

Dashboard Code Updates Required

Current (Phase 1): Using Mock API

// src/http/ui-handlers.js
const { getArticleEngagement, getCategoryBenchmarks, getTopArticles } = require('./analytics-api');

// pageAnalytics() calls mock functions:
const topArticles = getTopArticles(10);
const benchmarks = getCategoryBenchmarks('technology');

After Integration: Use Real Backend APIs

// Option 1: Move to async route handlers
if (req.method === 'GET' && pathname === '/ui/analytics') {
  // Fetch real data from API
  const topArticles = await fetch('/api/analytics/top-articles?limit=10');
  const html = pageAnalytics(theme, await topArticles.json());
  res.end(html);
}

// Option 2: Server-side data loading
const analyticsApi = require('../analytics');
const topArticles = analyticsApi.getTopArticles(10);
const html = pageAnalytics(theme, topArticles);

Testing Strategy

Current Tests

  • ✅ 10/10 analytics-api.js tests passing (mock data)
  • ✅ Dashboard page loads and renders (mock data)
  • ✅ CSV export generates valid CSV

Post-Integration Tests

  • Real database populated with sample engagement data
  • Dashboard queries real analytics tables
  • API responses match dashboard expectations
  • CSV export includes real data
  • Date range filtering works
  • Performance: Dashboard load < 2 seconds

Dependencies to Add

From package.json on other branch:

{
  "dependencies": {
    "pg": "^8.x",  // PostgreSQL client
    // ... others
  }
}

Database setup:

# Requires PostgreSQL running with schema from:
src/analytics/migrations/001-schema.sql

Option A (Rebase - Cleanest):

  1. Backup current branch: git branch task/BIT-5284-analytics-dashboard-backup
  2. Reset to real backend: git reset --hard task/BIT-4619-gitea-actions-secrets
  3. Cherry-pick dashboard UI commits: git cherry-pick a7a2fe4...a7a2fe4
  4. Update dashboard code to use real API endpoints
  5. Test integration
  6. Commit integration: feat(analytics): Integrate dashboard UI with real backend (BIT-5284)

Effort: 2-3 hours Risk: Low (git backup available if needed) Result: Clean, testable integration

Trigger: Approval from BIT-5162 owner or next heartbeat run


Files Reference

Dashboard UI (Current Branch)

  • src/http/analytics-api.js — WILL BE DELETED (mock layer)
  • src/http/analytics-api.test.js — WILL BE DELETED (mock tests)
  • src/http/ui-handlers.js — WILL BE UPDATED (add real API calls)
  • docs/ANALYTICS_DASHBOARD_PLAN.md — KEEP (design reference)

Real Backend (Other Branch)

  • src/analytics/* — WILL BE ADDED
  • src/store/engagement-store.js — WILL BE ADDED
  • src/store/article-store.js — WILL BE ADDED
  • package.json — WILL BE MERGED (pg dependency)

Decision

Recommend: Approach A (Rebase)

  • Cleanest integration
  • Minimal conflicts (sequential cherry-pick vs. merge)
  • Results in coherent branch ready for main merge
  • Can be executed in single focused run

Blocker Resolved? NO — still depends on BIT-5283 product decisions being implemented in real backend. Timeline: Backend completed (Apr 18), UI complete (Apr 23), integration ready (pending approval).