How yoursza1/paidly works
Purpose and entry points
Paidly is a multi-tenant business operations platform covering commercial documents, payments, subscriptions, inventory/POS, workforce/payroll, and platform administration. The browser app is a Vite/React SPA bootstrapped by src/main.jsx and routed from src/App.jsx. Production API requests are served either by Vercel function entrypoints under api/ or the Express backend rooted at server/src/index.js.
Frontend application boundary
Pages compose domain UI, services, and Supabase-backed data access. Authentication, organization context, branding, and connectivity are global client concerns managed through contexts and protected shells:
• src/contexts/AuthContext.jsx
• src/contexts/CompanyContext.jsx
• src/components/layout/AuthenticatedShell.jsx
The client calls Supabase directly for much tenant CRUD and calls /api for privileged, payment, email, admin, and integration workflows. src/api/customClient.js is the principal direct data client; src/lib/authedApiRequest.js represents the authenticated API boundary.
Session, data, and realtime runtime
The frontend explicitly coordinates session recovery, request volume, persisted query data, mutations, and realtime rather than letting individual screens own connections. This is a cross-cutting runtime layer intended to prevent duplicate requests and reconnect storms:
• src/core/auth/SessionCoordinator.ts
• src/core/runtime/RuntimeCoordinator.ts
• src/core/realtime/RealtimeManager.ts
Supabase Auth establishes identity; query/cache and realtime reconciliation update UI state; session/wake recovery controls invalidation and retry behavior. Connection lifecycle state is exposed through src/contexts/ConnectionLifecycleContext.jsx.
Commercial document engine
Invoices, quotes, typed documents, expense claims, document sends, public sharing, PDF generation, reminders, and engagement events converge on a document-engine model. The frontend creates and transitions documents, while server routes perform authoritative event, reminder, send, and payment operations:
• src/document-engine/documentCreateFlow.js
• src/document-engine/documentStateMachine.js
• server/src/documents/documentEventService.js
Shared commercial calculations and status semantics prevent divergent browser/server behavior:
• shared/commercial/calculateCommercialDocument.js
• shared/documents/documentEngine.js
• shared/documents/documentEvents.js
Public viewers are separately exposed through api/public-share.js and corresponding public API handlers, avoiding authenticated UI paths.
Payments, billing, and entitlements
A payment-intent/payment-engine layer connects invoices and POS checkout to supported payment rails. Provider selection, validation, payment status transitions, and document-payment event bridging reside server-side:
• server/src/payments/paymentEngine.js
• server/src/payments/paymentIntentService.js
• server/src/payments/documentPaymentEventBridge.js
Subscription billing and feature authorization are separate but connected: PayFast recurring/ITN processing updates subscription state, then entitlements gate product surfaces:
• server/src/billing/payfastItnPipeline.js
• server/src/billing/entitlements.js
• src/components/subscription/FeatureGate.jsx
PayFast is the primary named billing provider; Ozow and card-terminal abstractions also exist.
POS, inventory, and workforce domains
POS is a dedicated operational subsystem with staff access, registers/sessions, checkout, returns, receipts, inventory synchronization, and optional Square/Yoco integrations:
• server/src/pos/posApiRoutes.js
• server/src/pos/posSaleProcessor.js
• server/src/pos/posInventorySync.js
Workforce includes employee provisioning, leave authorization, payroll pay runs, payslips, and public payslip access:
• server/src/workforce/workforceRoutes.js
• server/src/payroll/payrollService.js
• shared/payroll/calculatePayroll.js
These domains share tenant and entitlement boundaries but retain server-side authorization and transactional logic.
Persistence, infrastructure, and security
Supabase provides Postgres, Auth, Storage, Realtime, RLS, RPCs, migrations, and Edge Functions. Its evolving authoritative schema and tenant/security rules are captured in:
• supabase/schema.postgres.sql
• supabase/migrations/20260619120000_multi_tenant_company_extension.sql
• supabase/migrations/20260906120000_commercial_document_engine.sql
Vercel hosts the SPA and serverless API adapters such as api/auth/[route].js and api/pos/[[...path]].js; the Node backend can also run separately with CORS controls. External services include Supabase, PayFast, Resend/email delivery, Square, Yoco, and Sentry (server/src/sentry.js). Privileged server operations use service-role Supabase clients and enforce request validation, rate limiting, and authorization before database writes.
Main entry points: index.js Express backend · schema.postgres.sql Supabase · payfastItnPipeline.js Billing and entitlements · paymentEngine.js Payment engine
Components 20
Browser SPA
- React SPA · Tenant business operations UI.
src/main.jsx - App routes
src/App.jsx - Tenant session context · Auth and company context drive protected UI.
src/contexts/AuthContext.jsx - Authenticated shell
src/components/layout/AuthenticatedShell.jsx - Runtime coordination · Coordinates recovery, cache invalidation, and wake behavior.
src/core/runtime/RuntimeCoordinator.ts - Realtime manager
src/core/realtime/RealtimeManager.ts - Direct data client · Handles tenant CRUD from the browser.
src/api/customClient.js - Authenticated API client
src/lib/authedApiRequest.js - Document engine · Creates and transitions invoices, quotes, and related documents.
src/document-engine/documentCreateFlow.js - Feature gate
src/components/subscription/FeatureGate.jsx
Server APIs
- Vercel API adapters · Hosts public and routed API adapters.
api/auth/[route].js - Express backend · Separately deployable authoritative backend.
server/src/index.js - Document event service · Processes sends, reminders, events, and payments.
server/src/documents/documentEventService.js - Payment engine · Selects rails and bridges payment status to documents.
server/src/payments/paymentEngine.js - Billing and entitlements · Processes PayFast ITNs and derives feature access.
server/src/billing/payfastItnPipeline.js - POS operations · Processes sales, returns, registers, and inventory sync.
server/src/pos/posSaleProcessor.js - Workforce and payroll · Authorizes workforce actions and runs payroll.
server/src/payroll/payrollService.js
Supabase Platform
- Supabase · Tenant RLS, RPCs, schema, and managed runtime.
supabase/schema.postgres.sql - PayFast
- External integrations · Resend, Square, Yoco, and Sentry integrations.
server/src/sentry.js
Connections 25
- React SPA → App routes: boots
- App routes → Authenticated shell: protects tenant pages
- Tenant session context → Authenticated shell: supplies identity and company
- React SPA → Runtime coordination: coordinates lifecycle
- Runtime coordination → Realtime manager: controls reconnects
- Runtime coordination → Direct data client: coordinates requests
- Direct data client → Supabase: tenant CRUD and auth
- Realtime manager → Supabase: subscriptions
- Document engine → Authenticated API client: authoritative operations
- Authenticated API client → Vercel API adapters: /api requests
- Vercel API adapters → Express backend: adapts routes
- Express backend → Document event service: document routes
- Express backend → Payment engine: payment routes
- Express backend → Billing and entitlements: billing webhooks
- Express backend → POS operations: POS routes
- Express backend → Workforce and payroll: workforce routes
- Document event service → Supabase: events and documents
- Payment engine → Document event service: payment events
- Payment engine → External integrations: payment rails
- Billing and entitlements → PayFast: recurring payments and ITNs
- Billing and entitlements → Supabase: subscription state
- Billing and entitlements → Feature gate: entitlements
- POS operations → Supabase: sales and inventory
- POS operations → Payment engine: checkout payments
- Workforce and payroll → Supabase: employees and pay runs