# SaaS Analytics (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-saas-analytics` · version 1.0.0 · block · pro (All-Access)
- category: App screens
- build: Base UI (one set of files; its dependencies follow the build)
- install (this build): `npx shadcn@latest add @beautiful-ui-pro/lumen-saas-analytics`
- npm dependencies: none
- registry dependencies: utils, @beautiful-ui-pro/lumen-saas-screens, @beautiful-ui-pro/lumen-customer-intelligence, @beautiful-ui-pro/lumen-sidebar, @beautiful-ui/lumen-tooltip, @beautiful-ui/lumen-chart, @beautiful-ui-pro/lumen-area-chart, @beautiful-ui-pro/lumen-bar-chart, @beautiful-ui-pro/lumen-cell-bars, @beautiful-ui-pro/lumen-flow-funnel, @beautiful-ui-pro/lumen-orbit, @beautiful-ui-pro/lumen-trend, @beautiful-ui-pro/lumen-metric-header, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-saas-analytics
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

A runnable SaaS app built from Lumen: a collapsible sidebar with six views, Overview, Customers and Revenue under Analytics, and Team, Billing and Settings under Workspace. The analytics views read one set of customers with weekly MRR, so every page agrees; the Customers view is the Customer Intelligence workspace, and the workspace views are SaaS Screens, wired to your backend through the team, billing and settings props. No router needed: map view and onViewChange onto yours, or drop it on one page.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: none beyond React.
- Files: `components/ui/lumen/workspaces/saas-analytics.tsx`; shared code: `lib/beautiful-ui/lumen/saas-analytics-model.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-saas-screens`, `lumen-customer-intelligence`, `lumen-sidebar`, `lumen-tooltip`, `lumen-chart`, `lumen-area-chart`, `lumen-bar-chart`, `lumen-cell-bars`, `lumen-flow-funnel`, `lumen-orbit`, `lumen-trend`, `lumen-metric-header`, `lumen-foundation`.
- Builds: one set of files for both, but its dependencies come in Base UI and Radix builds. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `SaasAnalyticsApp`, and every exported type.
- CSS: the install merges this item's rules (the registry `css` field) into your global stylesheet, in `@layer components`, and adds the lumen foundation (tokens, keyframes, motion levels) once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--lumen-*` custom properties (`--lumen-accent`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-focus`, `--lumen-good`, `--lumen-good-text`, `--lumen-hairline`, `--lumen-ink`, `--lumen-muted-ink`, `--lumen-series-1`, `--lumen-series-2`, `--lumen-series-3`, `--lumen-series-4`, `--lumen-series-5`, `--lumen-series-6`, `--lumen-warn`, `--lumen-warn-text`); this item's CSS also reads `--lumen-font-mono`, `--lumen-font-sans`, `--lumen-radius-k`. Never add Tailwind colour classes inside the component.

```tsx
import { SaasAnalyticsApp, type SaasView } from "@/components/ui/lumen/workspaces/saas-analytics";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `SaasAnalyticsApp` | — | The app: sidebar, top bar and the six views. |

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `GlassSoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/glass-sound.json`, import from `@/components/beautiful-ui/glass-sound`); `GlassSoundToggle` is its mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/lumen/workspaces/saas-analytics.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- SaaS analytics app, product analytics dashboard, revenue dashboard, MRR dashboard, admin analytics template, starter app, Lumen
- Starting a SaaS analytics product or internal dashboard with navigation, metrics, revenue, customers and the team, billing and settings screens
- Seeing how Lumen pieces compose into a whole app, then keeping the views you need

### Not when
- A single dashboard card: install that chart
- Apps with their own shell: take the views instead (Customer Intelligence, SaaS Screens, the charts)

## Mistakes
- Give every customer's history the same length as weeks, oldest first, with 0 before they joined
- Map view and onViewChange onto your router so the back button works
- planConfig keys must be the plan values in customers; a plan missing from planConfig is left out of the charts
- With your own customers, pass funnel too: the trial funnel is not drawn otherwise
- team, billing and settings keep their own sample state until you pass your data and callbacks; check permissions on your server

## Usage

```tsx
// app/analytics/[view]/analytics.tsx (Next.js App Router). Your page.tsx loads the data on the
// server and renders <Analytics view={view} customers={…} weeks={…} … />.
"use client";

import { useRouter } from "next/navigation";
import { SaasAnalyticsApp, type SaasView } from "@/components/ui/lumen/workspaces/saas-analytics";
import type { Invoice, Member, UsageMeter } from "@/components/ui/lumen/workspaces/saas-screens";
import type { ChartConfig } from "@/components/ui/lumen/chart";
import type { CiCustomer } from "@/lib/beautiful-ui/lumen/customer-intelligence-model";
import type { ActionSpec } from "@/lib/beautiful-ui/core/insights";

// Throws on a failed request, so each view shows the error in words.
async function send(url: string, method: "POST" | "PATCH" | "DELETE", body?: unknown) {
  const res = await fetch(url, { method, headers: { "content-type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) });
  if (!res.ok) throw new Error((await res.text()) || `Request failed (${res.status})`);
}

// Keys match customers[].plan.
const plans: ChartConfig = {
  scale: { label: "Scale", theme: { light: "#6B74F5", dark: "#8B93FF" } },
  growth: { label: "Growth", theme: { light: "#17A673", dark: "#4ADE9B" } },
  starter: { label: "Starter", theme: { light: "#E08A12", dark: "#FFB547" } },
};

export function Analytics(props: {
  view: SaasView;
  /** One entry per week start, oldest first, e.g. ["2025-09-29", …, "2026-09-28"]. */
  weeks: string[];
  /** e.g. { id: "cus_81", name: "Northwind", plan: "scale", region: "Europe", mrr: 4200, seats: 60, tenure: 18,
   *  health: "Expanding", owner: "Maya Chen", renews: "2027-03-01", history: [0, 0, 3600, …, 4200] } */
  customers: CiCustomer[];
  trial: { organic: number[]; paid: number[]; referral: number[] }; // visitors, sign-ups, activated, paid
  members: Member[];
  seats: number;
  plan: { name: string; price: number; interval: "month" | "year"; renews: string };
  usage: UsageMeter[];
  invoices: Invoice[];
  workspace: { name: string; timeZone: string; weeklyDigest: boolean; anomalyAlerts: boolean };
  me: { name: string; avatarUrl?: string };
  approvers: { name: string; avatarUrl?: string }[];
}) {
  const router = useRouter();
  return (
    <SaasAnalyticsApp
      className="h-svh"
      company={{ name: props.workspace.name, plan: props.plan.name }}
      view={props.view}
      onViewChange={(v) => router.push(`/analytics/${v}`)}
      customers={props.customers}
      weeks={props.weeks}
      today={new Date().toISOString().slice(0, 10)}
      event={{ date: "2026-08-12", label: "Seat pricing" }}
      planConfig={plans}
      actor={props.me}
      reviewers={props.approvers}
      onExecute={(action: ActionSpec) => send("/api/actions", "POST", action)}
      funnel={{
        stages: ["Visited", "Signed up", "Activated", "Paid"],
        sources: [
          { id: "organic", label: "Organic" },
          { id: "paid", label: "Paid ads" },
          { id: "referral", label: "Referral" },
        ],
        counts: [props.trial.organic, props.trial.paid, props.trial.referral],
        unit: "visitors",
      }}
      team={{
        members: props.members,
        seats: props.seats,
        onMembersChange: () => router.refresh(),
        onInvite: (email, role) => send("/api/team/invites", "POST", { email, role }),
        onRoleChange: (member, role) => send(`/api/team/${member.id}`, "PATCH", { role }),
        onRemove: (member) => send(`/api/team/${member.id}`, "DELETE"),
      }}
      billing={{
        plan: props.plan,
        seats: { used: props.members.length, included: props.seats },
        usage: props.usage,
        invoices: props.invoices,
        currency: "USD",
        onChangePlan: () => router.push("/billing/plans"),
        onManagePayment: () => router.push("/billing/portal"),
      }}
      settings={{
        defaultValue: props.workspace,
        onSave: (s) => send("/api/workspace", "PATCH", s),
        onDelete: async () => {
          await send("/api/workspace", "DELETE");
          router.push("/");
        },
      }}
    />
  );
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `customers` | `CiCustomer[]` | `Lumen's 300 sample customers` | Every customer: { id, name, plan, region, mrr, seats, tenure (months), health: "Healthy" \| "Expanding" \| "At risk", owner, renews, history }. history is MRR per week, aligned with weeks, 0 before they joined. Overview, Customers and Revenue all read it. |
| `weeks` | `string[]` | `the sample's 52 weeks` | ISO dates of each week's start, oldest first; the same length as every history. The sidebar footer shows the last one ("Data to Sep 28"). |
| `today` | `string` | `"2026-09-27"` | ISO date the Customers view's date presets count back from. Pass today's date. |
| `event` | `{ date: string; label: string }` | `{ date: "2026-08-12", label: "Seat pricing" }` | A dated event marked on the Overview trend and on the Customers view, and cited as evidence there (a pricing change, an outage). |
| `view / defaultView / onViewChange` | `"overview" \| "customers" \| "revenue" \| "team" \| "billing" \| "settings" / same / (view: SaasView) => void` | `— / "overview" / —` | The current view (SaasView). Controlled with view, or uncontrolled from defaultView; onViewChange fires on every sidebar pick either way, so map it onto your router. |
| `planConfig` | `ChartConfig` | `enterprise, midMarket, selfServe` | Colours and labels by plan key, shared by every chart. Its keys are the plans the charts draw, so they must match customers[].plan; a plan without a label is title-cased. |
| `company` | `{ name: string; plan?: string }` | `{ name: "Lumen", plan: "Analytics" }` | The sidebar header and the breadcrumb; the logo is the name's first letter. |
| `actor / reviewers` | `Actor / Actor[]  (Actor = { name, initials?, avatarUrl? })` | `a sample team` | Customers view: who is acting, and who can approve a recommendation that needs a second person. |
| `onExecute` | `(action: ActionSpec) => void \| Promise<void>` |  | Customers view: runs a recommendation's action once it is confirmed (and approved, if it requires approval). ActionSpec carries label, changes, affected, risks, reversible and requiresApproval. Throw or reject to report a failure. |
| `funnel` | `Partial<FlowFunnelProps>` |  | Overview's trial funnel: stages, sources, counts[source][stage], config, unit and the rest of Flow Funnel's props. Without it the funnel shows only while customers is the sample; with your customers and no funnel it is left out, never drawn with sample numbers. |
| `team` | `TeamView props` | `sample members, 10 seats` | Team view: members / defaultMembers (Member = { id, name, email, role: "owner" \| "admin" \| "member" \| "viewer", status?: "active" \| "invited" }), onMembersChange(members), onInvite(email, role), onRoleChange(member, role), onRemove(member), seats. The async callbacks run before the list changes; throw to show the error and keep the list. |
| `billing` | `BillingView props` | `a sample Growth plan` | Billing view: plan { name, price, interval: "month" \| "year", renews }, seats { used, included }, usage (UsageMeter[]: { id, label, used, limit, unit }; a meter warns at 80%), invoices (Invoice[]: { id, date, amount, status: "paid" \| "due" \| "failed", url? }; url adds a download link), currency (default "USD"), onChangePlan(), onManagePayment(). |
| `settings` | `SettingsView props` | `name "Lumen", UTC, both alerts on` | Settings view: defaultValue (WorkspaceSettings = { name, timeZone, weeklyDigest, anomalyAlerts }), onSave(settings), onDelete() after the person types the workspace name. Throw to show "Not saved: …" or keep the delete dialog open. |
| `className / …div props` | `React.ComponentProps<"div">` |  | On the root (data-slot="saas-analytics"); give it a height, e.g. h-svh. |

Full docs: https://beautiful-ui.dev/components/lumen-saas-analytics

## Customising
- Colours: set the `--lumen-*` tokens on `:root`, or on a container with the `lumen-scope` class to retheme one area. Add the `lumen-inherit` class to follow your shadcn palette instead (`--chart-N`, `--destructive`).
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| Tab | Sidebar, then the view |
| Ctrl/⌘ + B | Collapse or expand the sidebar |

## Motion inventory

| Interaction | What moves |
|---|---|
| View | Charts sweep in on the new view (subtle) |

## Accessibility contract (preserve when editing)
- The sidebar marks the current view with aria-current=page; a view change moves focus to its heading, as a page navigation would
- Each view keeps its pieces' own keyboard models, labels and data tables

## Install

```bash
npx shadcn@latest add @beautiful-ui-pro/lumen-saas-analytics
```

Pro item: needs the `@beautiful-ui-pro` registry in `components.json` and `BEAUTIFUL_UI_TOKEN` in `.env.local` (https://beautiful-ui.dev/account). Setup: https://beautiful-ui.dev/docs/pro. Your components.json `style` picks the build: radix-*, new-york and default get Radix, base-* gets Base UI.

## Credits
- Built on shadcn/ui (https://ui.shadcn.com)

The lumen foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/lumen-foundation.json.
