# ducthanh8386/lms-final architecture

> Architecture diagram of the GitHub repository ducthanh8386/lms-final, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ducthanh8386/lms-final
- Repository: https://github.com/ducthanh8386/lms-final

## Overview

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: [`frontend/src/App.jsx`](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/App.jsx) (App), [`frontend/src/lib/supabaseClient.js`](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/lib/supabaseClient.js) (Supabase client), [`frontend/src/services/adminService.js`](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/adminService.js) (Admin service), [`frontend/src/components/ProtectedRoute.jsx`](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/components/ProtectedRoute.jsx) (Guard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_frontend_src_main(("main<br/>entrypoint<br/>[main.jsx]"))
  node_frontend_src_app["App<br/>router<br/>[App.jsx]"]
  node_protected_route{{"Guard<br/>route gate<br/>[ProtectedRoute.jsx]"}}
  node_main_layout["Shell<br/>layout<br/>[MainLayout.jsx]"]
  node_auth_ctx["Auth state<br/>context<br/>[AuthContext.jsx]"]
  node_cart_ctx["Cart state<br/>context<br/>[CartContext.jsx]"]
  node_confirm_ctx["Confirm state<br/>context<br/>[ConfirmContext.jsx]"]
  node_toast_ctx["Toast state<br/>context<br/>[ToastContext.jsx]"]
  node_auth_service["Auth service<br/>[authService.js]"]
  node_course_service["Course service<br/>[courseService.js]"]
  node_class_service["Class service<br/>[classService.js]"]
  node_teacher_service["Teacher service<br/>[teacherService.js]"]
  node_admin_service["Admin service<br/>[adminService.js]"]
  node_login_page["Login<br/>page<br/>[Login.jsx]"]
end

subgraph group_student["Student area"]
  node_course_list["Courses<br/>page<br/>[CourseList.jsx]"]
  node_cart_page["Cart<br/>page<br/>[Cart.jsx]"]
end

subgraph group_teacher["Teacher area"]
  node_teacher_courses["Manage courses<br/>page<br/>[CourseManage.jsx]"]
end

subgraph group_admin["Admin area"]
  node_admin_dashboard["Admin dashboard<br/>page<br/>[AdminDashboard.jsx]"]
end

subgraph group_supabase["Supabase backend"]
  node_supabase_client[("Supabase client<br/>data client<br/>[supabaseClient.js]")]
  node_supabase_migrations[("Migrations<br/>schema")]
  node_admin_users_fn{{"Admin users fn<br/>edge function<br/>[index.ts]"}}
end

node_frontend_src_main -->|"bootstraps"| node_frontend_src_app
node_frontend_src_app -->|"routes through"| node_protected_route
node_frontend_src_app -->|"wraps"| node_main_layout
node_frontend_src_app -->|"exposes"| node_login_page
node_frontend_src_app -->|"exposes"| node_course_list
node_frontend_src_app -->|"exposes"| node_cart_page
node_frontend_src_app -->|"exposes"| node_teacher_courses
node_frontend_src_app -->|"exposes"| node_admin_dashboard
node_frontend_src_app -->|"shares state"| node_auth_ctx
node_frontend_src_app -->|"shares state"| node_cart_ctx
node_frontend_src_app -->|"shares state"| node_confirm_ctx
node_frontend_src_app -->|"shares state"| node_toast_ctx
node_protected_route -->|"checks"| node_auth_ctx
node_login_page -->|"calls"| node_auth_service
node_auth_service -->|"uses"| node_supabase_client
node_course_list -->|"calls"| node_course_service
node_cart_page -->|"calls"| node_class_service
node_teacher_courses -->|"calls"| node_teacher_service
node_admin_dashboard -->|"calls"| node_admin_service
node_course_service -->|"uses"| node_supabase_client
node_class_service -->|"uses"| node_supabase_client
node_teacher_service -->|"uses"| node_supabase_client
node_admin_service -->|"uses"| node_supabase_client
node_supabase_client -.->|"targets"| node_supabase_migrations
node_admin_service -->|"invokes"| node_admin_users_fn
node_supabase_migrations -.->|"supports"| node_admin_users_fn

click node_frontend_src_main "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/main.jsx"
click node_frontend_src_app "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/App.jsx"
click node_protected_route "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/components/ProtectedRoute.jsx"
click node_main_layout "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/components/layout/MainLayout.jsx"
click node_auth_ctx "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/context/AuthContext.jsx"
click node_cart_ctx "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/context/CartContext.jsx"
click node_confirm_ctx "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/context/ConfirmContext.jsx"
click node_toast_ctx "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/context/ToastContext.jsx"
click node_supabase_client "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/lib/supabaseClient.js"
click node_auth_service "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/authService.js"
click node_course_service "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/courseService.js"
click node_class_service "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/classService.js"
click node_teacher_service "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/teacherService.js"
click node_admin_service "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/adminService.js"
click node_login_page "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/pages/auth/Login.jsx"
click node_course_list "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/pages/student/CourseList.jsx"
click node_cart_page "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/pages/student/Cart.jsx"
click node_teacher_courses "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/pages/teacher/CourseManage.jsx"
click node_admin_dashboard "https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/pages/admin/AdminDashboard.jsx"
click node_supabase_migrations "https://github.com/ducthanh8386/lms-final/blob/main/supabase/migrations/20260620000000_initial_schema.sql"
click node_admin_users_fn "https://github.com/ducthanh8386/lms-final/blob/main/supabase/functions/admin-users/index.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_src_main,node_frontend_src_app,node_protected_route,node_main_layout,node_auth_ctx,node_cart_ctx,node_confirm_ctx,node_toast_ctx,node_auth_service,node_course_service,node_class_service,node_teacher_service,node_admin_service,node_login_page toneBlue
class node_course_list,node_cart_page toneAmber
class node_teacher_courses toneMint
class node_admin_dashboard toneRose
class node_supabase_client,node_supabase_migrations,node_admin_users_fn toneIndigo
```

## Components

### Frontend SPA

React/Vite single-page app, routing, shared state, and UI flows

- [main](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/main.jsx): entrypoint · Vite/React bootstrapping entry · `frontend/src/main.jsx`
- [App](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/App.jsx): router · Top-level route composition · `frontend/src/App.jsx`
- [Guard](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/components/ProtectedRoute.jsx): route gate · Authenticated and role-based access control · `frontend/src/components/ProtectedRoute.jsx`
- [Shell](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/components/layout/MainLayout.jsx): layout · Common app chrome around protected pages · `frontend/src/components/layout/MainLayout.jsx`
- [Auth state](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/context/AuthContext.jsx): context · Session, user, and role state · `frontend/src/context/AuthContext.jsx`
- [Cart state](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/context/CartContext.jsx): context · Student cart and checkout coordination · `frontend/src/context/CartContext.jsx`
- [Confirm state](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/context/ConfirmContext.jsx): context · Global destructive-action confirmation flow · `frontend/src/context/ConfirmContext.jsx`
- [Toast state](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/context/ToastContext.jsx): context · Global notification and feedback state · `frontend/src/context/ToastContext.jsx`
- [Auth service](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/authService.js): service · Login, register, and session operations · `frontend/src/services/authService.js`
- [Course service](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/courseService.js): service · Course browsing and course data access · `frontend/src/services/courseService.js`
- [Class service](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/classService.js): service · Class enrollment and class data access · `frontend/src/services/classService.js`
- [Teacher service](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/teacherService.js): service · Instructor-side course and workflow operations · `frontend/src/services/teacherService.js`
- [Admin service](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/services/adminService.js): service · Administrative operations and privileged data access · `frontend/src/services/adminService.js`
- [Login](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/pages/auth/Login.jsx): page · Authentication entry page · `frontend/src/pages/auth/Login.jsx`

### Student area

Learner-facing browsing, cart, checkout, and study screens

- [Courses](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/pages/student/CourseList.jsx): page · Student course catalog · `frontend/src/pages/student/CourseList.jsx`
- [Cart](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/pages/student/Cart.jsx): page · Student purchase and enrollment cart · `frontend/src/pages/student/Cart.jsx`

### Teacher area

Instructor-facing course, class, assessment, and grading screens

- [Manage courses](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/pages/teacher/CourseManage.jsx): page · Teacher course administration · `frontend/src/pages/teacher/CourseManage.jsx`

### Admin area

Administrative oversight and user/course governance

- [Admin dashboard](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/pages/admin/AdminDashboard.jsx): page · Admin oversight console · `frontend/src/pages/admin/AdminDashboard.jsx`

### Supabase backend

Direct Supabase client, schema migrations, and edge functions

- [Supabase client](https://github.com/ducthanh8386/lms-final/blob/main/frontend/src/lib/supabaseClient.js): data client · Frontend connection to Supabase · `frontend/src/lib/supabaseClient.js`
- [Migrations](https://github.com/ducthanh8386/lms-final/blob/main/supabase/migrations/20260620000000_initial_schema.sql): schema · Postgres schema and feature evolution · `supabase/migrations/20260620000000_initial_schema.sql`
- [Admin users fn](https://github.com/ducthanh8386/lms-final/blob/main/supabase/functions/admin-users/index.ts): edge function · Privileged admin user management · `supabase/functions/admin-users/index.ts`

## Connections

- 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
