# Partner dashboard and team CRM on Cloudflare Workers

> A web dashboard for a partner program — stats, payouts, an advertiser panel, courses and a team CRM — where access rules live in the database, not in the front end.

- Service: Backends and dashboards on Cloudflare Workers
- Stack: Hono, TypeScript, Astro, PostgreSQL, Browser Rendering
- Canonical: https://jamm-automation.com/cases/partner-dashboard/
- Updated: 2026-11-29

## Manual

Partners, team owners, advertisers and admins look at the same data, and each must see only their own slice.

- **Roles:** four kinds of users share one dataset with different rights.
- **Risk:** an access rule kept only in application code can leak another user's data.

## System

One Worker serves the API, a static front end serves the pages, and the database decides who sees what.

- **API:** Hono and TypeScript on a Cloudflare Worker.
- **Front end:** static Astro with uk, ru and en dictionaries.
- **Sign-in:** Telegram login widget and a JWT session.
- **Access:** the Worker calls a few SECURITY DEFINER SQL functions; the role is resolved in SQL (`fn_tcrm_role`) and the data is cut to the caller's scope.
- **CRM:** team owners get a reduced view of their own people.

## Autopilot

Receipts are rendered and sent by a queue consumer.

- **Receipts:** a queue consumer renders payout receipts with Browser Rendering (headless Chromium), takes an element screenshot as PNG and sends it to Telegram with `sendPhoto`.
- **Fallback:** if rendering fails, a text receipt goes out.
- **Tests:** the Worker routes are covered by automated tests, so role and payout changes are checked before release.
