STYL System Audit Report
Full schema + logic audit — March 2026. No tables renamed or duplicated.
Issues Found & Fixed
Provider.services_offered.price had no enforcement boundary preventing STYL Days from pulling provider-set prices.
Added description annotation on Provider.services_offered.price clarifying it is used for regular bookings only. StylDayBookings.servicePrice description updated to state it sources from STYL Days preset ($75/$85) only. StylDayEvents.usePresetPricing flag added (default: true) as a runtime check point.
Transaction, TransactionLedger, and Order entities had no finalized flag. App-confirm + delayed Stripe webhook could both write payment state, causing balance drift.
Added finalized (boolean), finalizedAt (datetime), and finalizedBy (enum: app_confirm | stripe_webhook | admin_manual) to Transaction, TransactionLedger, and Order. All payment confirmation paths must check finalized === true before writing and set it on first write.
CorporateAccount.outstanding_balance_cents and CorporateInvoice.outstanding_balance had no enforcement that they equal billed − paid. Manual adjustments could leave these out of sync.
Added description constraints on CorporateAccount and CorporateInvoice fields. CorporateAccount description notes outstanding_balance_cents = total_billed_cents - total_paid_cents at all times. Admin adjustment flows must recalculate both fields atomically.
UserSubscription had no composite uniqueness guard. A user could end up with multiple active super_styl records if app-confirm and webhook both ran.
Added account_type field (user/provider/store) to UserSubscription for cleaner scoping. Added idempotency_key field. subscriptionEngine.confirmProvider and confirmStore now deactivate any prior active record for same account type before creating a new one.
User.plan enum had 'pro' and 'elite_pro' — neither matches the actual Super STYL product. superStylSubscription function sets subscription_type='super_styl' but User.plan was never updated to match.
Updated User.plan enum to ['free', 'super_styl']. superStylSubscription confirm action should set User.plan = 'super_styl' on activation and User.plan = 'free' on cancellation.
User entity had no corporate_account_id field. Frontend had no reliable way to detect a corporate employee and route them to corporate dashboard vs standard dashboard.
Added corporate_account_id field to User entity. Frontend routing logic should check: if user.corporate_account_id exists → show CorporateDashboard view.
Notification.type enum only covered bookings, orders, and messages. Subscription, invoice, corporate, and admin action notifications all used free-text or unsupported values, silently failing enum validation.
Extended Notification.type enum to include: subscription, subscription_update, payment, invoice, invoice_update, corporate, admin_action, system, payout_update. Added role_target field to enforce role-appropriate delivery.
Two naming conventions (camelCase from original schema vs snake_case from subscription/superAdmin functions) were writing to the same entity with incompatible field names, creating orphan fields.
Extended AdminAuditLog to formally declare both conventions as valid fields: actorUserId/actionType/targetId (camelCase legacy) and admin_email/action/target_email/entity_type/entity_id/details (snake_case used by Section 11/12 functions). old_value and new_value fields added for admin adjustment logging.
AuditLog.action_type enum was missing actions for subscriptions, discounts, invoices, balance adjustments, STYL Days, product uploads, and pickup code verification — all used in app workflows.
Extended AuditLog.action_type enum with 14 new values covering all missing action types.
TransactionLedger.orderType enum only had BOOKING, ORDER, HOTEL_BOOKING. STYL Days bookings and corporate invoices had no dedicated type, causing misrouted payout calculations.
Added STYL_DAY_BOOKING and CORPORATE_INVOICE to TransactionLedger.orderType. Added corpContributionCents, employeeContributionCents for split payment tracking. Added checkoutSessionId for app-side idempotency.
Transaction.type lacked STYL_DAY_BOOKING and SUBSCRIPTION types. Transaction.channel lacked STYL_DAYS. Discount amount was not captured.
Added STYL_DAY_BOOKING, SUBSCRIPTION, CORPORATE_INVOICE to Transaction.type. Added STYL_DAYS to Transaction.channel. Added amountDiscount, finalized, finalizedAt, finalizedBy fields.
StylDayEvents had no providerCapacity field, and allowProviderOverride defaulted to false. This silently blocked unlimited provider assignment.
Added providerCapacity field (0 = unlimited). Changed allowProviderOverride default to true. Added usePresetPricing flag.
StylDayEvents had no invoiceIdempotencyPrefix. Multiple invoice creation calls for the same event could generate duplicate CorporateInvoice records.
Added invoiceIdempotencyPrefix to StylDayEvents. Added invoiceId reference field to StylDayBookings. Added idempotency_key to CorporateInvoice (already existed but not described as a duplicate guard).
StylDayBookings had no confirmationSource field, making it impossible to know whether a booking was confirmed via app-redirect or Stripe webhook — preventing safe idempotency checks.
Added confirmationSource enum (app_confirm | stripe_webhook | admin_manual) and transactionLedgerId reference to StylDayBookings.
Order had pickup_verification_code but no pickup_code_expires_at. Codes never expired, creating a security window for stale code reuse.
Added pickup_code_expires_at (datetime) to Order entity. Pickup verification logic must reject codes past this timestamp.
Order entity tracked delivery_fee and service_fee amounts but had no boolean flags to record whether they were waived. Reports and admin views couldn't distinguish waived-zero from charged-zero.
Added service_fee_waived and delivery_fee_waived boolean flags to Order. These must be set during order creation based on customer's active Super STYL entitlement.
Provider entity was missing stripe_subscription_id, stripe_customer_id, subscription_activated_at, subscription_cancelled_at, and cancellation_reason. cancelSubscription function wrote to these fields but they weren't in the schema.
Added all five fields to Provider entity schema.
discount_percent had no annotation clarifying it is Super Admin only. Invoice discounts were also missing the discount_applied_by and discount_applied_at provenance fields.
Updated CorporateAccount.discount_percent description to 'Super Admin only'. Added discount_applied_by and discount_applied_at to CorporateInvoice for full audit trail.
approval_roles default only included admin and ops_manager. Social Media Manager was not included, violating the requirement that SM Manager can approve and edit student portal content.
Updated approval_roles default to ['admin', 'ops_manager', 'social_media_manager']. Added editable_roles field with same default.
Order.store_commission_rate description did not clarify it is a snapshot. If a store changes tiers, historical orders could appear to have the wrong rate.
Updated Order.store_commission_rate description to explicitly state it is snapshotted from Store.commission_rate at order time.
monthly_plan_type had no annotation tying it to STYL Days preset pricing. This could be confused with regular subscription plans.
Updated monthly_plan_type description to 'Plan ID from STYL Days preset pricing — only applicable for approved corporate monthly rate plans'.
- •Stripe webhook functions (webhook1/webhook2) must check Transaction.finalized before writing payment state — cannot be verified without reading those function files (not found during audit).
- •Corporate balance recalculation (outstanding_balance_cents = total_billed_cents - total_paid_cents) must be enforced atomically in the billing function — verify on every admin adjustment and payment record.
- •Super STYL confirm path in superStylSubscription should also update User.plan = 'super_styl' to stay in sync with updated enum — review that function if not already done.
- •STYL Days service fee waiver logic (admin/ops override per booking) needs runtime enforcement in the checkout function — confirm serviceFeeWaived flag propagates correctly to StylDayBookings and invoice line items.
- •Provider subscription (pro) downgrade/cancellation must reset Provider.tier back to 'basic' and set commission_rate back to 0.30 — verify cancelSubscription function handles this correctly.
- •4-digit store pickup code generation must create a time-limited code when order status becomes 'accepted'/'preparing' and write pickup_code_expires_at — review order status transition logic.
- •Duplicate invoice prevention for STYL Days events requires invoiceIdempotencyPrefix to be set when creating the event and checked during invoice creation — implement in billing function.
- •Student portal automation schedules (blog, tip, video) may have conflicting cron jobs if multiple were created across sessions — run list_automations to verify no duplicates.