← Back to Documentation

πŸš€ Mission Control Documentation

Complete technical documentation for the Mission Control feature - a space-themed course management interface that displays both enrolled courses and free courses with gamified elements.

πŸ“‹ Feature Overview

Core Functionality

  • β€’ Displays enrolled courses from user enrollments
  • β€’ Shows free courses marked with payment_type = "free"
  • β€’ Space-themed UI with mission cards and difficulty indicators
  • β€’ Pagination for course navigation
  • β€’ Progress tracking with visual progress bars
  • β€’ FREE badge for free courses

Technical Stack

  • β€’ React/Next.js for frontend
  • β€’ Tailwind CSS for styling
  • β€’ Supabase for database and authentication
  • β€’ Custom hooks for data fetching
  • β€’ API routes for backend logic
  • β€’ Database migrations for schema changes

Frontend Components

πŸ“„ app/components/MissionControl.tsx

Main Mission Control component that displays enrolled and free courses in a space-themed interface

Features:

  • β€’ Space-themed UI with gradient backgrounds and holographic effects
  • β€’ Displays both enrolled courses and free courses
  • β€’ Pagination for course navigation
  • β€’ Mission difficulty indicators (Easy, Medium, Hard)
  • β€’ Progress tracking with visual progress bars
  • β€’ FREE badge for free courses
  • β€’ Responsive design with hover effects

Key Functions:

  • β€’ MissionCard: Individual course display component
  • β€’ getMissionIcon: Maps course icons to space-themed emojis
  • β€’ getMissionDifficulty: Calculates difficulty based on progress
  • β€’ useEnrolledCourses & useFreeCourses: Data fetching hooks

Custom Hooks

πŸ“„ app/hooks/useEnrolledCourses.ts

Custom React hook for fetching courses the user is enrolled in

Features:

  • β€’ Fetches courses based on user enrollments
  • β€’ Handles authentication via Bearer token
  • β€’ Error handling and loading states
  • β€’ Caches data to prevent unnecessary API calls

Key Functions:

  • β€’ fetchEnrolledCourses: Main data fetching function
  • β€’ Error handling for network and authentication issues
  • β€’ Loading state management

πŸ“„ app/hooks/useFreeCourses.ts

Custom React hook for fetching free courses from the database

Features:

  • β€’ Fetches courses with payment_type = "free"
  • β€’ Enriches courses with modules, lessons, and learning outcomes
  • β€’ Error handling and loading states
  • β€’ No-cache policy for real-time data

Key Functions:

  • β€’ fetchFreeCourses: Main data fetching function
  • β€’ Error handling for API failures
  • β€’ Loading state management

API Routes

πŸ“„ app/api/courses/enrolled/route.ts

API endpoint for fetching courses the user is enrolled in

Features:

  • β€’ Dual authentication support (cookies and Bearer tokens)
  • β€’ Fetches enrollments and maps to courses
  • β€’ Separates free and paid program enrollments
  • β€’ Includes additional free courses by title/category
  • β€’ Comprehensive error handling and logging

Key Functions:

  • β€’ GET: Retrieves enrolled courses with complete details
  • β€’ Authentication handling with fallback mechanisms
  • β€’ Course filtering logic for enrolled and free courses
  • β€’ Data enrichment with modules and learning outcomes

πŸ“„ app/api/courses/free/route.ts

API endpoint for fetching all free courses from the database

Features:

  • β€’ Filters courses by payment_type = "free"
  • β€’ Enriches courses with complete module and lesson data
  • β€’ Transforms data to match frontend expectations
  • β€’ Comprehensive error handling

Key Functions:

  • β€’ GET: Retrieves all free courses with complete details
  • β€’ Data transformation for frontend compatibility
  • β€’ Module and lesson enrichment
  • β€’ Learning outcomes integration

Database & Migrations

πŸ“„ supabase/migrations/20250120000001_add_payment_type_to_courses.sql

Database migration to add payment_type column to courses table

Features:

  • β€’ Adds payment_type VARCHAR(20) column with CHECK constraint
  • β€’ Sets default value to "paid"
  • β€’ Updates existing courses with appropriate payment types
  • β€’ Creates index for efficient filtering

Key Functions:

  • β€’ ALTER TABLE: Adds payment_type column
  • β€’ UPDATE: Populates existing courses with payment types
  • β€’ CREATE INDEX: Optimizes payment_type queries

Utility Scripts

πŸ“„ scripts/apply_payment_type_migration.cjs

Node.js script to apply payment_type migration to database

Features:

  • β€’ Connects to Supabase using environment variables
  • β€’ Updates existing courses with payment_type values
  • β€’ Verifies migration results
  • β€’ Tests free courses query functionality

Key Functions:

  • β€’ applyPaymentTypeMigration: Main migration function
  • β€’ Course categorization logic
  • β€’ Verification and testing procedures

βš™οΈ Technical Specifications

UI/UX Design

  • β€’ Theme: Space-themed with purple/blue gradients
  • β€’ Animations: Hover effects, pulse animations, gradient transitions
  • β€’ Responsive: Mobile-first design with grid layouts
  • β€’ Accessibility: Semantic HTML, keyboard navigation, screen reader support

Data Flow

  • β€’ Auth: Dual method (cookies preferred, Bearer token fallback)
  • β€’ Caching: No-cache for real-time data, client-side state management
  • β€’ Error Handling: Graceful degradation, user-friendly error messages
  • β€’ Loading: Skeleton loading, progress indicators

Performance

  • β€’ Pagination: 2 courses per page to reduce initial load
  • β€’ Lazy Loading: Components load data on mount
  • β€’ Optimization: Memoized components, efficient re-renders

πŸ“ Implementation Notes

Database Schema: The payment_type column was added to the courses table to distinguish between free and paid courses. This enables the Mission Control to display both enrolled courses and any free courses available to all users.

Authentication Strategy: The API routes support both cookie-based authentication (preferred) and Bearer token authentication (fallback) to ensure compatibility with different client implementations.

Data Enrichment: Courses are enriched with modules, lessons, and learning outcomes to provide complete information for the frontend display. This is done at the API level to minimize client-side processing.

Error Handling: Comprehensive error handling is implemented at multiple levels - API routes, custom hooks, and UI components - to ensure graceful degradation and user-friendly error messages.