Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
docs: update all docs for Reddit analytics and global posts page
spacesdrivee9d5909e58ec
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bfc5dc5..cd45ad8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,30 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).### Added+**Reddit Analytics improvements**+- Karma separated into its own dedicated card in `RedditAnalytics.jsx` (total, post, comment, awardee karma); previously karma was mixed into the profile header+- KPI cards: Posts Fetched, Total Score, Total Comments, Awards Received - replacing the previous generic set+- Awards Received (`total_awards_received` from Reddit API) added to per-post data and analytics computation (`totalAwards`, `avgAwards`)+- Score Breakdown card now shows 6 metrics: avg score, median score, best single post, avg upvote ratio, total comments, avg comments+- Section labels updated: "Post Activity" to "Posting Frequency", "Score Distribution" to "Score Breakdown", "Performance Scores" to "Performance Indicators"++**Reddit Posts global page**+- `frontend/src/features/analytics/reddit/RedditPostsAll.jsx` - new page at `/reddit-posts` aggregating posts across all connected Reddit accounts using `Promise.allSettled`+- Account selector dropdown (shown only when 2+ Reddit accounts connected)+- Subreddit filter, text search, and sort by score, comments, or date+- Three summary StatCards: Posts Shown, Combined Score, Total Comments+- Empty state when no Reddit accounts connected+- Route `/reddit-posts` added to `App.jsx` before the existing `/reddit-posts/:id` route+- "Reddit Posts" nav item added to Analytics section of Sidebar++**Overview karma fix**+- Reddit karma no longer counted in Total Audience KPI (karma is not subscribers/followers)+- Audience Comparison bar chart and Audience Share pie chart now exclude Reddit accounts+- Content leaderboard and All Accounts table now exclude Reddit accounts+- Reddit accounts display a dedicated karma card (total, post, comment karma per account) below the main KPI row++### Fixed+**Reddit Application-Only OAuth**- Added `REDDIT_CLIENT_ID` and `REDDIT_CLIENT_SECRET` optional Worker secrets for application-only OAuth (client credentials grant)- `getAppOnlyToken(env)` in `backend/services/reddit.js` - exchanges client credentials for a bearer token via `POST /api/v1/access_token` with `grant_type=client_credentials`; token cached in isolate memory with expirydiff --git a/DECISIONS.md b/DECISIONS.mdindex 03703b0..0edd2a7 100644--- a/DECISIONS.md+++ b/DECISIONS.md@@ -334,3 +334,45 @@ Records every significant architectural decision, the alternatives considered, a- If `REDDIT_ENCRYPTION_KEY` is lost, all stored Reddit passwords are unrecoverable - users would need to re-add their accounts with a new password- A compromised Worker environment (leaked `REDDIT_ENCRYPTION_KEY` + DB access) allows decryption of all stored passwords- Reddit's unofficial login API (`ssl.reddit.com/api/login`) is not a documented endpoint and could change without notice++---++## ADR-015: Reddit karma excluded from audience metrics in Overview++**Date:** 2026-07-11+**Status:** Accepted++**Decision:** Reddit karma (total, post, comment) is displayed in a separate card on the Overview dashboard and is never added to the Total Audience count or included in the Audience Comparison or Audience Share charts.++**Alternatives considered:**+- Include karma as an "audience proxy" alongside YouTube subscribers and Instagram followers++**Reasoning:**+- Karma is an engagement/reputation score that accumulates over a Reddit account's lifetime; it has no relationship to audience size+- A user with 100k karma and zero followers is categorically different from a YouTube channel with 100k subscribers+- Mixing them into a single "Total Audience" KPI produces a number that is meaningless and actively misleading+- Reddit's own platform does not expose a follower or subscriber count for user profiles via their API++**Trade-offs:**+- Reddit accounts appear less prominently in the Overview since they have no audience bar in the comparison chart; this is the correct representation of what the data means++---++## ADR-016: Global Reddit Posts page uses Promise.allSettled across all accounts++**Date:** 2026-07-11+**Status:** Accepted++**Decision:** The `/reddit-posts` page fetches posts from all connected Reddit accounts concurrently using `Promise.allSettled`, then merges and displays them in a single table. Failures from individual accounts show a toast but do not block posts from other accounts from displaying.++**Alternatives considered:**+- Sequential fetches: simpler but slower; one slow account blocks all others+- Single-account page only: matches YouTube Videos and Shorts pattern but Reddit accounts are more likely to be used across separate communities++**Reasoning:**+- `Promise.allSettled` (not `Promise.all`) ensures a failed account does not reject the entire request+- Matches the established `VideoExplorer` pattern for multi-channel YouTube+- Users tracking multiple Reddit identities benefit from a unified view; per-account pages still exist for deep analysis++**Trade-offs:**+- All Reddit account post lists are fetched in parallel on page mount, which may trigger more API calls than a single-account view; mitigated by Redis cache on each individual account endpointdiff --git a/docs/architecture/OVERVIEW.md b/docs/architecture/OVERVIEW.mdindex 14e908b..5233e2c 100644--- a/docs/architecture/OVERVIEW.md+++ b/docs/architecture/OVERVIEW.md@@ -1,4 +1,4 @@-# Architecture Overview+# Architecture Overview## System Topology@@ -29,6 +29,7 @@│ Supabase │ │ Upstash │ │ External APIs ││ Postgres │ │ Redis │ │ ├── YouTube Data API v3 ││ │ │ (cache) │ │ ├── Instagram Graph API v25 │+│ │ │ (cache) │ │ ├── Reddit Public JSON API ││ tables: │ │ │ │ └── Cloudinary Upload API ││ accounts │ │ keys: │ └──────────────────────────────────────┘│ settings │ │ videos: │diff --git a/docs/architecture/data-flows/ANALYTICS.md b/docs/architecture/data-flows/ANALYTICS.mdindex 20c9f67..4fda2a8 100644--- a/docs/architecture/data-flows/ANALYTICS.md+++ b/docs/architecture/data-flows/ANALYTICS.md@@ -123,6 +123,86 @@ InstagramAnalytics.jsx mounts -> api.getIGAnalytics(id)}```+## Reddit Analytics Flow++```+User navigates to /reddit/:id+ │+ ▼+RedditAnalytics.jsx mounts -> api.getRedditAnalytics(id)+ -> GET /api/accounts/:id/reddit-analytics+ │+ ▼+ Worker: redditRouter+ 1. getAccountById(supabase, id, userId) - verify ownership+ 2. redis cache check: key reddit:{userId}:{accountId}+ -> cache hit: return immediately+ -> cache miss: continue+ 3. Fetch from Reddit public JSON API (with optional session cookie):+ a. GET /user/{username}/about.json+ -> profile: totalKarma, postKarma, commentKarma, awardeeKarma, iconUrl, createdAt+ b. Paginate /user/{username}/submitted.json?limit=100+ -> up to 10 pages x 100 items = up to 1000 posts+ 4. computeRedditAnalytics(profile, posts)+ -> score stats, subreddit breakdown, timing analysis+ 5. Cache result in Redis+ 6. Return { profile, analytics }+```++### computeRedditAnalytics() Output (partial)++```js+{+ fetchedPosts: 100,+ totalScore: 45000,+ avgScore: 450,+ medianScore: 120,+ totalComments: 3200,+ avgComments: 32,+ avgUpvoteRatio: 91.4, // percentage+ totalAwards: 18,+ avgAwards: 0.18,+ topPosts: [ /* top 10 by score */ ],+ worstPosts: [ /* bottom 5 by score */ ],+ subredditBreakdown: [+ { subreddit: 'programming', posts: 40, totalScore: 20000, avgScore: 500, avgComments: 45 },+ // ...+ ],+ mediaTypeDistribution: { text: 60, link: 25, image: 10, video: 5 },+ postsByDayOfWeek: [ /* 7 entries with avgScore and post count per day */ ],+ postsByHour: [ /* 24 entries with avgScore per hour */ ],+ bestPostingDay: 'Tuesday',+ bestPostingHour: '14:00',+ monthlyBreakdown: [+ { month: '2025-06', posts: 8, score: 3600, avgScore: 450 },+ // ...+ ],+ postsLast7Days: 2,+ postsLast30Days: 8,+ postsLast90Days: 24,+ postFrequency: { perWeek: 1.8, perMonth: 7.6 },+ viralityScore: 4.2, // peak / average score ratio+ consistencyScore: 68, // 0-100, higher = more uniform performance+}+```++### Per-post fields (in posts array and topPosts)++```js+{+ id, title, subreddit, subredditPrefixed,+ score, upvoteRatio, numComments,+ url, permalink, thumbnail,+ mediaType, // 'text' | 'image' | 'video' | 'link'+ isSelf, isVideo, isNsfw,+ createdAt, // ISO string+ flair,+ awardsCount, // total_awards_received from Reddit API+}+```++Note: Reddit disabled `view_count` from their API in December 2018. The field always returns `null` regardless of authentication method. Views are not available for Reddit posts.+## Overview Dashboard (Cross-Account)```@@ -136,3 +216,5 @@ Overview.jsx uses accounts from AppContext```The Overview doesn't fetch fresh analytics - it uses the cached account metadata (subscriber counts, view counts) already in `AppContext.accounts`. Deep per-account analytics (video lists, engagement rates) are only fetched when the user navigates to a specific account page.++Reddit accounts are excluded from the audience totals, audience comparison chart, and audience share pie chart. Karma is not equivalent to subscribers or followers - it is an engagement/reputation metric. Reddit accounts get their own karma summary card in the Overview showing totalKarma, postKarma, and commentKarma. The audience charts and leaderboard tables only include YouTube and Instagram accounts.diff --git a/docs/architecture/frontend/FEATURES.md b/docs/architecture/frontend/FEATURES.mdindex 33d6960..91b4111 100644--- a/docs/architecture/frontend/FEATURES.md+++ b/docs/architecture/frontend/FEATURES.md@@ -10,18 +10,22 @@ frontend/src/│ │ │ └── ChannelAnalytics.jsx <- YouTube channel analytics│ │ ├── instagram/│ │ │ └── InstagramAnalytics.jsx <- Instagram account analytics-│ │ └── overview/-│ │ └── Overview.jsx <- Cross-platform aggregate dashboard+│ │ ├── overview/+│ │ │ └── Overview.jsx <- Cross-platform aggregate dashboard+│ │ └── reddit/+│ │ ├── RedditAnalytics.jsx <- Reddit account analytics (karma, scores, subreddits)+│ │ ├── RedditPosts.jsx <- Per-account post explorer+│ │ └── RedditPostsAll.jsx <- Global post explorer (all Reddit accounts)│ ├── accounts/-│ │ └── Accounts.jsx <- Add/remove connected accounts-│ ├── publish/-│ │ └── Publish.jsx <- Instagram immediate publish-│ ├── schedule/-│ │ └── Schedule.jsx <- Instagram scheduled posts queue+│ │ └── AccountManager.jsx <- Add/remove connected accounts+│ ├── publishing/+│ │ └── UploadContent.jsx <- Instagram publish + scheduled post queue│ ├── settings/│ │ └── Settings.jsx <- GitHub PAT and other settings│ └── videos/-│ └── VideoExplorer.jsx <- YouTube video library with filtering+│ ├── VideoExplorer.jsx <- YouTube video library with filtering+│ ├── ShortsExplorer.jsx <- YouTube Shorts-filtered view+│ └── ReelsExplorer.jsx <- Instagram Reels-filtered view```## Feature Conventions@@ -71,8 +75,9 @@ Each page manages its own loading/data/error state. Pages do not write to `AppCo| Accounts | `/accounts` | Connect/disconnect social accounts (YouTube, Instagram, Reddit) || Channel Analytics | `/channel/:id` | YouTube analytics for one channel || Instagram Analytics | `/instagram/:id` | Instagram analytics for one account |-| Reddit Analytics | `/reddit/:id` | Reddit analytics for one account - karma, post scores, subreddit breakdown, timing |-| Reddit Posts | `/reddit-posts/:id` | Searchable and sortable post list for a Reddit account |+| Reddit Analytics | `/reddit/:id` | Reddit analytics for one account - karma breakdown, score timeline, post type distribution, day/hour analysis, subreddit breakdown, top posts |+| Reddit Posts (global) | `/reddit-posts` | Combined post explorer across all Reddit accounts with account and subreddit filters |+| Reddit Posts (per account) | `/reddit-posts/:id` | Searchable and sortable post list for a single Reddit account || Video Explorer | `/videos/:id` | YouTube video library with search and sort || Publish | `/publish/:id` | Publish a post to Instagram immediately || Schedule | `/schedule/:id` | View and manage the scheduled post queue |diff --git a/docs/architecture/frontend/ROUTING.md b/docs/architecture/frontend/ROUTING.mdindex a93d615..2454e39 100644--- a/docs/architecture/frontend/ROUTING.md+++ b/docs/architecture/frontend/ROUTING.md@@ -15,7 +15,8 @@ The app uses React Router v6 in `frontend/src/App.jsx`. The router uses `Browser| `/channel/:id` | `ChannelAnalytics.jsx` | `:id` = account.id for YouTube accounts || `/instagram/:id` | `InstagramAnalytics.jsx` | `:id` = account.id for Instagram accounts || `/reddit/:id` | `RedditAnalytics.jsx` | `:id` = account.id for Reddit accounts |-| `/reddit-posts/:id` | `RedditPosts.jsx` | `:id` = account.id; filterable/sortable post explorer |+| `/reddit-posts` | `RedditPostsAll.jsx` | Combined post explorer across all connected Reddit accounts |+| `/reddit-posts/:id` | `RedditPosts.jsx` | `:id` = account.id; filterable/sortable post explorer for one account || `/videos/:id` | `VideoExplorer.jsx` | `:id` = account.id for YouTube accounts || `/publish/:id` | `Publish.jsx` | `:id` = account.id for Instagram accounts || `/schedule/:id` | `Schedule.jsx` | `:id` = account.id for Instagram accounts |@@ -23,21 +24,7 @@ The app uses React Router v6 in `frontend/src/App.jsx`. The router uses `Browser## Auth Guard-There is no dedicated `<ProtectedRoute>` component. Auth protection is applied inline in the layout route:--```jsx-// App.jsx-function AppLayout() {- const { user, loading } = useAuthContext();-- if (loading) return <LoadingScreen />;- if (!user) return <Navigate to="/login" replace />;-- return <SidebarLayout />;-}-```--All routes nested under `AppLayout` are protected. `/login` is the only public route.+Auth protection is applied via a `<ProtectedRoute>` component wrapping the layout route in `App.jsx`. All child routes are protected. `/login` is the only public route.## Lazy Loading