Code Documentation - FaqiangMei/MHA-Survey-Portal GitHub Wiki
Code Documentation
This page links the major areas of the Rails codebase to the functionality described in the wiki. Use it as a map when you are exploring or making changes.
Controllers
Application-wide
application_controller.rbβ Authenticates users, enforces modern browser support, preloads notifications, and redirects incomplete student profiles to onboarding.sessions_controller.rbβ Custom Devise session flow that triggers survey auto-assignment after login and protects against GET sign-out calls.omniauth_callbacks_controller.rbβ Handles Google OAuth callbacks, restricts logins to TAMU domains, and routes users to their role dashboards.dashboards_controller.rbβ Entry point for all role dashboards plus admin/advisor management tables and the environment-controlled role switcher.accounts_controller.rbβ Allows users to update their display name.settings_controller.rbβ Persists per-user accessibility preferences such as text scaling and notification settings.notifications_controller.rbβ Lists, shows, and marks notifications as read; supports bulk mark-all-read.student_profiles_controller.rbβ CRUD interface for completing and updating student profile details.student_records_controller.rbβ Builds the survey completion matrix used by advisors/admins.surveys_controller.rbβ Student-facing survey submission and autosave endpoints.survey_responses_controller.rbβ Renders individual survey responses, secure downloads, and composite assessment PDFs.question_responses_controller.rb,feedbacks_controller.rb,questions_controller.rb,categories_controller.rb,evidence_controller.rb,pages_controller.rbβ Supporting CRUD and utility endpoints used across the app.
Namespaced controllers
admin/base_controller.rbβ Ensures only admins access the namespace.admin/surveys_controller.rbβ Survey builder, lifecycle management, and change logging.admin/questions_controller.rbβ Global question management helpers.admin/survey_change_logs_controller.rbβ Exposes survey audit history.advisors/base_controller.rbβ Guards advisor-only flows while permitting admin oversight.advisors/surveys_controller.rbβ Track-aware assignment/unassignment tools and due-date management.advisors/students_controller.rbβ Advisor-specific student details and updates.api/reports_controller.rbβ JSON API powering the analytics dashboard (filters, benchmark, competency, course, alignment endpoints).accounts_controller.rb,settings_controller.rb, and Devise controllers support all namespaces.
Models
Userβ Core devise record with Google OAuth, role enum, profile associations, and text scaling preference.Student,Advisor,Adminβ Profile tables keyed by*_id, linked back toUserand used for authorisation scopes.Survey,Category,Question,SurveyQuestionβ Survey structure including track assignments (SurveyTrackAssignment) and nested categories/questions.SurveyAssignmentβ Connects surveys to students/advisors with due dates, completion tracking, and notification hooks.SurveyResponse,QuestionResponse,StudentQuestionβ Response materialisation and analytics helpers including signed download tokens.Feedbackβ Advisor feedback per survey/category with optional scoring.Notificationβ Polymorphic in-app notification records with deduplication.SurveyChangeLog,SurveyAuditLogβ Audit history for admin actions.CategoryQuestion,SurveyCategoryTag,SurveyTrackAssignment,SurveyAssignmentβ Join models supporting survey metadata.CategoryandQuestionexpose enums for question types and required logic used throughout controllers and views.
Services & Modules
Reports::DataAggregatorβ Central analytics service calculating filters, benchmarks, competency summaries, course outcomes, and alignment data based on the current userβs scope.Reports::ExcelExporterβ Builds XLSX dashboards from aggregator payloads using Axlsx.CompositeReportGeneratorβ Produces cached composite assessment PDFs by merging student answers and advisor feedback (requires WickedPdf).CompositeReportCacheβ Lightweight cache wrapper keyed by survey response fingerprint.SurveyAssignmentNotifierβ Utility for scheduling βdue soonβ and βpast dueβ notifications and sending ad-hoc alerts.SurveyAssignments::AutoAssigner(expected underapp/services/survey_assignments/) β Hook invoked on login/OAuth to assign track-appropriate surveys; ensure this service exists and is configured.
Background Jobs & Tasks
SurveyNotificationJobβ Processes notification events (:assigned,:due_soon,:past_due,:completed,:survey_updated,:survey_archived,:custom).ApplicationJobβ Base job inheriting from ActiveJob; queue configuration inconfig/queue.yml(polling dispatcher with configurable concurrency).- Rake tasks under
lib/tasks(notifications.rake,add_questions.rake) provide maintenance utilities. - The
scripts/coverage_report.rbhelper converts SimpleCov output into CI-friendly summaries.
Frontend Structure
- Stimulus controllers in
app/javascript/controllers/(reports_controller.js,filters_panel_controller.js,survey_bulk_controller.js) attach behaviour to Rails views. - React analytics app in
app/javascript/reports/app.jsrenders the advisor/admin dashboard using Chart.js 4; mounted viaReportsControllerviewreports/show.html.erb. - High-contrast and accessibility helpers reside in
app/javascript/application.jsalongside Turbo initialisation. - Tailwind CSS builds are managed through
bin/rails tailwindcss:*commands triggered in Docker (cssservice) or viabin/devlocally.
Views & Layouts
app/views/layouts/application.html.erbβ Primary layout with role-aware navigation, notification badge, and text-scaling CSS variables.app/views/layouts/auth.html.erbβ Minimal layout for Devise views.app/views/layouts/mailers/*.erbβ Base ActionMailer templates (Devise defaults).- Partial directories (
app/views/shared,app/views/reports, etc.) group reusable UI fragments like navbars, role switcher, and notification dropdowns.
API Endpoints
/api/reports/filtersβ Filter metadata for the analytics app./api/reports/benchmarkβ Cohort benchmark statistics./api/reports/competency-summary,/course-summary,/alignmentβ Data for charts and tables rendered in React./evidence/check_accessβ JSON endpoint to validate Google Drive URLs./upβ Rails health check consumed by uptime monitors.
Database Schema Highlights
- PostgreSQL primary store with UUID/sequence ids depending on table (see
db/schema.rb). userstable keyed byidwith enumrole, OAuth fields (uid,avatar_url), notification & text-scaling preferences.students,advisors,adminstables reuse*_idprimary keys that match the correspondingusers.idfor tight coupling.- Surveys reference categories/questions via
survey_idandcategory_id; responses link throughstudent_questionsandquestion_responses. - Notifications, assignments, change logs, and audit logs include indexed timestamps for efficient dashboard queries.
Supporting Artifacts
- Sample data:
db/seeds.rbpopulates surveys, assignments, notifications, and synthetic responses across cohorts. - Tests:
test/directory follows Minitest conventions (test_helper.rbenables optional SimpleCov viaCOVERAGE=1). - Tooling:
run_tests.rb(Ruby script) wrapsrails test;docker-compose.ymldefines local containers;Procfile.devandbin/devorchestrate foreman-style processes.
Refer back to the repository for deeper divesβeach class and module is documented inline with concise comments to speed up comprehension.