Commit graph

231 commits

Author SHA1 Message Date
b06d285922 test: implement project-wide dynamic test growth guard 2026-02-15 22:54:45 +00:00
153e4a2d5f fix(monitoring): regenerate importMap with monitoring components
The importMap was missing MonitoringNavLinks and MonitoringDashboardView
entries, causing the /admin/monitoring page to render blank.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 01:24:51 +00:00
086dd269fa fix(monitoring): address code review findings
- SSE stream: detect client disconnect via request.signal to stop
  polling loop (prevents wasted DB queries after tab close)
- AlertEvaluator: split shouldFire/recordFired so cooldown is only
  recorded after successful dispatch (prevents alert suppression
  on dispatch failure)
- SnapshotCollector: cache payload instance (avoid re-importing on
  every 60s tick)
- Alert acknowledge: validate alertId type (string|number)
- Logs search: add 300ms debounce to prevent query-per-keystroke
- Replace remaining `any` cast with Record<string, unknown>

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 01:02:50 +00:00
96b8cca9d6 docs: update PROJECT_STATUS.md and CLAUDE.md with monitoring dashboard
- Mark Monitoring & Alerting Dashboard as completed in roadmap
- Add monitoring subsystem to CLAUDE.md subsystems table
- Add 4 monitoring collections to collections list (55+ → 59+)
- Add monitoring dashboard URL
- Add changelog entry for 15.02.2026

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:53:52 +00:00
151b96d641 fix(monitoring): cache payload instance in logger to prevent flaky tests
The fire-and-forget dynamic import chain (3 awaits) was racing with
test flush timeouts. Caching the resolved payload instance fixes both
the flakiness and eliminates per-call import overhead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:52:17 +00:00
dd73162035 feat(monitoring): add monitoring dashboard UI with 5 tabs, SSE connection, and shared components
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:45:41 +00:00
5f38136b95 feat(monitoring): add REST API endpoints for monitoring dashboard
Add 7 API route handlers for the monitoring system:
- GET /api/monitoring/health - system health overview
- GET /api/monitoring/services - individual service status checks
- GET /api/monitoring/performance - performance metrics with period filter
- GET /api/monitoring/alerts - paginated alert history with severity filter
- POST /api/monitoring/alerts/acknowledge - acknowledge alerts
- GET /api/monitoring/logs - paginated logs with level/source/date filters
- GET /api/monitoring/snapshots - time-series data for charts

All endpoints require super-admin authentication.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:37:01 +00:00
0615b22188 feat(monitoring): add snapshot collector to queue worker
Periodic metric collection running in the queue-worker PM2 process.
Collects system metrics every 60s (configurable), stores them in
MonitoringSnapshots, and evaluates alert rules against each snapshot.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:34:28 +00:00
d252ed321a feat(monitoring): add retention policies for monitoring collections
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:33:43 +00:00
0ff8b5c9d8 feat(monitoring): add structured monitoring logger
Fire-and-forget logger that writes to the monitoring-logs collection
with log level filtering via MONITORING_LOG_LEVEL env var. Falls back
to console output when Payload is not yet initialized.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:32:09 +00:00
97c8f32967 feat(monitoring): add alert evaluator with cooldown and multi-channel dispatch
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:30:21 +00:00
dc14c5dbc7 feat(monitoring): add performance tracker with ring buffer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:29:58 +00:00
4907371715 feat(monitoring): add monitoring service with system health and service checks
Implements checkSystemHealth (CPU, memory, disk, load), service checks
(Redis, PostgreSQL, PgBouncer, SMTP, queues, OAuth, cron), and the
collectMetrics aggregator that gathers all metrics in parallel.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:26:28 +00:00
ee981c32bc feat(monitoring): add database migration for 4 monitoring collections
Creates tables, enums, and indexes for monitoring_snapshots,
monitoring_logs, monitoring_alert_rules, and monitoring_alert_history.
Includes hasMany select tables and the critical
payload_locked_documents_rels columns.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:19:35 +00:00
34becc8f49 feat(monitoring): add 4 monitoring collections (Snapshots, Logs, AlertRules, AlertHistory)
Add monitoring access controls to centralized access module and create
four new system-wide collections for the monitoring dashboard:
- MonitoringSnapshots: historical system metrics for trend charts
- MonitoringLogs: structured logs for business events (WORM)
- MonitoringAlertRules: configurable alert rule definitions
- MonitoringAlertHistory: alert log with acknowledge support

Collections are registered in payload.config.ts but intentionally
excluded from multi-tenant plugin since they are system-wide.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:14:53 +00:00
214e2ddde8 feat(monitoring): add shared types for monitoring system
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:11:33 +00:00
c7fd95d3da docs: add monitoring dashboard implementation plan (31 tasks, 5 phases)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:01:16 +00:00
15bdd66eb6 docs: add monitoring & alerting dashboard design
Event-driven architecture with SSE real-time updates, 5-tab dashboard
(System Health, Services, Performance, Alerts, Logs), 4 new collections,
and integration with existing alert-service.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 23:53:25 +00:00
a0ef957a7f docs: add YouTube Operations Hub documentation
Add comprehensive YouTube feature documentation covering 9 collections,
12 custom API endpoints, 3 cron jobs, admin views, services, hooks,
and access control across CLAUDE.md, CLAUDE_REFERENCE.md, and
API_ANLEITUNG.md.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 18:02:59 +00:00
7446318bf3 docs: update Redis auth, PM2 config, and eviction policy documentation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 17:56:16 +00:00
d50d3cd208 feat: add update-contracts.sh for type extraction workflow
Script extracts types from payload-types.ts, updates the
payload-contracts repo, builds to verify, and optionally pushes.

Usage: ./scripts/update-contracts.sh [--push]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 17:53:20 +00:00
e904f0949b fix(queue): resolve queue-worker crash-loop via Redis auth and PM2 config
Redis requires authentication but IORedis connections were not passing a
password, causing immediate NOAUTH failures and a PM2 crash-loop (1900+
restarts). Additionally, the PM2 config used `npx` as the script entry
which caused instability.

- Add REDIS_PASSWORD support to queue-service.ts and redis.ts
- Change PM2 script from npx wrapper to direct tsx CLI entry point
- Add explicit exec_mode: 'fork' to prevent cluster mode issues

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 17:46:54 +00:00
ed07e15670 fix: remove .js extensions from TypeScript imports
Fixes Next.js build failure caused by .js extensions in relative
imports within VideoMetricsSyncService and ChannelMetricsSyncService.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 17:24:43 +00:00
692498871c feat(youtube): register content calendar as admin view
Adds the Content Calendar view at /admin/content-calendar and
integrates it into the YouTube Dashboards nav group.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 17:18:12 +00:00
5394f628e4 feat(youtube): add FullCalendar content calendar component
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:53:30 +00:00
95079ec652 feat(youtube): add content calendar API with conflict detection
GET endpoint returns FullCalendar-compatible events with schedule
conflict detection. PATCH endpoint supports drag & drop rescheduling
with published-video protection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:52:17 +00:00
2466745e7f feat(youtube): add conflict detection service
Detect scheduling conflicts in the content calendar including same-day
longform collisions, weekly frequency limit violations, and weekend
scheduling warnings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:50:24 +00:00
d8118528db feat(youtube): add team capacity planning API
Adds a capacity calculator utility and API endpoint that computes
workload utilization for team members with YouTube roles.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:49:55 +00:00
2ea42ca404 chore: add FullCalendar dependencies
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:49:32 +00:00
1f63ae14f4 docs: optimize CLAUDE.md for context window efficiency (1493→401 lines)
Extract detailed subsystem documentation into docs/CLAUDE_REFERENCE.md.
CLAUDE.md is loaded into every AI conversation - reducing it by 73% saves
~38KB of context window tokens per session while keeping all essential info.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:46:52 +00:00
8ae5841cc1 feat(youtube): add auto status transition hook
Automatically transitions YouTube content status when conditions are met
(e.g., upload_scheduled -> published when videoId is present) and sends
notifications to assigned users.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:42:25 +00:00
9e7b433cd0 feat(youtube): add comparison, trends, ROI analytics
Add analytics helper functions (calculateComparison, calculateTrends,
calculateROI) and extend the analytics API route with three new tabs
for video metric comparison, trend analysis, and ROI calculation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:37:51 +00:00
e4fea9db4c feat(youtube): add ROI cost fields to YouTubeContent
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:35:57 +00:00
ce4c21fd0a feat(youtube): add upload worker and API route
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:34:28 +00:00
e6ef78a08a feat(youtube): register upload worker in queue startup
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:33:52 +00:00
6cc3011804 feat(youtube): add VideoUploadService
Implements a service that uploads videos to YouTube via the Data API v3.
Resolves OAuth credentials from social-accounts, reads media files from
disk, and handles scheduled publishes by setting privacyStatus to private
with a publishAt timestamp. Includes 12 unit tests covering successful
uploads, scheduled publishing, credential/media validation, and API errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:31:25 +00:00
fb4d5a8fe5 feat(youtube): add upload queue job definition
Add YOUTUBE_UPLOAD to QUEUE_NAMES and create the job definition
with enqueue and status functions. Uses 2 retry attempts instead
of the default 3 since uploads are resource-intensive.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:30:07 +00:00
289b69380f feat(youtube): add reply thread import to comment sync
Add getCommentReplies method to YouTubeClient for fetching reply threads
via the YouTube comments.list API. Modify CommentsSyncService to import
reply threads during sync, storing them as type 'reply' with
parentInteraction relationship in community-interactions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:28:33 +00:00
13507d1361 feat(youtube): add metrics sync cron endpoints
Add two cron endpoints for automated YouTube metrics syncing:
- /api/cron/youtube-metrics-sync (every 6 hours): syncs video performance
  metrics (views, likes, comments) for all active channels
- /api/cron/youtube-channel-sync (daily at 04:00 UTC): syncs channel-level
  statistics (subscribers, total views, video count)

Both endpoints follow the established cron pattern with CRON_SECRET auth,
concurrent execution guards, HEAD monitoring, and structured logging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:27:05 +00:00
5ddcd5ab45 feat(youtube): add VideoMetricsSyncService for batch metrics sync
Syncs video performance metrics (views, likes, comments) from YouTube
API to YouTubeContent.performance fields. Supports batch processing
with 50-video API limit, credential validation, and per-batch error
handling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:25:12 +00:00
b52e668ecb feat(youtube): add ChannelMetricsSyncService
Syncs channel-level statistics (subscribers, views, video count) from
YouTube Data API to YouTubeChannels.currentMetrics fields for all active
channels. Follows the same credential-loading pattern as existing sync
services.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:24:57 +00:00
065e75b014 feat(youtube): add getVideoStatistics to YouTubeClient
Add batch video statistics retrieval method that fetches view counts,
like counts, and comment counts for up to 50 videos per request.
Includes unit tests covering normal operation, empty input, missing
statistics defaults, null API response, and error propagation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:21:33 +00:00
097bc5225c feat(youtube): add upload and analytics OAuth scopes
Add youtube.upload and yt-analytics.readonly scopes to enable video
uploading and analytics data retrieval in the YouTube Operations Hub.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 13:19:23 +00:00
2718dea356 docs: add YouTube Operations Hub extensions implementation plan
22-task implementation plan covering 4 phases:
- Phase 1: YouTube API Integration (10 tasks)
- Phase 2: Analytics Dashboard (3 tasks)
- Phase 3: Workflow Automation (3 tasks)
- Phase 4: Content Calendar (6 tasks)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 12:45:42 +00:00
2e32a958bc docs: add YouTube Operations Hub extensions design
Design for 4 extensions: YouTube API Integration (metrics sync,
video upload, comment import), Analytics Dashboard (comparison,
trends, ROI), Workflow Automation (auto-status, deadline reminders,
capacity planning), Content Calendar (FullCalendar, drag & drop,
conflict detection).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 12:38:37 +00:00
8907653744 docs: add YouTube thumbnail download to documentation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 12:33:31 +00:00
6ffe6e756c feat: add bulk YouTube thumbnail download endpoint
POST /api/youtube/thumbnails/bulk (Super-Admin only)
Supports ?dryRun=true for preview. Downloads sequentially with 500ms delay.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 12:32:31 +00:00
2872f32635 feat: auto-download YouTube channel images on create/update
Adds channelThumbnailUrl field to store YouTube API URL.
afterChange hook downloads image to Payload Media when branding.logo is empty.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 12:30:48 +00:00
a09f6abc3d feat: auto-download YouTube thumbnails on content create/update
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 12:29:44 +00:00
52a6bce815 feat: add downloadAndUploadImage utility for YouTube thumbnails
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 12:29:04 +00:00