# sbktckp/clipency architecture

> Architecture diagram of the GitHub repository sbktckp/clipency, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sbktckp/clipency
- Repository: https://github.com/sbktckp/clipency

## Overview

#### Purpose and deployment
Clipency is a performance-based creator marketplace: brands fund CPM campaigns; clippers submit short-form content; staff review it; verified views drive creator earnings and brand spend. It is a static HTML/CSS/vanilla-JS frontend deployed to Vercel, backed by Supabase PostgreSQL, Auth, RPCs, and Edge Functions. Primary deployment/routing policy is in `vercel.json`; authenticated-route deployment settings also exist in `auth/vercel.json`.

#### Entry points and route topology
The public entry is `index.html`, with a mobile alternative at `landing-mobile/index.html`. The application’s authenticated surface begins at `auth/index.html`; its principal creator workspace/dashboard is `auth/dashboard.html` with logic in `auth/dashboard.js`. Vercel rewrites friendly root routes into `auth/`; root physical assets can override those rewrites, including duplicate root `clipency-*.js` files.

#### Client boot, identity, and authorization
Browser-side Supabase initialization is centralized in `auth/supabaseClient.js` (and a root counterpart at `supabaseClient.js`). Authentication entry protection and role-based destination selection are handled by `auth/clipency-auth-entry-guard.js`, `auth/access-control.js`, and `auth/role-router.js`. Roles form an explicit trust boundary: clippers and brands use product flows; admins receive full operational access; reviewers are restricted to submission decisions. The frontend must not be treated as the authorization boundary—privileged Supabase RPCs enforce staff/admin checks.

#### Creator workflow and marketplace
The creator-facing application combines dashboard, campaign discovery, account linking, submission, earnings, and reporting. The core UI/data orchestration is concentrated in `auth/clipency-functional-core.js`, while campaigns are surfaced through `auth/campaigns/index.html`, `auth/clipency-campaigns-classic.js`, and `auth/clipency-campaign-detail-bridge.js`. Submission is a discrete stage in `auth/clipency-clip-submit.js`; connected social accounts and payout views live under `auth/accounts/index.html` and `auth/payouts/index.html`. This flow reads/writes Supabase data through the browser client and RPC/query interfaces.

#### Staff operations and review boundary
Admin operations are a separate admin-OS shell, anchored by `auth/admin/index.html`, `auth/clipency-admin-os.js`, and `auth/clipency-admin-launch.js`. It covers campaign management, users, leads, connected accounts, payouts, logs, and review queues. Reviewers use the narrower review surface at `auth/review/index.html` and `auth/clipency-admin-review-actions.js`: approve/reject actions transition submitted clips into or out of the live/earning lifecycle. Admin and reviewer access should be verified server-side via Supabase staff gates and revoked public RPC execution.

#### Financial, analytics, and operational integrations
Payout/account status and dynamic earnings presentation are implemented client-side in `auth/clipency-wallet.js`, `auth/clipency-payouts-dynamic.js`, and `auth/clipency-stats-dynamic.js`, with authoritative financial state residing in Supabase. The README also identifies an external Next.js finance dashboard at `finance.clipency.in`, plus custom Supabase analytics views. Operations include a Telegram COO bot implemented outside this tree as Supabase Edge Functions, triggered through webhooks and scheduled via `pg_cron`/`pg_net`; its secrets remain in Supabase/Vercel rather than source.

#### Architectural constraints
The system is predominantly progressive/static pages enhanced by many independently loaded scripts, rather than a bundled SPA framework. UI panels in the admin OS must mount under `#cxos`, and dynamic data should use delegated listeners rather than inline handlers. Supabase query failures require `try/catch`; server database migrations are managed through Supabase migration tooling, not direct production SQL.

Main entry points: [`auth/clipency-auth-entry-guard.js`](https://github.com/sbktckp/clipency/blob/main/auth/clipency-auth-entry-guard.js) (Identity and role routing), [`auth/clipency-functional-core.js`](https://github.com/sbktckp/clipency/blob/main/auth/clipency-functional-core.js) (Creator workflow core), [`auth/supabaseClient.js`](https://github.com/sbktckp/clipency/blob/main/auth/supabaseClient.js) (Browser Supabase client), [`auth/index.html`](https://github.com/sbktckp/clipency/blob/main/auth/index.html) (Authenticated entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public entry"]
  node_vercel["Vercel routing<br/>deployment config<br/>[vercel.json]"]
  node_landing["Public landing<br/>static HTML<br/>[index.html]"]
  node_mobile_landing["Mobile landing<br/>static HTML<br/>[index.html]"]
end

subgraph group_client["Authenticated client"]
  node_auth_entry["Authenticated entry<br/>static HTML<br/>[index.html]"]
  node_identity_guards["Identity and role routing<br/>auth guard scripts"]
  node_supabase_browser["Browser Supabase client<br/>client SDK bootstrap<br/>[supabaseClient.js]"]
  node_creator_dashboard["Creator dashboard<br/>workspace page<br/>[dashboard.html]"]
  node_functional_core["Creator workflow core<br/>UI orchestration"]
  node_campaigns["Campaign discovery<br/>campaign UI<br/>[index.html]"]
  node_submission["Clip submission<br/>submission workflow"]
  node_accounts_payouts["Accounts and payouts<br/>creator finance UI<br/>[index.html]"]
end

subgraph group_staff["Staff operations"]
  node_admin_os["Admin OS<br/>staff operations shell<br/>[index.html]"]
  node_admin_core["Admin operations<br/>admin UI logic"]
  node_review_surface["Reviewer queue<br/>restricted review UI<br/>[index.html]"]
  node_review_actions["Review decisions<br/>staff action logic"]
end

subgraph group_backend["Supabase backend"]
  node_supabase[("Supabase platform<br/>PostgreSQL, Auth, RPCs")]
  node_staff_gates{{"Privileged RPC staff gates<br/>server authorization"}}
end

subgraph group_external["External operations"]
  node_edge_ops{{"Telegram COO automation<br/>Supabase Edge Functions"}}
  node_finance_dashboard["Finance dashboard<br/>external Next.js app"]
end

node_vercel -->|"serves root"| node_landing
node_vercel -->|"rewrites authenticated routes"| node_auth_entry
node_landing -->|"sign-in path"| node_auth_entry
node_mobile_landing -->|"sign-in path"| node_auth_entry
node_auth_entry -->|"boots"| node_identity_guards
node_identity_guards -->|"checks session"| node_supabase_browser
node_identity_guards -->|"routes clippers and brands"| node_creator_dashboard
node_identity_guards -->|"routes admins"| node_admin_os
node_identity_guards -->|"routes reviewers"| node_review_surface
node_creator_dashboard -->|"loads workflow UI"| node_functional_core
node_functional_core -->|"surfaces campaigns"| node_campaigns
node_functional_core -->|"submits clips"| node_submission
node_functional_core -->|"shows accounts and earnings"| node_accounts_payouts
node_functional_core -->|"queries and invokes RPCs"| node_supabase_browser
node_supabase_browser -->|"Auth, queries, RPCs"| node_supabase
node_admin_os -->|"loads operations"| node_admin_core
node_admin_core -->|"admin data and actions"| node_supabase_browser
node_review_surface -->|"loads decisions"| node_review_actions
node_review_actions -->|"transitions clip status"| node_supabase_browser
node_supabase -->|"executes privileged RPC checks"| node_staff_gates
node_staff_gates -.->|"authorizes admin operations"| node_admin_core
node_staff_gates -.->|"authorizes review decisions"| node_review_actions
node_supabase -->|"webhooks and scheduled triggers"| node_edge_ops
node_finance_dashboard -->|"reads finance and analytics state"| node_supabase

click node_vercel "https://github.com/sbktckp/clipency/blob/main/vercel.json"
click node_landing "https://github.com/sbktckp/clipency/blob/main/index.html"
click node_mobile_landing "https://github.com/sbktckp/clipency/blob/main/landing-mobile/index.html"
click node_auth_entry "https://github.com/sbktckp/clipency/blob/main/auth/index.html"
click node_identity_guards "https://github.com/sbktckp/clipency/blob/main/auth/clipency-auth-entry-guard.js"
click node_supabase_browser "https://github.com/sbktckp/clipency/blob/main/auth/supabaseClient.js"
click node_creator_dashboard "https://github.com/sbktckp/clipency/blob/main/auth/dashboard.html"
click node_functional_core "https://github.com/sbktckp/clipency/blob/main/auth/clipency-functional-core.js"
click node_campaigns "https://github.com/sbktckp/clipency/blob/main/auth/campaigns/index.html"
click node_submission "https://github.com/sbktckp/clipency/blob/main/auth/clipency-clip-submit.js"
click node_accounts_payouts "https://github.com/sbktckp/clipency/blob/main/auth/accounts/index.html"
click node_admin_os "https://github.com/sbktckp/clipency/blob/main/auth/admin/index.html"
click node_admin_core "https://github.com/sbktckp/clipency/blob/main/auth/clipency-admin-os.js"
click node_review_surface "https://github.com/sbktckp/clipency/blob/main/auth/review/index.html"
click node_review_actions "https://github.com/sbktckp/clipency/blob/main/auth/clipency-admin-review-actions.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_vercel,node_landing,node_mobile_landing toneBlue
class node_auth_entry,node_identity_guards,node_supabase_browser,node_creator_dashboard,node_functional_core,node_campaigns,node_submission,node_accounts_payouts toneAmber
class node_admin_os,node_admin_core,node_review_surface,node_review_actions toneMint
class node_supabase,node_staff_gates toneRose
class node_edge_ops,node_finance_dashboard toneIndigo
```

## Components

### Public entry

- [Vercel routing](https://github.com/sbktckp/clipency/blob/main/vercel.json): deployment config · Rewrites friendly routes into the authenticated surface. · `vercel.json`
- [Public landing](https://github.com/sbktckp/clipency/blob/main/index.html): static HTML · `index.html`
- [Mobile landing](https://github.com/sbktckp/clipency/blob/main/landing-mobile/index.html): static HTML · `landing-mobile/index.html`

### Authenticated client

- [Authenticated entry](https://github.com/sbktckp/clipency/blob/main/auth/index.html): static HTML · `auth/index.html`
- [Identity and role routing](https://github.com/sbktckp/clipency/blob/main/auth/clipency-auth-entry-guard.js): auth guard scripts · Selects product destinations by role; not the final authorization boundary. · `auth/clipency-auth-entry-guard.js`
- [Browser Supabase client](https://github.com/sbktckp/clipency/blob/main/auth/supabaseClient.js): client SDK bootstrap · `auth/supabaseClient.js`
- [Creator dashboard](https://github.com/sbktckp/clipency/blob/main/auth/dashboard.html): workspace page · `auth/dashboard.html`
- [Creator workflow core](https://github.com/sbktckp/clipency/blob/main/auth/clipency-functional-core.js): UI orchestration · Coordinates dashboard, earnings, account, and marketplace interactions. · `auth/clipency-functional-core.js`
- [Campaign discovery](https://github.com/sbktckp/clipency/blob/main/auth/campaigns/index.html): campaign UI · `auth/campaigns/index.html`
- [Clip submission](https://github.com/sbktckp/clipency/blob/main/auth/clipency-clip-submit.js): submission workflow · `auth/clipency-clip-submit.js`
- [Accounts and payouts](https://github.com/sbktckp/clipency/blob/main/auth/accounts/index.html): creator finance UI · `auth/accounts/index.html`

### Staff operations

- [Admin OS](https://github.com/sbktckp/clipency/blob/main/auth/admin/index.html): staff operations shell · Mounts operational panels under #cxos. · `auth/admin/index.html`
- [Admin operations](https://github.com/sbktckp/clipency/blob/main/auth/clipency-admin-os.js): admin UI logic · Manages campaigns, users, accounts, payouts, logs, and queues. · `auth/clipency-admin-os.js`
- [Reviewer queue](https://github.com/sbktckp/clipency/blob/main/auth/review/index.html): restricted review UI · `auth/review/index.html`
- [Review decisions](https://github.com/sbktckp/clipency/blob/main/auth/clipency-admin-review-actions.js): staff action logic · Approves or rejects submitted clips. · `auth/clipency-admin-review-actions.js`

### Supabase backend

- **Supabase platform**: PostgreSQL, Auth, RPCs · Authoritative marketplace, financial, identity, and authorization state.
- **Privileged RPC staff gates**: server authorization · Enforces staff/admin checks and restricts public RPC execution.

### External operations

- **Telegram COO automation**: Supabase Edge Functions · Webhook and scheduled operational automation using pg_cron and pg_net.
- **Finance dashboard**: external Next.js app

## Connections

- Vercel routing → Public landing: serves root
- Vercel routing → Authenticated entry: rewrites authenticated routes
- Public landing → Authenticated entry: sign-in path
- Mobile landing → Authenticated entry: sign-in path
- Authenticated entry → Identity and role routing: boots
- Identity and role routing → Browser Supabase client: checks session
- Identity and role routing → Creator dashboard: routes clippers and brands
- Identity and role routing → Admin OS: routes admins
- Identity and role routing → Reviewer queue: routes reviewers
- Creator dashboard → Creator workflow core: loads workflow UI
- Creator workflow core → Campaign discovery: surfaces campaigns
- Creator workflow core → Clip submission: submits clips
- Creator workflow core → Accounts and payouts: shows accounts and earnings
- Creator workflow core → Browser Supabase client: queries and invokes RPCs
- Browser Supabase client → Supabase platform: Auth, queries, RPCs
- Admin OS → Admin operations: loads operations
- Admin operations → Browser Supabase client: admin data and actions
- Reviewer queue → Review decisions: loads decisions
- Review decisions → Browser Supabase client: transitions clip status
- Supabase platform → Privileged RPC staff gates: executes privileged RPC checks
- Privileged RPC staff gates → Admin operations: authorizes admin operations
- Privileged RPC staff gates → Review decisions: authorizes review decisions
- Supabase platform → Telegram COO automation: webhooks and scheduled triggers
- Finance dashboard → Supabase platform: reads finance and analytics state
