Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Controller Architecture

This chapter outlines the controllers needed to implement the MÜSLI integration into MaMpf. Controllers are organized by functional area and follow Rails conventions with namespacing.

Overview

How to read this chapter

We do not expose a public API. "Primary caller" refers to who invokes the controller actions inside MaMpf: HTML forms (Turbo), background jobs, or teacher/editor UIs. Use these sections to wire views, jobs, and service objects to the right endpoints.

At a glance

NamespaceKey controllersPrimary caller
RegistrationCampaigns, UserRegistrations, Policies, AllocationTeacher/Editor UI, Student UI, Job
RosterMaintenanceTeacher/Editor UI
AssessmentAssessments, Grading, ParticipationsTeacher/Editor UI, Tutor UI
StudentPerformanceRecords, Certifications, EvaluatorTeacher/Editor UI
ExamExamsTeacher/Editor UI
GradeSchemeSchemesTeacher/Editor UI
DashboardDashboard, Admin::DashboardStudent UI, Teacher/Editor UI

Controllers are grouped into the following namespaces:

  • Registration: Campaign setup, student registration, allocation
  • Roster: Post-allocation roster maintenance
  • Assessment: Assessment setup, grading, result viewing
  • StudentPerformance: Performance records, teacher certification, evaluator proposals
  • Exam: Exam management
  • GradeScheme: Grading scheme configuration
  • Dashboard: Student and teacher/editor views

Turbo responses

Controllers render HTML plus Hotwire responses:

  • Turbo Frames for partial page replacement within a frame.
  • Turbo Streams for broadcasting or incremental updates. Prefer frames for scoped, request/response UI flows; prefer streams for updates triggered by background jobs or actions affecting multiple parts of the page.

Registration Controllers

Registration::CampaignsController

Purpose

Manage registration campaigns for lectures.

ControllerPrimary callersResponses
Registration::CampaignsControllerTeacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
indexList all campaigns for a lecture
newForm to create a new campaign
createCreate campaign with divisions and policies
showView campaign details and status
editEdit campaign settings (before allocation)
updateUpdate campaign
destroyDelete campaign (if no registrations exist)

Responsibilities

  • CRUD operations for campaigns
  • Validate date ranges and capacity constraints
  • Display campaign status (draft, open, closed, processing, completed)
  • Pre-flight checks: Before opening campaigns with student_performance policies:
    • Verify all lecture students have StudentPerformance::Certification records
    • Ensure all certifications have status: :passed or :failed (no pending)
    • Block campaign opening with clear error message if checks fail
  • Pre-finalization checks: Before finalizing campaigns:
    • Re-validate certification completeness
    • Check for stale certifications (due to rule changes or record updates)
    • Prompt remediation workflow if issues exist

Registration::UserRegistrationsController

Purpose

Handle the student registration flow.

ControllerPrimary callersResponses
Registration::UserRegistrationsControllerStudent UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
indexShow available campaigns for current user
newPre-flight eligibility check; show registration form if eligible, error message if not
createSubmit registration with ranked preferences (preference-based) or direct registration (FCFS)
showView registration status and assigned roster
editModify preferences (before allocation deadline)
updateUpdate preferences
destroyWithdraw from campaign

Responsibilities

  • Pre-flight eligibility check on page load via campaign.evaluate_policies_for(user, phase: :registration)
  • Conditionally render registration interface based on eligibility result
  • Display clear rejection reasons when policies fail (before user invests effort)
  • Display eligibility status based on StudentPerformance::Certification
  • Show certification status (passed/failed) for exam campaigns
  • Handle preference ranking (drag-and-drop or priority input)
  • Show allocation results after campaign completes
  • Validate registration constraints

Registration::PoliciesController

Purpose

Admin interface for managing registration policies.

ControllerPrimary callersResponses
Registration::PoliciesControllerTeacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
indexList all policies for a campaign
newCreate policy form
createCreate eligibility or allocation policy
editModify policy
updateUpdate policy
destroyRemove policy

Responsibilities

  • Select policy type (eligibility vs allocation scoring)
  • Configure policies (score thresholds, enrollment requirements, etc.)
  • Policy preview/testing interface

Registration::AllocationController

Purpose

Trigger and monitor the allocation algorithm.

ControllerPrimary callersResponses
Registration::AllocationControllerTeacher/Editor UI, JobHTML, Turbo Frames/Streams

Actions

ActionPurpose
showView allocation status and preview
createTrigger allocation algorithm
retryRe-run allocation with adjusted parameters
finalizeCommit allocation results to rosters
allocate_and_finalizeCompute allocation and immediately finalize

Responsibilities

  • Run allocation algorithm as background job
  • Display allocation statistics (satisfaction rate, unassigned students)
  • Allow parameter adjustments before finalization
  • Create rosters from allocation results
  • Support single-step allocate_and_finalize flow when desired
  • Delegate to Campaign API: allocate!, finalize!, allocate_and_finalize!
  • Validate certification completeness before finalization

Roster Controllers

Roster::MaintenanceController

Purpose

Handle post-allocation roster changes.

ControllerPrimary callersResponses
Roster::MaintenanceControllerTeacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
indexOverview of all rosters for a lecture
showView specific roster with participants
editModify roster metadata (e.g., tutor/time/place)
updateSave roster metadata changes; perform move/add/remove
moveMove students between rosters

Responsibilities

  • Manual roster adjustments
  • Move participants between groups
  • Tutor reassignment
  • Capacity override
  • Does not re-run the automated solver or reopen the campaign

Assessment Controllers

Assessment::AssessmentsController

Purpose

Configure assessments for lectures.

ControllerPrimary callersResponses
Assessment::AssessmentsControllerTeacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
indexList all assessments for a lecture
newCreate assessment form
createCreate assessment with parameters
showView assessment details
editModify assessment settings
updateUpdate assessment
destroyDelete assessment (if no grades exist)
publish_resultsPublish results to students

Responsibilities

  • Create and configure assessments
  • Set max points, weight, thresholds
  • Configure eligibility contribution
  • Link to specific divisions or entire lecture
  • Control visibility lifecycle (publish/unpublish results)

Assessment::GradingController

Purpose

Enter and manage grades.

ControllerPrimary callersResponses
Assessment::GradingControllerTutor UI, Teacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
showGrading interface for an assessment
updateBulk update grades for multiple students
exportExport grades as CSV
importImport grades from CSV

Responsibilities

  • Display grading table (filterable by roster/division)
  • Bulk grade entry
  • Validate grade values (0 to max_points)
  • Calculate derived metrics (percentages, pass/fail)

Assessment::ParticipationsController

Purpose

Student view of assessment results.

ControllerPrimary callersResponses
Assessment::ParticipationsControllerStudent UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
indexList all assessments student can view
showView grades and feedback for specific assessment

Responsibilities

  • Display personal grades
  • Show aggregate statistics (if configured)
  • Feedback and comments from graders

Exam Controllers

ExamsController

Purpose

Manage exam instances for lectures.

ControllerPrimary callersResponses
ExamsControllerTeacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
indexList all exams for a lecture
newCreate exam form
createCreate exam
showView exam details and certification summary
editModify exam settings
updateUpdate exam
destroyDelete exam

Responsibilities

  • Exam scheduling (date, location)
  • Registration deadline management
  • Display certification summary (number of students passed/failed)
  • Link to certification dashboard for detailed review
  • Export eligible student list (students with status: :passed)

Student Performance Controllers

StudentPerformance::RecordsController

Purpose

View and manage performance records (factual data only).

ControllerPrimary callersResponses
StudentPerformance::RecordsControllerTeacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
indexList performance records for all students
showDetailed performance breakdown for one student
recomputeTrigger recomputation for specific student(s)
exportExport performance data

Responsibilities

  • Display factual performance data (points, achievements)
  • Show computation timestamp and rule version
  • Trigger manual recomputation when needed
  • Export performance data for analysis
  • No eligibility interpretation - pure factual data display

StudentPerformance::CertificationsController

Purpose

Teacher certification workflow for eligibility decisions.

ControllerPrimary callersResponses
StudentPerformance::CertificationsControllerTeacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
indexCertification dashboard showing all students
createBulk create certifications from proposals
updateManual override of individual certification
bulk_acceptAccept all proposals in one action
remediateHandle stale/pending certifications before campaign operations
exportExport certification list

Responsibilities

  • Display certification dashboard with proposals
  • Show proposed status (passed/failed) for each student
  • Bulk accept proposals (common case)
  • Manual override with required note field
  • Handle rule change diff: "12 students would change: failed → passed"
  • Remediation workflow for pending/stale certifications
  • Verify completeness before allowing campaign operations
  • Track certification history (certified_at, certified_by)

StudentPerformance::EvaluatorController

Purpose

Generate eligibility proposals using the Evaluator service.

ControllerPrimary callersResponses
StudentPerformance::EvaluatorControllerTeacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
bulk_proposalsGenerate proposals for all lecture students
preview_rule_changeShow impact of rule modifications before saving
single_proposalGenerate proposal for specific student (review case)

Responsibilities

  • Call StudentPerformance::Evaluator.bulk_proposals(lecture)
  • Display proposals in reviewable format
  • Show rule change preview: affected students and status changes
  • Generate single proposal for manual review cases
  • Does not create Certifications - only generates proposals for teacher review

Grade Scheme Controllers

GradeScheme::SchemesController

Purpose

Configure grading schemes for courses.

ControllerPrimary callersResponses
GradeScheme::SchemesControllerTeacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
indexList all schemes for a course
newCreate grading scheme
createSave scheme with thresholds
editModify scheme
updateUpdate scheme
applyApply scheme to assessment results
previewPreview grade distribution
  • Define grade thresholds (1.0, 1.3, 1.7, ..., 5.0)
  • Configure bonus points and rounding policies
  • Preview grade distribution before finalizing
  • Apply scheme to generate final grades

Dashboard Controllers

DashboardController

Purpose

Student-facing dashboard.

ControllerPrimary callersResponses
DashboardControllerStudent UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
showOverview of all enrollments, registrations, grades

Responsibilities

  • Display active campaigns requiring action
  • Show roster assignments
  • List assessment results
  • Display exam eligibility status

Admin::DashboardController

Purpose

Teacher and editor dashboard.

ControllerPrimary callersResponses
Admin::DashboardControllerTeacher/Editor UIHTML, Turbo Frames/Streams

Actions

ActionPurpose
showOverview of all campaigns, rosters, assessments for managed lectures

Responsibilities

  • Quick access to campaign management
  • Roster statistics and allocation quality metrics
  • Grading progress tracking
  • Exam eligibility overview

RESTful Design Principles

RESTful design

All controllers follow Rails conventions:

  • Use standard REST actions where possible.
  • Nest resources appropriately (lectures/:id/campaigns).
  • Use member vs collection routes correctly.
  • Render HTML and Hotwire responses (Turbo Frames/Streams); no public JSON API.

Authorization

Authorization

Controllers integrate with CanCanCan abilities:

  • load_and_authorize_resource for standard CRUD.
  • Custom checks for special actions (allocation, grading).
  • Role-based access (student, tutor, teacher, editor, admin).

Error Handling

Error handling

Controllers should handle:

  • ActiveRecord validation errors (display form errors).
  • Authorization failures (redirect with flash message).
  • Background job failures (show status and retry option).
  • Constraint violations (e.g., deleting campaign with registrations).