My App
CourseKitBackend

Built-in Constraints

Overlap, capacity, and availability constraint implementations

Overview

CourseKit ships with three built-in constraints that are registered automatically (unless enableBuiltInConstraints is set to false). Each extends the ScheduleConstraint abstract class.

OverlapConstraint

Detects instructor double-bookings and room time overlaps.

PropertyValue
type'overlap'
severity'error'

How it works:

  1. Groups all occurrences by instructor (via getInstructorsForEvent)
  2. Groups all occurrences by room
  3. Within each group, sorts by start time and checks for overlapping consecutive pairs
  4. Produces 'instructor-double-book' or 'room-overlap' conflicts
// Example conflict output
{
    id: 'overlap-instructor-inst1-event1-event2',
    type: 'instructor-double-book',
    severity: 'error',
    message: 'Instructor inst1 is double-booked between events event1 and event2',
    involvedEventIds: ['event1', 'event2'],
    involvedEntityIds: ['inst1'],
    metadata: { entityType: 'instructor', aStart: '...', aEnd: '...', bStart: '...' },
}

CapacityConstraint

Checks if the total student count across all assigned groups exceeds the room's capacity.

PropertyValue
type'capacity'
severity'warning'

How it works:

  1. For each occurrence with a room, fetches the group IDs
  2. Sums student counts across all groups
  3. Compares against room.capacity
  4. Skips rooms with capacity === 0 (unlimited)
// Example conflict output
{
    id: 'capacity-room1-event1-1709308800000',
    type: 'room-over-capacity',
    severity: 'warning',
    message: 'Room Lecture Hall A has capacity 50 but event has 75 students',
    involvedEventIds: ['event1'],
    involvedEntityIds: ['room1', 'group1', 'group2'],
    metadata: { roomCapacity: 50, totalStudents: 75, excess: 25 },
}

AvailabilityConstraint

Checks events against entity availability rules (blocked time windows).

PropertyValue
type'availability'
severity'error' for hard blocks, 'warning' for soft blocks

How it works:

  1. For each occurrence, collects all entities to check (room + instructors)
  2. Calls isEntityAvailable() for each entity
  3. Hard blocks produce severity: 'error'; soft blocks produce severity: 'warning'
// Example conflict output
{
    id: 'availability-inst1-event1-1709308800000',
    type: 'availability-violation',
    severity: 'error',
    message: 'instructor inst1 is blocked during event event1',
    involvedEventIds: ['event1'],
    involvedEntityIds: ['inst1'],
    metadata: { entityType: 'instructor', hardness: 'hard', blockStart: '...', blockEnd: '...' },
}

Built-in Constraints Summary

ConstraintTypeSeverityWhat it checks
OverlapConstraintoverlaperrorInstructor and room double-bookings
CapacityConstraintcapacitywarningRoom capacity vs. group size
AvailabilityConstraintavailabilityerror / warningEvents during blocked time windows

Custom Constraints

See the Custom Constraints guide for how to create your own.

On this page