How rohithuge/mathx works
Project Type and Purpose
• This is a full-stack, React-based single-page application (SPA) built with Vite, tailored for coding contests/competitions (MathX).
• Frontend uses React + Vite + Tailwind CSS; backend relies on Supabase (Postgres, Auth, Realtime) plus Supabase edge functions (Deno) for server-side logic.
• It integrates with an external code-execution API (Judge0) and uses client-side Web Workers for timer functionality.
File Structure Analysis
• Top-level files:
• index.html, vite.config.js, tailwind.config.js: build and styling setup
• config.js, .env: runtime configuration
• supabase/: Supabase project config + serverless functions
• src/ directory subdivided into:
• src/coding: “contest engine” module (routes, protected routes, code editor, contest state contexts, hooks for Judge0 and Supabase)
• src/components & src/layouts & src/pages: general app UI (landing, auth, admin, contest list, event pages)
• src/config & src/contexts & src/hooks: global configuration, authentication context, custom hooks (leaderboard, events, submissions)
• src/scripts: one-off scripts (e.g., data sync from Appwrite to Supabase)
• src/workers: client Web Worker for precise countdown timer
• supabase/functions: Deno-based edge functions (autoSubmit) for scheduled or triggered server-side tasks.
Key README Insights
a. Main Components
• Client (Web Browser)
• React SPA
• CodeEditor & UI components
• TimerWorker (Web Worker)
• Static Hosting (e.g., Vercel/Netlify/CDN)
• Supabase Backend
• Auth (JWT, OAuth)
• Realtime Database (Postgres + subscriptions)
• Edge Functions (Deno-based autoSubmit)
• External Services
• Judge0 API (code compilation/execution)
• Optional Appwrite (legacy data source synced via scripts)
• Database (Postgres) for contests, problems, submissions, leaderboards
b. Relationships & Interactions
1. User loads SPA from CDN/static host.
2. SPA authenticates via Supabase Auth → JWT token.
3. For contest pages:
• Web Worker spawns TimerWorker → keeps client-side timer in sync.
• SPA subscribes to Supabase Realtime for leaderboard updates.
4. When user submits code:
• SPA calls Judge0 API → polls for result via custom hook (useJudge0).
• Result is sent to Supabase (via insert into submissions table or edge function).
5. Supabase edge function (autoSubmit) can auto-grade or auto-submit on schedule.
6. Admin UI uses Supabase RPC or functions to manage contests/questions.
c. Architectural Patterns & Principles
• SPA with clear separation: “coding engine” vs. “public pages” vs. “admin console.”
• Context providers (ContestStageContext, AuthContext) for global state.
• Hooks for side-effects and data fetching (Supabase, Judge0).
• Use of Web Worker for non-blocking timekeeping.
• Serverless edge functions for timed or triggered backend logic.
d. Technologies & Frameworks
• Frontend: React, Vite, Tailwind CSS
• State & Data: React Context, custom Hooks, Supabase JS client
• Backend: Supabase (Auth, Realtime, Functions), Postgres
• External API: Judge0
• Build & Deployment: Vite, CDN/Netlify/Vercel, supabase CLI