How ducthanh8386/lms-final works
1. High-level shape
- This is an LMS-style application called lms-cour.
- The architecture is split into a React single-page frontend and a Supabase backend for auth, database, and serverless functions.
- There is no separate custom backend server in the repo; application logic is mostly in the frontend service layer plus Supabase SQL/functions.
2. Frontend runtime and deployment
- The frontend lives under frontend/ and uses Vite + React.
- frontend/vercel.json indicates the SPA is deployed on Vercel.
- frontend/.env.example and src/lib/supabaseClient.js show the frontend is configured to connect directly to Supabase via environment variables.
3. App shell and routing boundary
- src/main.jsx and src/App.jsx are the entry points.
- ProtectedRoute.jsx enforces authenticated/role-based access.
- MainLayout.jsx and Navbar.jsx define the common application shell around most pages.
- The page structure is organized by persona and feature area: auth, student, teacher, admin, plus a public Home page.
4. Cross-cutting client state
- The main shared state is handled with React context:
- AuthContext.jsx for user/session/role state
- CartContext.jsx for student cart/checkout flow
- ConfirmContext.jsx for destructive-action confirmation dialogs
- ToastContext.jsx for user notifications
- These contexts are the main in-browser coordination layer; most pages likely depend on them instead of passing props deeply.
5. Feature-oriented UI organization
- UI is split by user role:
- Student pages: course list/detail, cart, checkout, classes, learning, schedule, quiz, lesson study
- Teacher pages: course/class/lesson/assignment/quiz/schedule/grading/order management, students, settings
- Admin pages: dashboard, course approval, user management
- This suggests the system is a multi-tenant educational platform with distinct workflows for browsing/enrolling, teaching, and administration.
6. Service layer as the frontend-to-backend boundary
- src/services/ contains domain-specific API wrappers:
- authService, courseService, classService, studentService, teacherService
- assignmentService, quizService, scheduleService
- adminService, notificationService
- These services are the main data-access boundary from React into Supabase.
- src/hooks/useCourses.js indicates some data is further abstracted into reusable hooks.
7. Supabase backend responsibilities
- src/lib/supabaseClient.js shows the frontend talks directly to Supabase.
- The supabase/migrations/ folder defines the backend schema and feature evolution:
- 20260620000000_initial_schema.sql
- 20260621_classes.sql
- 20260621_quiz_engine.sql
- 20260621_schedules_notifications.sql
- This implies the backend is primarily Postgres + Supabase auth/policies, with schema-managed domain data for classes, quizzes, schedules, and notifications.
8. Serverless backend extension
- supabase/functions/admin-users/index.ts is a Supabase Edge Function.
- This is the one explicit custom backend function in the repo, and its name suggests it handles privileged admin user operations that should not be done directly from the client.
9. Domain data flows
- Authentication flow: login/register pages call auth services, which use Supabase auth; AuthContext stores the session; ProtectedRoute gates access by role.
- Student commerce/enrollment flow: course browsing → add to cart → checkout detail → enrollment/my classes/my learning.
- Teaching flow: teacher creates/manages courses, classes, lessons, assignments, quizzes, schedules, then reviews grading and students.
- Admin flow: admin approves courses and manages users, likely via elevated database access and the admin-users function.
10. Shared UI and interaction components
- ConfirmDialog, Toast, and NotificationBell provide app-wide interaction patterns for confirmation, feedback, and alerts.
- WeeklyCalendar.jsx is a specialized scheduling component.
- TeacherTabs.jsx supports complex teacher-facing navigation.
11. Validation and schema layer
- src/schemas/index.js suggests some client-side schema/validation definitions exist for form or payload validation.
- This helps keep the service calls and page forms aligned with backend expectations.
12. Architecture summary for a diagram
- Draw the frontend as a React SPA with a shared shell, auth/role gating, and a service layer beneath feature pages.
- Draw Supabase as the backend boundary with:
- Auth
- Postgres schema managed by migrations
- Edge functions for privileged operations
- Show the main data paths as:
- UI page → context/hook → domain service → Supabase client → Supabase auth/db/function
- Emphasize the three user domains: student, teacher, and admin, since most pages and services are organized around those boundaries.
Main entry points: App.jsx App · supabaseClient.js Supabase client · adminService.js Admin service · ProtectedRoute.jsx Guard
Components 21
Frontend SPA
React/Vite single-page app, routing, shared state, and UI flows
- main · Vite/React bootstrapping entry
frontend/src/main.jsx - App · Top-level route composition
frontend/src/App.jsx - Guard · Authenticated and role-based access control
frontend/src/components/ProtectedRoute.jsx - Shell · Common app chrome around protected pages
frontend/src/components/layout/MainLayout.jsx - Auth state · Session, user, and role state
frontend/src/context/AuthContext.jsx - Cart state · Student cart and checkout coordination
frontend/src/context/CartContext.jsx - Confirm state · Global destructive-action confirmation flow
frontend/src/context/ConfirmContext.jsx - Toast state · Global notification and feedback state
frontend/src/context/ToastContext.jsx - Auth service · Login, register, and session operations
frontend/src/services/authService.js - Course service · Course browsing and course data access
frontend/src/services/courseService.js - Class service · Class enrollment and class data access
frontend/src/services/classService.js - Teacher service · Instructor-side course and workflow operations
frontend/src/services/teacherService.js - Admin service · Administrative operations and privileged data access
frontend/src/services/adminService.js - Login · Authentication entry page
frontend/src/pages/auth/Login.jsx
Student area
Learner-facing browsing, cart, checkout, and study screens
Teacher area
Instructor-facing course, class, assessment, and grading screens
- Manage courses · Teacher course administration
frontend/src/pages/teacher/CourseManage.jsx
Admin area
Administrative oversight and user/course governance
- Admin dashboard · Admin oversight console
frontend/src/pages/admin/AdminDashboard.jsx
Supabase backend
Direct Supabase client, schema migrations, and edge functions
- Supabase client · Frontend connection to Supabase
frontend/src/lib/supabaseClient.js - Migrations · Postgres schema and feature evolution
supabase/migrations/20260620000000_initial_schema.sql - Admin users fn · Privileged admin user management
supabase/functions/admin-users/index.ts
Connections 26
- main → App: bootstraps · React entry mounts the app
- App → Guard: routes through · Protected areas are gated by route checks
- App → Shell: wraps · Common shell around most authenticated pages
- App → Login: exposes · Public auth route
- App → Courses: exposes · Student browsing route
- App → Cart: exposes · Student cart route
- App → Manage courses: exposes · Teacher workflow route
- App → Admin dashboard: exposes · Admin workflow route
- App → Auth state: shares state · App-wide session and role state
- App → Cart state: shares state · Student cart state
- App → Confirm state: shares state · Confirmation dialog state
- App → Toast state: shares state · Notification state
- Guard → Auth state: checks · Access control depends on authenticated role state
- Login → Auth service: calls · Credentials and session actions
- Auth service → Supabase client: uses · Auth API boundary
- Courses → Course service: calls · Catalog data retrieval
- Cart → Class service: calls · Enrollment and checkout-related operations
- Manage courses → Teacher service: calls · Teacher CRUD and workflow operations
- Admin dashboard → Admin service: calls · Administrative operations
- Course service → Supabase client: uses · Data access through Supabase
- Class service → Supabase client: uses · Data access through Supabase
- Teacher service → Supabase client: uses · Data access through Supabase
- Admin service → Supabase client: uses · Data access through Supabase
- Supabase client → Migrations: targets · Client talks to schema-backed database and auth
- Admin service → Admin users fn: invokes · Privileged admin user operations go through edge function
- Migrations → Admin users fn: supports · Function operates against migrated backend schema