Core Workflows

1. Member Onboarding

User invited to organisation

Admin creates user record with organisation and location assignment

License created

Binds user + organisation + membership tier + space. Triggers license job.

Line item generated

License job creates recurring line item with pricing from membership (primary vs extra member rates)

Welcome email sent

User job sends welcome mail with JWT token, WiFi credentials, and onboarding instructions

Access provisioned

RADIUS WiFi user auto-created. Papercut print account synced. Clay access group assigned.

2. Monthly Invoice Run

Admin initiates invoice run

Reviews preview for a location showing all active organisations and calculated amounts

Line items calculated

Sum from active licenses + adhoc charges. Apply discounts (commitment, volume). Pro-rata for mid-month changes.

Invoice approved

Status becomes "subscription_locked". Xero invoice created with line items, tracking codes, and tax.

Invoice sent

Emailed to organisation contacts (invoice + accounting email addresses). Status unlocked after send.

Payment processed

If auto-pay enabled, PayFast charges stored token. Otherwise manual payment via portal.

Fulfillment

Line items processed by type: stuff/space credits → wallet topup, printing → Papercut balance adjustment

3. Room Booking

Member selects room and time

System checks availability, applies access control (private rooms), calculates cost

Cost calculated

Peak (8am-5pm) vs off-peak rates. Half-day (4+ hrs) and full-day (8+ hrs) discounts applied.

Ledger reserve created

Funds held in wallet via reserve transaction. Reserve expires after 24 hours (configurable).

Notifications sent

iCal attachment to organiser and attendees. Location manager gets admin notification.

Reserve converted or expired

Cron job converts expired reserves to debits every 60 seconds. Cancelled bookings delete reserves.

4. Sales Pipeline (CRM)

Lead created

From web form (with reCAPTCHA), manual entry, or external integration. Heat rated (hot/mild/cold).

Opportunity opened

Track template auto-generates task tree with cascading due dates

Tasks worked

Follow-up calls, emails, meetings, site visits tracked. Email history from Mailarchiva.

Won or abandoned

Won: triggers onboarding. Referral rewards credited to wallet if referral source. Abandoned: reason captured, lead archived.

5. Self-Service Purchase

Member browses products

Filtered by location + headquarters. Shows member discounts.

Payment

Via stored PayFast token (one-click) or wallet credit deduction. VAT calculated.

Fulfillment

Product type determines action: stuff → wallet topup, space → wallet topup, printing → Papercut balance.

6. Check-in / Presence

Guest: QR code scan

Enter email/name, accept terms. Guest record created or updated. Confirmation emails sent.

Member: Direct login

Session-based authentication. Check-in record created with timestamp.

Federated: Unikey PIN

Encrypted PIN validated against external WSM instances. WiFi provisioned on check-in.

Background Job Processing

Jobs are triggered via Google Cloud Pub/Sub messages and processed by packages/jobs/worker.js.

Job TypeTriggerActions
Booking POST/PUT/DELETE on booking Send iCal invite, update notification, or cancellation to organiser + attendees + location manager
User User creation/update Onboarding: create license, send welcome email with JWT + WiFi creds, setup Papercut/RADIUS
License License CRUD Create/update/delete line items. Generate pricing with Xero codes. Update user memberships.
Invoice Invoice status change Purchase fulfillment by product type (stuff/space/printing wallet topups). Lineitem normalisation. VAT handling.
Payment Payment trigger One-click PayFast charge. Xero payment recording. Organisation-wide payment processing.
Membership Membership CRUD Xero sync: create item codes with location-specific tracking names
Discount Discount changes Set escalation dates based on commitment discount expiry
Email Various triggers Template-based HTML email rendering and sending via Nodemailer
Lead Lead lifecycle events CRM notifications, status updates
Organisation Org changes Xero contact sync, membership updates, access control changes
Product Product CRUD Xero item sync with location tracking codes

Scheduled Tasks (Cron)

The cron scheduler (packages/cron/cron.js) runs every minute, checking for "due" schedule records. It prevents concurrent execution with a locking mechanism.

TaskFrequencyPurpose
Xero Token Refresh Every minute Refreshes OAuth token to prevent API auth failures. Sends alert email on failure.
Xero Cache Update Every hour Pre-fetches credit notes and payments for faster dashboard loading
Ledger Reserve Cleanup Every 60 seconds Converts expired booking reserves to actual debits
Wallet Quota Top-ups Daily/Weekly/Monthly/Annually Resets credit quotas per configured frequency
Health Check Every minute (commented out) Monitors stuck jobs, alerts if stuck > 1 hour

Key Business Rules

Pricing Model

Booking Cost Calculation

Wallet Deduction Logic

Invoice Lifecycle

Lead Spam Prevention

Critical Data Flow Patterns

Financial Flow

Organisation --> License --> LineItem --> Invoice | | +--> Ledger (reserves) +--> Payment User --> Wallet --> Ledger --> Balance (cached summary) User --> Booking --> Ledger (reserve --> debit on expiry)

Sales Pipeline Flow

Lead --> Opportunity --> Task (tree from Track template) | | | +--> Proposal | +--> Contract | +--> Contact (unified view)

Access Control Flow

User --> Organisation --> Location | | +--> Membership ---------+ +--> License (binds all) +--> ClayTag (door access) +--> RadAcct (WiFi) +--> Papercut (printing)

Workflow Summary

ProcessTriggerKey StepsDuration
Member OnboardingNew userWelcome mail → License → Line item → Access provisioningImmediate
Monthly InvoicingAdmin actionCalculate → Approve → Send → Pay → FulfillManual + Scheduled
Room BookingMember actionCreate → Reserve funds → Notify → Convert/expirePer booking
Self-Service PurchaseMember actionBrowse → Pay → Fulfill (wallet topup)Immediate
Check-inGuest/MemberScan/Login → Record → Email notificationReal-time
CRM OpportunitySales teamLead → Opportunity → Tasks → Win/Lose → ArchiveDays to months
License LifecycleAdmin actionCreate → Line item → Invoice → Pay → FulfillMonthly
Price EscalationScheduledCheck dates → Apply percentage → Update line itemsAnnual