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: document /docs, require RLS, fix README setup
spacesdrivece18835f06d1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex cae402b..94996c1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,14 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).## [Unreleased]+### Added++**Documentation site at `/docs`**+- Public documentation built into the app, laid out like a modern developer docs site: section tabs, grouped sidebar, "On this page" outline with scroll tracking, search with `/` or Ctrl K, previous and next links, copy-page and copy-code buttons, light and dark themes and a phone layout+- Separate paths for members (sign in, connect accounts, analytics, publishing, tracked content, troubleshooting) and administrators (Supabase, YouTube, Instagram, Cloudinary, Redis, backend and frontend deploys, GitHub automation, launch checklist)+- Reference pages for every environment variable, how scheduling works, the security model and common questions+- Links to the docs from the sign-in page, the user menu, the command palette and Settings+### Changed**Interface redesign in the Twiligent brand**@@ -19,10 +27,13 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).- Settings reorganised into labelled sections, with a theme picker- UI copy in sentence case, without exclamation marks; error messages say what to do next- Charts use the brand data-visualisation series in both themes+- Settings, Scheduled publishing now says who needs to set anything up: members nothing, administrators only the backend deploy. The GitHub backup guide is marked optional and for administrators, and starts folded### Fixed- The Worker cron and the GitHub Actions workflow could both publish the same scheduled post; posts are now claimed atomically+- README: `VITE_API_URL` example now ends in `/api`; the setup SQL now creates `tracked_posts` and turns on row level security for all four tables+- Buttons rendered as links no longer log a Base UI native-button warning### Removeddiff --git a/DECISIONS.md b/DECISIONS.mdindex 6a3c057..b78d18b 100644--- a/DECISIONS.md+++ b/DECISIONS.md@@ -557,3 +557,20 @@ Records every significant architectural decision, the alternatives considered, a**Trade-offs:**- Saving the GitHub section now clears any previously stored token. That token was never used.- The default contact address is specific to the original deployment; other self-hosters should set `VITE_ADMIN_EMAIL`.++---++## ADR-026: Public documentation inside the frontend at /docs++**Date:** 2026-10-13+**Status:** Accepted++**Decision:** User and self-hosting documentation lives in the React app under `frontend/src/docs/`, served at the public route `/docs` outside `ProtectedRoute`. Pages are JSX built from a small set of doc components (headings with anchors, callouts, steps, tables, code blocks). The navigation is defined once in `docs/nav.js`; `docs/routes.js` maps each slug to a lazily loaded named export, and a test checks the two stay in sync. Content is split into two audiences: members of an instance, who need nothing beyond signing in, and administrators, who run their own instance.++**Context:** People using a hosted instance were following GitHub and Supabase setup steps they could not complete, because step 2 needs the instance's Supabase secret key. Self-hosters had no single place that explained every key, where to get it and where it goes.++**Trade-offs:**+- No Markdown pipeline or docs framework: no new dependencies, and the docs share the app's tokens, theme and components. Writing pages needs JSX rather than Markdown.+- Docs ship with each frontend deploy, so they always match the deployed version, but cannot be updated without a frontend deploy.+- Each section is one code-split chunk, so the docs add nothing to the dashboard's initial load.+diff --git a/README.md b/README.mdindex cd876b0..6b6a833 100644--- a/README.md+++ b/README.md@@ -146,6 +146,10 @@ cd frontend && npm run devOpen [http://localhost:5173](http://localhost:5173) and sign up for an account, then go to **Accounts** to add your first YouTube channel or Instagram account.+The full documentation, including a step-by-step self-hosting guide that explains every key, is built into the app at `/docs` (for example [http://localhost:5173/docs](http://localhost:5173/docs)). It is public, so you can share the link with members before they sign in.++**Using someone else's Twiligent?** You need none of this. Sign in with the link you were given; the server, keys and scheduled publishing are already handled by the administrator.+---## Prerequisites@@ -208,8 +212,31 @@ create table scheduled_posts (scheduled_at timestamptz not null,data jsonb);++-- Tracked content table+create table tracked_posts (+ id text primary key,+ user_id uuid not null references auth.users(id) on delete cascade,+ account_id text references accounts(id) on delete set null,+ url text not null,+ label text not null default '',+ category text not null default '',+ content_type text not null default 'reddit',+ created_at timestamptz not null default now(),+ updated_at timestamptz not null default now(),+ data jsonb+);++-- Row level security: the backend uses the secret key, which bypasses it.+-- With no policies, the public publishable key cannot read or change any table.+alter table accounts enable row level security;+alter table settings enable row level security;+alter table scheduled_posts enable row level security;+alter table tracked_posts enable row level security;```+If you created the tables from an earlier version of this README, run the `tracked_posts` and `alter table` statements above as well. Then, in Supabase Authentication, turn off **Confirm email** unless you have set up an email provider, and turn off new signups once your team has accounts if the instance is private.+**4. Configure credentials**See [Configuration](#configuration) below.@@ -256,7 +283,7 @@ UPSTASH_REDIS_REST_TOKEN=...```VITE_SUPABASE_URL=https://your-project.supabase.coVITE_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...-VITE_API_URL=http://localhost:8787+VITE_API_URL=http://localhost:8787/api# Optional: who users contact for Instagram tester access and scheduling problems```diff --git a/claude.md b/claude.mdindex 2daa0df..87936f9 100644--- a/claude.md+++ b/claude.md@@ -97,6 +97,7 @@ docs/SECURITY.md Security model, key handling, isolationPERFORMANCE.md Caching strategy, edge optimization+frontend/src/docs/ Public user and self-hosting docs served at /docs (in-app, JSX)DECISIONS.md Architectural decision logCHANGELOG.md Version history and feature changesROADMAP.md Planned features and prioritiesdiff --git a/docs/architecture/OVERVIEW.md b/docs/architecture/OVERVIEW.mdindex 0165a3e..f535845 100644--- a/docs/architecture/OVERVIEW.md+++ b/docs/architecture/OVERVIEW.md@@ -109,6 +109,8 @@ See `docs/architecture/cloudflare/WORKERS.md` for the full list of required WorkFrontend env vars are documented in `docs/architecture/cloudflare/PAGES.md`.+The SPA also serves public documentation at `/docs` (no sign-in, no API calls). It is static JSX in `frontend/src/docs/`, code-split per section; see `docs/architecture/frontend/FEATURES.md`.+## Key Architectural Invariants1. **The Worker never receives binary file uploads.** Cloudinary handles file ingestion directly from the browser. The Worker only receives Cloudinary URLs.diff --git a/docs/architecture/database/SCHEMA.md b/docs/architecture/database/SCHEMA.mdindex 954489c..706d9c5 100644--- a/docs/architecture/database/SCHEMA.md+++ b/docs/architecture/database/SCHEMA.md@@ -2,12 +2,14 @@## Overview-Supabase (PostgreSQL) with three application tables. All tables include `user_id` (UUID) referencing `auth.users` to scope data per user.+Supabase (PostgreSQL) with four application tables. All tables include `user_id` (UUID) referencing `auth.users` to scope data per user.The backend uses the **service-role key** (bypasses Row Level Security) but enforces isolation by always appending `.eq('user_id', userId)` on user-scoped queries. The `userId` comes exclusively from the verified JWT - never from request input.Cron handlers (`processScheduledPosts`, `autoRefreshInstagramTokens`) intentionally omit the `userId` filter to operate across all users.+RLS must be enabled on all four tables, with no policies, so the public anon key cannot reach them. See `SECURITY.md`.+---## Table: `accounts`diff --git a/docs/architecture/database/SECURITY.md b/docs/architecture/database/SECURITY.mdindex 3ee7655..6048d54 100644--- a/docs/architecture/database/SECURITY.md+++ b/docs/architecture/database/SECURITY.md@@ -24,7 +24,24 @@ See `DECISIONS.md` ADR-011 for the full reasoning. Summary:| `SUPABASE_ANON_KEY` | Cloudflare Worker (`requireAuth` only) | Only `getUser(token)` - JWT verification || `VITE_SUPABASE_ANON_KEY` | Frontend browser | Supabase Auth (sign in, sign up, sign out, session management) |-The anon key has no meaningful permissions beyond what Supabase Auth allows. It cannot read or write application tables unless RLS policies explicitly permit it.+The anon key is public: it ships in the frontend bundle. It cannot read or write application tables **only if RLS is enabled on them**. With RLS disabled, Supabase's Data API lets anyone holding the anon key query the tables directly, bypassing the Worker.++## Required: RLS Enabled With No Policies++Every application table must have RLS enabled and no policies:++```sql+alter table accounts enable row level security;+alter table settings enable row level security;+alter table scheduled_posts enable row level security;+alter table tracked_posts enable row level security;+```++This denies the anon and authenticated roles everything, while the service-role key used by the Worker and the GitHub Actions scheduler still bypasses RLS. The frontend never queries tables directly (it uses Supabase only for Auth), so no policies are needed. Supabase's Table Editor flags any table with RLS disabled. The setup SQL in the README and on the `/docs/self-host/supabase` page includes these statements.++## Signups++Supabase Auth accepts signups from anyone who knows the project URL and anon key. Private instances should turn off new signups in Supabase Authentication settings once their members have accounts.**The service-role key must never appear in:**- Frontend codediff --git a/docs/architecture/frontend/FEATURES.md b/docs/architecture/frontend/FEATURES.mdindex c17acea..88d5e6f 100644--- a/docs/architecture/frontend/FEATURES.md+++ b/docs/architecture/frontend/FEATURES.md@@ -9,6 +9,12 @@ frontend/src/│ ├── MetricAreaChart.jsx <- Shared Recharts area chart for single-metric comparisons│ ├── ChartPanel.jsx <- Titled chart container with an empty state│ └── ImageLightbox.jsx <- Thumbnail that opens the full image in a Dialog+├── docs/ <- Public documentation at /docs (outside the feature tree: no auth, no AppContext)+│ ├── DocsLayout.jsx <- Header, tabs, sidebar, outline, search, previous and next+│ ├── components.jsx <- DocTitle, H2, H3, Callout, Steps, CodeBlock, Table, PathCards, Badge+│ ├── nav.js <- Tabs, groups and pages; the single source for navigation+│ ├── routes.js <- Slug to lazy page map; nav.test.js checks it matches nav.js+│ └── pages/ <- Overview, Use, SelfHost, Reference (one chunk each)├── features/│ ├── analytics/│ │ ├── channel/@@ -31,7 +37,8 @@ frontend/src/│ ├── publishing/│ │ └── UploadContent.jsx <- Instagram publish + scheduled post queue│ ├── settings/-│ │ └── Settings.jsx <- GitHub PAT and other settings+│ │ ├── Settings.jsx <- Theme, server keys, scheduling, platform requirements, links+│ │ └── SchedulingSetupGuide.jsx <- Optional GitHub backup scheduler steps for administrators│ ├── analytics/videos/│ │ ├── VideoExplorer.jsx <- YouTube video library with filtering│ │ └── useChannelVideos.js <- Loads every channel's videos; shared with Shorts@@ -134,9 +141,9 @@ Each page manages its own loading/data/error state. Pages do not write to `AppCo| Tracked Content | `/tracked-content` | Monitor Reddit posts and YouTube videos; add by URL, assign categories, bulk edit, per-row refresh || Tracked Category | `/tracked-content/category/:name` | Detailed per-category analytics; YouTube section (views, likes, comments, bar chart, table) and Reddit section (score, ratio, comments, bar chart, table) rendered separately || 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 |-| Settings | `/settings` | GitHub PAT and platform settings |+| Publish | `/upload` | Publish or schedule to Instagram, bulk upload, and the scheduled post queue |+| Settings | `/settings` | Theme, server key status, who sets up scheduling, the optional GitHub backup guide |+| Documentation | `/docs` | Public guides for members and administrators, and the environment variable reference |## Adding a New Featurediff --git a/docs/architecture/frontend/ROUTING.md b/docs/architecture/frontend/ROUTING.mdindex 0640924..68be732 100644--- a/docs/architecture/frontend/ROUTING.md+++ b/docs/architecture/frontend/ROUTING.md@@ -9,6 +9,7 @@ The app uses React Router v6 in `frontend/src/App.jsx`. The router uses `Browser| Path | Component | Notes ||---|---|---|| `/login` | `Login.jsx` | Public - redirects to `/` if already authenticated |+| `/docs`, `/docs/*` | `docs/DocsLayout.jsx` | Public documentation. Child routes come from `docsChildRoutes` in `docs/routes.js`; unknown paths redirect to `/docs` || `/` (layout) | `AppLayout` (inline) | Protected - redirects to `/login` if unauthenticated || `/` (index) | `Overview.jsx` | Default page after login || `/accounts` | `AccountManager.jsx` | Connect and remove accounts. `?add=1` opens the add flow; `?ig_connected` and `?ig_error` report the Instagram OAuth result |@@ -28,7 +29,7 @@ The app uses React Router v6 in `frontend/src/App.jsx`. The router uses `Browser## Auth Guard-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.+Auth protection is applied via a `<ProtectedRoute>` component wrapping the layout route in `App.jsx`. All child routes are protected. `/login` and `/docs` are the only public routes.## Lazy Loadingdiff --git a/docs/philosophy/SECURITY.md b/docs/philosophy/SECURITY.mdindex a86b7aa..89bc431 100644--- a/docs/philosophy/SECURITY.md+++ b/docs/philosophy/SECURITY.md@@ -4,7 +4,7 @@| Credential | Where stored | Who reads it | Exposed to client? ||---|---|---|---|-| Supabase anon key | `VITE_SUPABASE_ANON_KEY` (env var in frontend build) | Frontend (Supabase JS auth) | **Yes - intentionally public** |+| Supabase anon key | `VITE_SUPABASE_ANON_KEY` (env var in frontend build) | Frontend (Supabase JS auth) | **Yes - intentionally public**, which is why RLS must be enabled on every application table (see `docs/architecture/database/SECURITY.md`) || Supabase service role key | Worker secret | Worker only | **Never** || Instagram App ID | Worker secret | Worker only | **Never** || Instagram App Secret | Worker secret | Worker only | **Never** |diff --git a/docs/workflows/SCHEDULING_SETUP.md b/docs/workflows/SCHEDULING_SETUP.mdindex 0a55742..eb0f7b0 100644--- a/docs/workflows/SCHEDULING_SETUP.md+++ b/docs/workflows/SCHEDULING_SETUP.md@@ -1,5 +1,7 @@# Set Up Your Own Scheduling With GitHub+> **Who this is for:** the administrator of a Twiligent instance. Step 2 needs the secret key of the instance's Supabase project. If you only sign in to someone else's Twiligent, you need none of this: the server already publishes your scheduled posts. This backup is optional even for administrators; the Worker cron publishes on its own once the backend is deployed. The public docs cover the same steps at `/docs/self-host/github`.+GitHub can check your scheduled Instagram posts every 15 minutes and publish the ones that are due, for free. It runs alongside the server's own scheduler as a backup, so posts still go out if the server is paused. You set it up once. It takes about 5 minutes.The same steps are in the app under **Settings, Scheduled publishing**, where typing your GitHub username turns every step into a direct link.