degreelink

Requirement Constraint System

Overview

The constraint system provides comprehensive validation, filtering, warnings, and credit exclusions for program requirements. Constraints ensure students meet specific academic requirements beyond simple credit or course counts.

System Components

1. Database Schema

File: backend/models/plan.py - PlanCourse model

Fields:

Purpose: Track which courses violate constraints so they can be excluded from credit calculations and displayed differently in the UI.


2. Constraint Evaluation & Credit Exclusion

File: backend/models/plan.py - Plan model

Features:

Purpose: Ensures that courses violating constraints don’t count toward requirement totals while still allowing them to exist in the plan.


3. Constraint Validation API

File: backend/routes/plans.py

New Endpoints:

New Method: Plan.check_course_constraint_violations()

Functionality:

Purpose: Allow frontend to check for constraint violations before committing courses to the database.


4. Course Addition with Constraint Support

File: backend/routes/plans.py

Changes:

Purpose: Support adding courses that violate constraints with proper tracking.


5. Constraint Display in UI

File: frontend/src/components/ProgressTracking.jsx - RequirementDetails component

Changes:

Purpose: Give users full visibility into constraint status and which courses violate them.


6. Filtered Course Suggestions

File: frontend/src/components/ProgressTracking.jsx - generateSuggestions()

Changes:

Purpose: Only suggest courses that would satisfy applicable constraints, improving user experience.


7. Constraint Violation Warnings

File: frontend/src/components/AddCourseToPlanModal.jsx

Changes:

Purpose: Warn users before adding courses that violate constraints while still allowing override for edge cases.


How It Works End-to-End

Adding a Course (Normal Flow)

  1. User selects “Add Course” from progress modal
  2. Chooses course and requirement category
  3. Clicks “Add Course”
  4. System validates against constraints via API
  5. If no violations: Course added normally
  6. Progress bar updates with credits counted

Adding a Course (With Constraint Violation)

  1. User selects course that violates constraint
  2. Clicks “Add Course”
  3. Warning modal appears showing:
    • Constraint type and description
    • Reason for violation
    • Notice that credits won’t count
  4. User can:
    • Cancel: Go back and choose different course
    • Add Anyway: Course added with violation flag
  5. Course appears in plan with:
    • Orange background
    • Warning icon
    • Violation reason displayed
    • Credits do NOT count toward requirement

Viewing Constraint Status

  1. User clicks on progress bar segment
  2. Modal shows requirement details
  3. “Constraints” section displays:
    • All constraints for requirement
    • Green checkmark for satisfied constraints
    • Red X for unsatisfied constraints
    • Specific reasons and tallies
  4. Courses section shows which courses violate constraints

Course Suggestions with Constraints

  1. User views course suggestions for requirement
  2. System checks if requirement has constraints
  3. Filters suggestions by:
    • Minimum course level requirements
    • Maximum credits for specific tags
    • Tag exclusions
  4. Only compliant courses are suggested

Constraint Types Supported

1. min_level_credits

Example: “At least 10 credits at 3000+ level”

2. min_tag_courses

Example: “At least 2 lab courses”

3. max_tag_credits

Example: “Maximum 7 credits of research courses”

4. min_courses_at_level

Example: “At least 3 courses at 4000 level”


Technical Details

Database Migration

flask db migrate -m "Add constraint violation tracking to PlanCourse"
flask db upgrade

New Database Fields

constraint_violation = db.Column(db.Boolean, default=False, index=True)
constraint_violation_reason = db.Column(db.Text)

API Request Format

POST /api/plans/by-code/ABC12345/validate-course-constraints
{
  "course_id": 123,
  "requirement_category": "Upper-Level Biology",
  "requirement_group_id": 45
}

API Response Format

{
  "violates": true,
  "violations": [
    {
      "constraint_type": "min_level_credits",
      "description": "At least 10 credits at 3000+ level",
      "reason": "Need 10cr at 3000+ level, have 6cr",
      "constraint_id": 7
    }
  ]
}

Benefits

  1. User Awareness: Users see all constraints and their status
  2. Guided Selection: Suggestions are pre-filtered to match constraints
  3. Informed Decisions: Clear warnings before violating constraints
  4. Flexibility: Users can still override constraints when necessary
  5. Accurate Progress: Violating courses don’t inflate credit counts
  6. Transparency: Violation reasons are clearly displayed

Future Enhancements (Optional)

  1. Constraint Autocorrection: Suggest alternative courses when violations detected
  2. Constraint Templates: Common constraint patterns for quick setup
  3. Historical Tracking: Log when constraints are overridden and why
  4. Bulk Validation: Validate entire plan against all constraints
  5. Smart Suggestions: AI-powered course recommendations considering constraints
  6. Constraint Dependencies: Support for complex multi-constraint logic

Testing Recommendations

  1. Basic Constraint Satisfaction:
    • Add courses that satisfy constraints → Credits count normally
  2. Level Constraints:
    • Try adding 1000-level course to requirement needing 3000+ → See warning
  3. Tag Constraints:
    • Add research courses beyond maximum → See warning and exclusion from suggestions
  4. Override Functionality:
    • Add violating course with override → Course added but credits don’t count
  5. UI Display:
    • Check constraint section shows all constraints with correct status
    • Verify violating courses have orange background and warning icon
  6. Filtered Suggestions:
    • Verify suggestions respect minimum level requirements
    • Check that maxed-out tags don’t appear in suggestions

Files Modified

Backend

Frontend


Conclusion

The constraint system is now fully functional with:

Users can now make informed decisions about course selection while the system ensures academic requirements are accurately tracked.