Scheduling & Calendar
The appointment calendar, walk-in queue, resource allocation, and conflict prevention.
7 min read
Overview
The scheduling engine is the operational core of Kagami. It gives a location a real-time, conflict-free view of who is doing what, where, and with which resource — for any day or week. The front desk lives in this surface all day: booking, moving, cancelling, and managing walk-ins.
The calendar simultaneously enforces staff availability, physical resource allocation (rooms, chairs, equipment), and shift rules. It prevents double-booking at both the staff and resource level and stays in sync across all connected devices in real time.
Calendar Views
The calendar (/dashboard/calendar) has three views (Day, Week, List) plus a mobile layout.
Day View
The primary workspace. A scrollable time grid with one column per staff member. Appointment blocks are coloured by status and category, and can be dragged to a new time or staff column. A store switcher scopes the calendar to one location.
Week View
A seven-day overview showing capacity at a glance. Click any day to drill into the day view.
List View
A flat, date-ranged list of appointments, which can span several stores.
Appointment States
The appointment_status enum (migrations 0009 and 0116) has seven values. scheduled is a legacy alias of confirmed; the allowed moves live in lib/scheduling/transitions.ts.
| State | Meaning |
|---|---|
pending_confirmation |
Awaiting confirmation (for example an online request). Drawn with a dashed outline |
scheduled |
Legacy alias for confirmed, still present on older rows |
confirmed |
Booked and confirmed |
in_progress |
Service actively under way (stays editable so services can be added mid-visit) |
completed |
Billed or finished. Final |
cancelled |
Cancelled. Final; a reason is required |
no_show |
Client did not arrive; a reason is required. Can be corrected back to confirmed, in_progress or completed |
There is no separate "checked in" status. Arrival is handled by the walk-in queue and the check-in link (a location can enable checkin_enabled, which adds the client to the queue).
Transition rules: open statuses (scheduled, pending_confirmation, confirmed) can move, be edited, cancelled, started or marked no-show. in_progress can be completed or cancelled. A billed appointment cannot be changed until its invoice is voided; voiding sets a completed appointment back to in_progress.
Creating an Appointment
From any empty cell on the calendar:
- Select the client (search existing or quick-create with name + phone)
- Add one or more services; each gets a staff assignment and a resource assignment
- System checks availability and computes the visit timeline. Service buffer times (
buffer_before_min,buffer_after_min) are stored on the service but are not applied here - Confirm. The server runs one guard (
assertStaffCanTake) before saving: the staff member must be active, work at the location and have the skill for each service, and the time must not be in the past - The appointment appears on the calendar and a confirmation message is sent
Deposits are not collected in this staff flow. They belong to the online booking flow (see Checkout, Deposits).
Multi-Service Visits
One appointment can hold several services. Each appointment_services row (a service line) has its own staff member, optional resource, start and end time, price and duration; the visit stays one record for the client and for checkout. Services can be added to an in-progress visit (lib/multi-service-visits), and the staff guard runs again for the added line. Parallel or concurrent staff scheduling exists as a helper (createConcurrentStaffBlocks, SALO-563) but I could not find a brand-level "parallel services" setting wired to it (unverified).
Appointment Groups
/dashboard/appointment-groups links several appointments into a labelled group (appointment_groups and appointment_group_members, migration 0047), for example a bridal party or one client served by several staff. A member row carries an optional role (such as lead or assist). Groups are an organising link only; each appointment is still billed on its own.
Drag-to-Reschedule
Appointments can be dragged to a new time slot or to a different staff column in the day view. On drop, rescheduleAppointmentAction re-runs the same staff guard (skill, leave, hours, overlap) and either commits or shows the real reason. Cancelled, completed, no-show and billed appointments cannot be moved.
Walk-In Queue
A live queue (walk_in_queue) for walk-ins without a pre-booked appointment. Queue entry statuses are waiting, serving, done and cancelled.
- Front desk adds the walk-in (name or client, service, optional preferred stylist) with
addToQueueAction; it starts aswaiting - Staff move it to
serving, thendone.cancelledneeds a reason and thebookings.cancelpermission - If the entry is linked to an appointment,
donesets that appointment tocompletedandcancelledsets it tocancelled, but only when the appointment's current status allows it. If it does not, the queue entry still changes and staff see a message saying the appointment was left as it was - Staff without the cross-staff permission can only queue or change their own entries
A client can also join the queue from the check-in page when the location has checkin_enabled.
Waitlist
/dashboard/waitlist holds clients who want a slot that is not available (waitlist_entries, migration 0027): client, service, store, preferred date, preferred time of day (free text such as morning), preferred staff and notes. Statuses are pending, notified, booked, expired and cancelled. Staff update an entry from pending or notified; re-queuing to pending clears the notified and resolved times. When an appointment is cancelled, the WhatsApp assistant ranks waitlist candidates for the freed slot (lib/ai/cancellation-matcher.ts) and offers it to the top client with a claim button.
Resource Allocation
Physical resources (rooms, chairs, stations, equipment) are rows in resources with a type and max_concurrent:
- A service line may reference one
resource_id - A database trigger (
fn_check_resource_overlap, migration 0009) rejects an overlapping booking of the same resource withdouble_booking_resource; there is no override /dashboard/resource-allocationshows availability for a time window- The day calendar has staff columns only; there is no per-resource column mode
Conflict and Double-Booking Prevention
Every booking write goes through assertStaffCanTake (lib/booking/availability.ts). It always blocks:
- Staff who are inactive, not at this location, or without the skill for a service
- Staff on approved or pending leave (never overridable)
- A start time that has already passed (about a 5 minute grace)
It also checks working hours or roster, closed days, and overlap with another of the staff member's appointments. For these soft rules, a booking made by an owner, brand manager, location manager or front desk user (allowManagerOverride) gets a warning and proceeds; a stylist gets the error. The message names the actual clash.
Realtime Sync
Appointment, queue and related table changes are pushed to open calendars through Supabase Realtime postgres_changes channels (lib/realtime/use-realtime-sync.ts), so two front-desk users see each other's changes. Writes use conditional updates on the current status, so a concurrent change cannot be silently overwritten; the loser gets an error naming the appointment's current state.
Non-Bookable Time
There is no free-form "calendar block" entity. Time that cannot be booked comes from:
- Store hours and staff shifts or roster (soft rule, overridable by managers and front desk)
- Approved or pending leave in
time_off(never overridable; declined and cancelled leave does not block, migration 0282) - Location closures (
location_closures): full days or partial-day open/close times, managed at/dashboard/settings/closures - Equipment maintenance is tracked separately (
equipment_assets) and does not block the calendar (unverified)
Business Rules
| Rule | Behaviour |
|---|---|
| Staff double-booking | Warning for managers/front desk, error for stylists |
| Resource double-booking | Always blocked by a database trigger; no override |
| Out-of-shift / outside store hours | Same as staff double-booking |
| Staff lacks the service skill | Always blocked, no override |
| Approved or pending leave | Always blocked, no override |
| Booking in the past | Blocked (about 5 minutes grace); managers can book earlier today with a warning |
| Cancel or no-show | A reason is required; cancelling needs the bookings.cancel permission |
| Editing a billed appointment | Blocked until the invoice is voided |
| Cross-staff calendar | scheduling.book_all_staff permission (default owner, managers, front desk); off means own calendar only |
| Time zone | The location's configured time zone |
Configuration Options
Online booking settings (lib/booking/settings-schema.ts) include advance_days (0 to 365), slot_interval_min (1 to 480 minutes), cancellation_hours and the deposit settings (require_deposit, deposit_pct). Operating hours, closures and shifts are set per location. Service buffers are stored on the service but not applied to availability (see Catalog). Parallel services, stylist self-edit rights and a no-show policy are not covered here; check the code before relying on them.
Key Data Entities
- appointments: the visit record (client, location, status, notes)
- appointment_services: each service line (staff, optional resource, start, end, price, duration)
- appointment_groups and appointment_group_members: link of related appointments
- walk_in_queue: walk-in entries (
waiting,serving,done,cancelled) - waitlist_entries: clients waiting for a slot
- time_off, location_closures: leave and closures that block booking
- resources: rooms, chairs, equipment units