Skip to main content

Core Engine Schema — core_engine

The scheduling core of RABS lives in the core_engine Postgres schema. It replaced the earlier parallel scheduling systems (workshed, loom, program_templates) with a single clean schema of 19 tables, a dedicated instance API at /api/v1/engine, and a fully-wired program creation wizard.

The previous docs in this section (Workshed + Loom, Program Wizard, Payment/Python/History Ribbon) remain as historical context — the thinking they describe evolved into the design documented here.


Conceptual Model

Six concepts underpin the entire engine:

ConceptMeaning
SourcesThe filing cabinets. Participant files, staff files, vehicle files, venue files. Without these, nothing operational can be built. Live in core_source.
ProgramsBlueprints. They describe what normally happens. Not the future and not the past — the current intended shape of the repeating thing.
IntentsThe calendar. A date-specific modification that does not rewrite the blueprint: a participant cancelled this Tuesday only, a bus unavailable for two weeks, an alternate pickup address, a billing override.
InstancesThe living thing. A program on a specific date after matching intents have been applied. Mutable until the day starts or the instance is locked.
The Active WindowDestructible and rebuildable. Programs + intents + settings reproduce the future. The window can be 4 weeks or 16 weeks — future instances are projections, not truth.
Locked InstancesHistorical truth. Once locked, they don't change because templates change. They store snapshots of names, addresses, rates, and totals as they were on the day.

Key principle: A foreign key is not history. If a locked billable line still references the live finance.billing_rates row, then changing a rate changes the past. Locked rows must denormalise the values that mattered at the time.


Schema Tables (19)

TablePurpose
programsThe blueprint. The repeating shape of a scheduled event.
program_slotsTime slots inside a program (pickup, activity, meal, dropoff).
program_participantsWho normally attends, with address preferences.
program_participant_billingDefault billing lines per participant.
program_staffStaff placeholders (auto / manual / open).
program_vehiclesVehicle placeholders (auto / manual / personal car).
program_requirementsComputed staffing/vehicle minimums.
program_activitiesActivities attached to a program.
intentsDate-specific modifications. The calendar.
instancesA program on a date after intents apply. The living thing.
instance_timeslotsCards on the live timeline for one instance.
instance_attendanceParticipant rows for one instance.
instance_shiftsStaff shifts for one instance.
instance_staff_checkinDay-of staff check-ins.
instance_vehicle_dispatchDay-of vehicle dispatch.
instance_billablesBilling lines generated for one instance.
instance_routesTransport route cards.
instance_artifactsPinned shift notes, incident reports, attachments.
instance_tagsSemantic tags with vector embeddings for search.

External foreign keys reach out to exactly four schemas: core_source (participants, staff, vehicles, venues), finance (billing rates), accounts (users), and admin (app settings). Nothing else. The engine is islanded by design.


Migration Scripts

FileWhat it did
20260420_core_engine_create.sqlBuilt the 19 tables in one transaction. Triggers, constraints, indexes.
20260420_core_engine_patch.sqlSchema-qualified trigger functions, NOT NULL booleans, relaxed split-shift uniqueness, CHECK constraint hardening.
20260420_core_ops_prune.sqlDropped 30+ dead tables from core_ops. The 20 surviving tables are operational support only.
20260421_seed_billing_rates.sqlReplaced 11 POC junk rows in finance.billing_rates with 73 real NDIS-style codes.

Instance API — /api/v1/engine

The engine route file (backend/routes_v1p/engine.js) is the operations-side counterpart to the wizard. The wizard builds the blueprint; the engine serves the live and locked instances.

Window

GET    /api/v1/engine/window

Reads admin.app_settings for loom_window_fortnights (default 4 = 56 days) and returns the date list the engine considers active.

Instances

GET    /api/v1/engine/instances
GET /api/v1/engine/instances/:id
PATCH /api/v1/engine/instances/:id

Attendance

GET    /api/v1/engine/instances/:id/attendance
POST /api/v1/engine/instances/:id/attendance
PATCH /api/v1/engine/instances/:id/attendance/:aid

Staff

GET    /api/v1/engine/instances/:id/staff
POST /api/v1/engine/instances/:id/staff
PATCH /api/v1/engine/instances/:id/staff/:sid

Vehicles

GET    /api/v1/engine/instances/:id/vehicles
POST /api/v1/engine/instances/:id/vehicles
PATCH /api/v1/engine/instances/:id/vehicles/:vid

Routes & Timeslots & Billables

GET    /api/v1/engine/instances/:id/routes
POST /api/v1/engine/instances/:id/routes
GET /api/v1/engine/instances/:id/timeslots
GET /api/v1/engine/instances/:id/billables

Locking

POST   /api/v1/engine/instances/:id/lock
POST /api/v1/engine/instances/lock-date

When an instance locks, names, addresses, rates, and totals are denormalised onto the instance and its children. Future template edits or rate changes can never rewrite the past.

Artifacts & Tags

GET    /api/v1/engine/instances/:id/artifacts
POST /api/v1/engine/instances/:id/artifacts
GET /api/v1/engine/instances/:id/tags
POST /api/v1/engine/instances/:id/tags

Backend Route Files

Twelve backend route files were rewritten to point at core_engine:

FileRole
templates.js (1671 lines)Wizard backend — programs, slots, participants, billing, staff, vehicles, requirements, finalize.
engine.jsInstance operations API (23 endpoints).
util_syncRethread.jsActive-window instance generation.
util_generateBilling.jsBilling line generation when instances are projected.
finance.jsPayment lifecycle, invoice tracking.
dashboard.jsLive operations dashboard queries.
programs.jsProgram list endpoints.
activities.jsProgram activities CRUD.
intentions.jsIntent CRUD (processing logic still to come).
loom.jsLegacy loom routes, patched but slated for replacement by engine.js.
master-schedule.jsCalendar-style schedule queries.
roster.jsStaff roster queries.

What stayed in core_ops: shift notes, shift cover claims, shift density cache, vehicle/venue documents and inspections, and the Type 2 session tables.


Program Creation Wizard

The wizard at page_prog_create walks the user through six steps:

  1. Details — program name, type, venue, schedule days
  2. Time Slots — pickup, activity, meal, other, dropoff with click-to-edit and adjacent give/take
  3. Participants — selection with photos, address preferences, participant fees
  4. Billing — real billing rates from 73 seeded codes, group ratios auto-calculate from 1:1 base rate, NF2F sibling lines
  5. Staffing — staff placeholders (auto / manual / open)
  6. Vehicles — vehicle placeholders (auto / manual / personal car)
  7. Finalize — calls util_syncRethread and util_generateBilling to project instances and billing lines into the active window

Key wizard features

  • Real billing rates — 73 seeded NDIS-style codes in dropdowns, group ratios auto-calculate
  • NF2F billing lines — each line has an NF2F button creating a sibling line tagged NF2F, with manual hours and rate
  • Participant photos — served via extension-free route at /api/v1/participants/:id/photo (probes for .png, .webp, .jpg, .jpeg)
  • Participant feesparticipant_fee column with checkbox and amount input
  • Click-to-edit time slots — editing a slot pushes against neighbours instead of overlapping
  • Draft management — drafts can be deleted, POST returns full program row

What's Next

AreaStatus
Lock endpoint denormalisation testingEndpoint exists, end-to-end snapshotting needs verification
syncRethread child completenessNeeds to confirm all instance children are generated (attendance, shifts, vehicles, billables, routes)
Intent-application engineintentions.js is CRUD-only — intents need side effects (cancel, swap venue, override times/billing)
Live operations frontendpage_workspace does not yet exist — the active workspace where today's instances are visible
Settings page renamepage_loom-settings → system-org settings page for threshold knobs
Template change historyChangelog for program blueprint changes

Quick Reference

ItemLocation
Schemacore_engine.* (19 tables, DB2)
Wizard backendbackend/routes_v1p/templates.js
Instance APIbackend/routes_v1p/engine.js/api/v1/engine
Sync enginebackend/routes_v1p/util_syncRethread.js
Billing enginebackend/routes_v1p/util_generateBilling.js
Wizard frontendadmin/src/js/pages/page_prog_create.js
Migrationsadmin/tasks/sql/sql-current/20260420_core_engine_*.sql
Build statusadmin/tasks/tasks_future/workshed-loom/BUILD_STATUS.md
Blog postFrom Loom to Engine