MOOC Utils

Utils like auto assignment solver extension and course notice announcment notification for MOOC courses

Website dashboard

Introduction#

The Next.js website: landing, auth, and dashboard for Notice Reminders, plus extension download for Assignment Solver. Routing, providers, API client, and UI structure.

Project structure#

The website is a Next.js application organized into:

  • App Router pages under website/app
  • Shared UI components under website/components
  • Client-side providers and context under website/lib
  • Global styles and fonts configured in the root layout

Core components#

  • Authentication Context: Centralized OTP login state, session refresh, and logout handling.
  • Providers: Wraps the app with React Query, theme switching, analytics, and auth context.
  • UI Components: Reusable building blocks for forms, cards, dialogs, and lists.
  • Pages: Marketing landing, notice reminders landing, OTP login, and user dashboard.

Key responsibilities:

  • Auth Context: request OTP, verify OTP, refresh session, logout, and expose user state.
  • Providers: configure caching policy, theme persistence, and global toasts.
  • UI Components: encapsulate business logic for subscriptions, notifications, and user profile.
  • Pages: orchestrate navigation and render appropriate components.

Architecture overview#

The system follows a layered architecture:

  • Presentation Layer: Next.js App Router pages and React components.
  • Domain Layer: UI components implementing business logic (subscriptions, notifications, user profile).
  • Data Access Layer: API client module encapsulating HTTP requests and error handling.
  • External Services: Notice Reminders API (courses, subscriptions, notifications, auth).

Detailed component analysis#

Authentication system (OTP login)#

The authentication system uses an OTP flow with two steps:

  • Request OTP: sends an email to the provided address.
  • Verify OTP: validates the 6-digit code and establishes a session.

Key behaviors:

  • Validation with Zod schemas for email and code length.
  • Controlled step transitions and error messaging.
  • Session persistence via cookies and refresh endpoint.

Notice reminders landing and course browsing#

The landing page integrates a multi-step signup flow:

  • Step 1: Course search and selection.
  • Step 2: Account details and notification preferences.
  • Step 3: OTP verification.
  • Step 4: Success screen with subscriptions.

Highlights:

  • Debounced search with Lucide icons and loading indicators.
  • Conditional validation for Telegram ID and at least one notification channel.
  • Mutation orchestration for OTP, channel creation, and subscriptions.

User dashboard#

The dashboard organizes content into three areas:

  • Top bar: welcome message and sign out.
  • Left column: notifications inbox and subscription manager.
  • Right column: user profile and quick actions.

API integration patterns#

The API client centralizes HTTP interactions:

  • Base URL configurable via environment variable.
  • Automatic cookie inclusion for session management.
  • Typed responses and errors mapped to a custom error class.
  • Dedicated functions for users, courses, subscriptions, channels, notifications, and auth.

UI component library usage#

Components use shadcn/ui primitives and Lucide icons:

  • Buttons, inputs, labels, cards, badges, dialogs, dropdowns, and toasts.
  • Consistent spacing, typography, and responsive layouts using Tailwind utilities.
  • Theming via next-themes with system preference support.

Dependency analysis#

External dependencies include Next.js, React Query, shadcn/ui, Tailwind CSS v4, and analytics.

Performance considerations#

  • React Query caching: staleTime configured to balance freshness and network usage.
  • Debounced search inputs to reduce API calls during typing.
  • Conditional query enabling to avoid unnecessary requests.
  • Efficient invalidation patterns to keep views synchronized after mutations.

Troubleshooting guide#

Common issues and resolutions:

  • Authentication failures: Verify OTP endpoint responses and error messages surfaced to the UI.
  • Network errors: Inspect API client error handling and ensure NEXT_PUBLIC_API_URL is set.
  • Session persistence: Confirm cookie-based auth and refresh endpoint usage.
  • UI state sync: Ensure React Query invalidations occur after mutations (e.g., subscriptions, notifications).

Conclusion#

Landing for strangers, dashboard for signed-in users, extension download as the bridge to Assignment Solver.