Appearance
05 — Master Admin & Website CMS Manual
This manual covers executive governance in CRM Master Admin (https://crm.thebridgefinance.lk/crm/admin) and public editorial management in Website CMS (https://thebridgefinance.lk/admin). These two systems use separate URLs, separate authentication mechanisms, and separate D1 databases.
Part A: CRM Master Admin Cockpit (/crm/admin)
Accessible exclusively to users with role master_admin (enforced by CrmRoleRoute and Worker middleware requireRole(["master_admin"])).
1. Master Admin Sidebar Items
| Group | Item | Path / Hash | Authority Scope |
|---|---|---|---|
| MAIN MENU | KPI Summary | /crm/admin | Master Admin only |
| MAIN MENU | Leads | /crm/admin#leads | Shared Staff Desk |
| MAIN MENU | Borrowers | /crm/admin#borrowers | Shared Staff Desk |
| MAIN MENU | Investors | /crm/admin#investors | Shared Staff Desk |
| OPERATIONS | Bookings | /crm/admin#bookings | Shared Staff Desk |
| OPERATIONS | Documents | /crm/admin#documents | Shared Staff Desk |
| OPERATIONS | Live Chat | /crm/admin#chat | Shared Staff Desk |
| OPERATIONS | Access Analytics | /crm/admin#analytics | Master Admin only |
| ACCOUNT | Staff Management | /crm/admin#staff | Master Admin only |
| ACCOUNT | Loan Policies & Limits | /crm/admin#policies | Master Admin only |
| ACCOUNT | Profile | /crm/admin#profile | Shared Staff Profile |
(The Security & Audit Trail view is also supported at /crm/admin#audit for CSV audit log export and outcome filtering.)
2. Executive KPI Summary (/crm/admin)
- Metrics Displayed:
Total Portfolio Value, Active Borrowers, Active Investors, Monthly Disbursements, Collection / Recovery metrics, and Average Yield. - Horizon Switcher: Toggle live aggregation by Weekly, Monthly, or Yearly (
GET /api/crm/admin/kpis).

3. Staff & User Management (/crm/admin#staff)
- Summary Strip: Live counts for
Active Officers,Super Admins,Total Authorized Staff, andActive. - Full CRUD Lifecycle:
- Create: Click Add User (
add-crm-user-btn), specifyFull Name,Email,Phone,Role(stafformaster_admin), andDepartment. Creating a user dispatches a welcome email with thehttps://crm.thebridgefinance.lk/crm/loginlink via Resend. - Read / Filter: Search by name, email, or role; filter dropdown for
All Staff & Officers,Staff Officer, orSuper Admin. - Update: Edit name, department, role, or account status (
active/suspended). - Delete: Permanently remove an authorized account (also recorded in
crm_deleted_usersso deleted users do not resurrect).
- Create: Click Add User (
- Master Admin Governance & Anti-Lockout Protections:
- Environment Root Allowlist (
MASTER_ADMIN_EMAILS): Emails configured in CloudflareMASTER_ADMIN_EMAILSare automatically recognized asmaster_adminduring OTP login even if a D1 seed record was missing. - Self-Protection: A signed-in
master_admincannot demote, suspend, or delete their own account. - Last-Admin Guard: The backend (
src/worker/index.ts) blocks any request that would demote, suspend, or delete the last activemaster_adminacross D1 +MASTER_ADMIN_EMAILS(HTTP 400).
- Environment Root Allowlist (

4. Loan Policies & Limits (/crm/admin#policies)
Configure underwriting parameters (GET/PUT /api/crm/admin/policies):
- Maximum Loan Facility Limit (LKR): Slider from
LKR 500,000toLKR 2,000,000(step100,000, aligned with public sitemap ceiling). - Floor APR (%) & Ceiling APR (%): Numeric bounds with a live visual
Active APR Band (0% – 30%)bar. - Automated Screening Score Threshold: Numeric score split gauge (
Manual Desk Audit < thresholdvsExpedited Approval >= threshold). - PDPA Audit Mode: Sri Lanka Personal Data Protection Act (PDPA No. 9 of 2022) cryptographic hashing and document interaction audit logging (
Enforced). - Click Save Policy Configuration to persist to D1 (
crm_loan_policies).

5. Security & Audit Trail (/crm/admin#audit)
- Filter audit logs by outcome (
All,Success,Flagged) and search by actor, action, or IP/TLS hash (GET /api/crm/admin/audit-logs). - Click the export button to compile and download an audit CSV report.
6. Access Analytics Dashboard (/crm/admin#analytics)
Enterprise telemetry, marketing attribution, threat monitoring, and UI/UX diagnostics cockpit across both the Public Marketing Website (thebridgefinance.lk) and CRM Portal (crm.thebridgefinance.lk).
- Super Admin RBAC & PDPA Privacy:
- Visible and accessible exclusively to
master_admin(enforced acrossCrmSidebar,CrmRoleRoute, defense-in-depth guards inAccessAnalyticsDashboard, and Worker middlewarerequireRole(["master_admin"])on every/api/crm/admin/analytics/*route; unauthenticated calls return HTTP401and non-admin roles receive HTTP403). - Raw IP addresses (
CF-Connecting-IP) are never stored: they are irreversibly hashed via SHA-256 (ip_hash, 16 hex chars) and masked (ip_masked, e.g.112.134.x.x), while emails, tokens, OTP codes, passwords, and NIC numbers are scrubbed before storage.
- Visible and accessible exclusively to
- Cross-Surface Client SDK & Server Security Telemetry:
AnalyticsTrackerautomatically captures route views, UTM campaigns, dwell time, Core Web Vitals (LCP,INP,CLS,FCP,TTFB), scroll-depth milestones (25%–100%), rage clicks, JS runtime errors, and CTA/download clicks across bothweb(anonymous) andcrm(role-attributed without PII) viaPOST /api/analytics/collect, preservingapps/webbundle isolation.- Server-side middleware on
/api/*logsauth_success,auth_failure,auth_denied(401/403),rate_limit(429), andapi_error(5xx) latency/status telemetry.
- Global Command Bar:
- Filter across Time Range (
24h,7d,30d,90d), Surface (All,Public Web,CRM Portal), and Role (All,Anonymous,Borrower,Investor,Staff,Super Admin), trigger Refresh, Export CSV / Export JSON, and verify active SHA-256 IP Anonymized status.
- Filter across Time Range (
- Five Operational Sub-Tabs:
- Overview: Displays 6 executive KPI cards with period deltas, interactive dual-series Web vs CRM traffic SVG chart, Surface & User Role breakdown donut/bars, active triggered Watch Rule alert banners, and prioritized Marketing / Security / UX recommendations.

- Marketing: 5-stage acquisition-to-approval conversion funnel correlated with live D1 records (
applications,investor_applications,consultations,inquiries,crm_users,cms_downloads), traffic channels, UTM campaigns, top landing pages, top CTAs,EN/SI/TAlanguage distribution, geo regions, and Download Center metrics.

- Security: Displays the aggregate Security Posture Score, failed OTP attempts,
401/403RBAC denials,5xxerrors, suspicious masked-IP alerts, authentication timeline, and Watch Rules Manager (Full 4-Operation CRUD) — defaults to Cards View with aCards | Tabletoggle, Create/Edit rule modal, Enable/Disable toggle, Delete confirmation dialog, permanent deletion without resurrection, and real-time threshold evaluation.

- UI/UX Lab: Core Web Vitals P75 scorecard (
LCP,INP,CLS,FCP,TTFB) with Good/Needs Improvement/Poor stacked distribution bars, rage-click hotspots, JS runtime errors, slowest routes, device/browser/viewport breakdown, scroll-depth meters, and an accessible 7×24 hourly usage heatmap.

- Live Logs: Real-time searchable/filterable access event stream (
GET /api/crm/admin/analytics/events), defaulting to Cards View with aCards | Tabletoggle and horizontally scrollable.crm-table-scrolltables, plus individual event deletion and> 90 daysretention purge (POST /api/crm/admin/analytics/purge) with confirmation.

- Optional Hybrid Marketing Note: If paid Google Ads attribution or Google Search Console keyword reporting is later required, standard GA4 tags may be added strictly to
thebridgefinance.lkwhile keeping this built-in Access Analytics dashboard as the authoritative console for CRM funnels, security threats, and UI/UX telemetry.
Part B: Website CMS (/admin)
Accessible at https://thebridgefinance.lk/admin (or /en/admin). Stored in the-bridge-cms-db (D1) and the-bridge-cms (R2).
1. CMS Authentication (/admin/login)
- Unauthenticated requests redirect immediately to
/admin/login. - First-time authorized users check their email status (
POST /api/admin/cms/auth/status), set a password (POST /api/admin/cms/auth/setup-password), and sign in with email + password (POST /api/admin/cms/auth/login) returning anauthToken(bridge_cms_token).
2. CMS Roles
| Role | Label | Capabilities |
|---|---|---|
main_admin | Main Admin | Full access to Overview, Announcements, Blog & Articles, Download Center, and Team & Access (/admin/users) |
writer | Writer | Create, edit, and publish Announcements, Blog & Articles, and Download Center; /admin/users is hidden and blocked with HTTP 403 |
3. CMS Modules & Workflows
- Overview (
/admin): Shows counts for published/draft Announcements (plus pinned count), Blog Articles, and active/hidden Download Center resources, with quick-create buttons.

- Announcements (
/admin/announcements): Manage press bulletins (Announcementslist,/new, and/:id). Supportspublished/draftstatus and pinned banner flag for the public homepage. - Blog & Articles (
/admin/blog):- Rich WYSIWYG editor powered by TipTap (headings, tables, highlights, text alignment, inline images).
- Supports cover image upload to Cloudflare R2 (
POST /api/admin/cms/upload→/api/files/:assetId), comma-separated tags, computed read time, custom slug handling (cleanly deletes old slug when renamed without leaving duplicate articles), and a live Google SERP Preview Card (thebridgefinance.lk › en › articles › <slug>).

- Download Center (
/admin/downloads): Upload official forms, guides, and fee schedules to R2 (activeorhiddenvisibility) and track download counts.

- Team & Access (
/admin/users, Main Admin Only): Add (POST /api/admin/cms/users), update, or delete CMS writers and admins (ConfirmDialogguards deletions). - QA Feedback Manager (
/admin/feedback): Unlisted maintenance route for reviewing and resolving submitted feedback pins (/api/feedback).
