# hrdpaliwal93/ai-based-learning-management-system architecture

> Architecture diagram of the GitHub repository hrdpaliwal93/ai-based-learning-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hrdpaliwal93/ai-based-learning-management-system
- Repository: https://github.com/hrdpaliwal93/ai-based-learning-management-system

## Overview

1. **Overall shape**
   - EduPortal is a two-tier LMS: a **React/Vite frontend** and a **PHP 8 REST API backend**, backed by **MySQL**. The architecture is centered on browser clients calling backend endpoints over HTTP, with the backend mediating all database access, authentication, and AI usage.

2. **Frontend boundary**
   - The frontend lives under `frontend/src` and is organized by **role and workflow** rather than by technical layer alone: `pages/student`, `pages/teacher`, shared `components`, global `context`, and `services`. This makes the UI split naturally into student and teacher experiences while sharing auth/session state and common layout components.

3. **Frontend entry and app shell**
   - `main.jsx`, `App.jsx`, `Navbar.jsx`, `Sidebar.jsx`, and `ProtectedRoute.jsx` define the application shell and route protection. `AuthContext.jsx` is the main client-side state boundary for session/user identity, while `services/api.js` is the single API access layer used by pages to talk to the backend.

4. **Student-facing workflows**
   - Student features are concentrated in `pages/student`: course catalog and details, test-taking, result viewing, and the student dashboard. These screens consume data from course, enrollment, test, result, dashboard, and AI endpoints, forming the student data flow: browse → enroll → consume resources → take test → view scores/recommendations.

5. **Teacher-facing workflows**
   - Teacher functionality is in `pages/teacher`: course management, resource management, analytics, and test building. These screens map to backend operations for creating/updating courses, uploading course materials, generating or publishing tests, and retrieving performance analytics and feedback.

6. **Backend API segmentation**
   - The backend is organized as a set of functional endpoint groups under `backend/api`: `auth`, `courses`, `enrollments`, `resources`, `tests`, `dashboard`, and `ai`. This is a classic REST-style decomposition where each folder represents a bounded feature area with its own CRUD or action-oriented endpoints.

7. **Authentication and session model**
   - `backend/api/auth/login.php`, `register.php`, `logout.php`, and `me.php` indicate **session-based authentication** rather than JWT. The frontend likely checks current identity through `me.php`, stores user state in `AuthContext`, and gates routes via `ProtectedRoute`. This makes auth a cross-cutting boundary spanning most UI and API calls.

8. **Core data model and persistence**
   - MySQL is the primary system of record, defined in `backend/database/schema.sql` and seeded by `seed.sql`. All durable LMS entities appear to be persisted here: users, courses, enrollments, resources, tests, submissions, results, and feedback. The backend config in `backend/api/config/db.php` is the database access boundary.

9. **Course, enrollment, and resource flow**
   - Courses are managed through `backend/api/courses/*`, enrollment through `backend/api/enrollments/*`, and course materials through `backend/api/resources/*`. The likely flow is: teacher creates course → course is published/listed → student enrolls → resources become available to enrolled students. This is one of the main domain pipelines in the system.

10. **Testing and assessment pipeline**
   - `backend/api/tests/*` covers test creation, publishing, submission, feedback, and result retrieval. This subsystem supports both teacher-authored tests and student attempts, with endpoints for individual results, all results, and course-scoped test data. It is the main academic assessment boundary in the system.

11. **AI subsystem**
   - `backend/api/ai/chat.php`, `generate_quiz.php`, and `recommendations.php` form a dedicated AI integration layer. The README identifies **Groq AI / Llama 3.3 70B** as the model provider, meaning the backend is the AI gateway: the frontend calls these endpoints, and the backend handles prompt construction, provider access, and response shaping. This keeps external AI credentials and logic off the client.

12. **Analytics and dashboards**
   - `backend/api/dashboard/student.php` and `teacher.php` aggregate data from multiple tables into role-specific summaries. These endpoints are important diagram nodes because they sit above raw CRUD APIs and produce derived views: progress statistics for students and performance/engagement analytics for teachers.

13. **Shared configuration and cross-cutting concerns**
   - `backend/api/config/cors.php` controls browser access boundaries, `ai.php` holds AI-related config, and `db.php` centralizes database connectivity. These are the main infrastructure-level files that influence how the frontend can call the backend and how the backend reaches external services.

14. **Deployment and runtime assumptions**
   - The project is designed for a **local XAMPP-style Apache + MySQL + PHP deployment** on the backend and a **Vite dev server** on the frontend. That means the frontend and backend are separate runtimes during development, connected over HTTP, with PHP acting as the API server and MySQL as the persistent store.

15. **Architectural summary for a diagram**
   - A good diagram should show: browser users split into **student** and **teacher** roles; a **React frontend** with shared auth/state and role-specific pages; a **PHP API** divided into auth, courses, enrollments, resources, tests, dashboards, and AI; a **MySQL database** as the system of record; and an **external AI provider** reached only through backend AI endpoints.

Main entry points: [`frontend/src/services/api.js`](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/services/api.js) (API client), [`frontend/src/App.jsx`](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/App.jsx) (App shell), [`backend/database/schema.sql`](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/database/schema.sql) (MySQL), [`frontend/src/main.jsx`](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/main.jsx) (App entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_main["App entry<br/>shell<br/>[main.jsx]"]
  node_app["App shell<br/>routing<br/>[App.jsx]"]
  node_authctx["Auth state<br/>client state<br/>[AuthContext.jsx]"]
  node_apiclient["API client<br/>http client<br/>[api.js]"]
  node_nav["Nav chrome<br/>ui shell<br/>[Navbar.jsx]"]
  node_sidebar["Sidebar<br/>ui shell<br/>[Sidebar.jsx]"]
  node_guard["Route guard<br/>access control<br/>[ProtectedRoute.jsx]"]
  node_student["Student UI<br/>role views<br/>[Dashboard.jsx]"]
  node_teacher["Teacher UI<br/>role views<br/>[Dashboard.jsx]"]
  node_login["Login<br/>auth page<br/>[Login.jsx]"]
  node_register["Register<br/>auth page<br/>[Register.jsx]"]
end

subgraph group_backend["Backend"]
  node_authapi["Auth API<br/>session endpoints<br/>[login.php]"]
  node_coursesapi["Courses API<br/>course endpoints<br/>[index.php]"]
  node_enrollapi["Enrollments API<br/>enrollment endpoints<br/>[enroll.php]"]
  node_resourcesapi["Resources API<br/>content endpoints<br/>[upload.php]"]
  node_testsapi["Tests API<br/>assessment endpoints<br/>[create.php]"]
  node_dashapi["Dashboards<br/>aggregate endpoints<br/>[student.php]"]
  node_aiapi["AI API<br/>ai gateway<br/>[chat.php]"]
  node_db[("MySQL<br/>relational store<br/>[schema.sql]")]
end

subgraph group_external["External"]
  node_ai(("Groq AI<br/>external model"))
end

node_browser(("Browser users<br/>actors"))

node_browser -->|"loads"| node_main
node_main -->|"boots"| node_app
node_app -->|"shares session"| node_authctx
node_app -->|"protects routes"| node_guard
node_app -->|"renders"| node_nav
node_app -->|"renders"| node_sidebar
node_app -->|"routes to"| node_login
node_app -->|"routes to"| node_register
node_student -->|"reads data"| node_apiclient
node_teacher -->|"reads data"| node_apiclient
node_apiclient -->|"calls"| node_authapi
node_apiclient -->|"calls"| node_coursesapi
node_apiclient -->|"calls"| node_enrollapi
node_apiclient -->|"calls"| node_resourcesapi
node_apiclient -->|"calls"| node_testsapi
node_apiclient -->|"calls"| node_dashapi
node_apiclient -->|"calls"| node_aiapi
node_authapi -->|"persists session data"| node_db
node_coursesapi -->|"reads/writes"| node_db
node_enrollapi -->|"reads/writes"| node_db
node_resourcesapi -->|"reads/writes"| node_db
node_testsapi -->|"reads/writes"| node_db
node_dashapi -->|"aggregates"| node_db
node_aiapi -->|"invokes"| node_ai

click node_main "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/main.jsx"
click node_app "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/App.jsx"
click node_authctx "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/context/AuthContext.jsx"
click node_apiclient "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/services/api.js"
click node_nav "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/components/Navbar.jsx"
click node_sidebar "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/components/Sidebar.jsx"
click node_guard "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/components/ProtectedRoute.jsx"
click node_student "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/pages/student/Dashboard.jsx"
click node_teacher "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/pages/teacher/Dashboard.jsx"
click node_login "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/pages/auth/Login.jsx"
click node_register "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/pages/auth/Register.jsx"
click node_authapi "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/auth/login.php"
click node_coursesapi "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/courses/index.php"
click node_enrollapi "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/enrollments/enroll.php"
click node_resourcesapi "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/resources/upload.php"
click node_testsapi "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/tests/create.php"
click node_dashapi "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/dashboard/student.php"
click node_aiapi "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/ai/chat.php"
click node_db "https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/database/schema.sql"

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_main,node_app,node_authctx,node_apiclient,node_nav,node_sidebar,node_guard,node_student,node_teacher,node_login,node_register toneBlue
class node_authapi,node_coursesapi,node_enrollapi,node_resourcesapi,node_testsapi,node_dashapi,node_aiapi,node_db toneAmber
class node_ai toneMint
class node_browser toneNeutral
```

## Components

### Frontend

React/Vite client for student and teacher workflows

- [App entry](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/main.jsx): shell · Bootstraps the React app and global providers · `frontend/src/main.jsx`
- [App shell](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/App.jsx): routing · Top-level routing and application composition · `frontend/src/App.jsx`
- [Auth state](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/context/AuthContext.jsx): client state · Session and identity state shared across the UI · `frontend/src/context/AuthContext.jsx`
- [API client](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/services/api.js): http client · Single frontend gateway for backend API calls · `frontend/src/services/api.js`
- [Nav chrome](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/components/Navbar.jsx): ui shell · Primary navigation and layout controls · `frontend/src/components/Navbar.jsx`
- [Sidebar](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/components/Sidebar.jsx): ui shell · Secondary navigation for role-based sections · `frontend/src/components/Sidebar.jsx`
- [Route guard](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/components/ProtectedRoute.jsx): access control · Protects authenticated routes in the client · `frontend/src/components/ProtectedRoute.jsx`
- [Student UI](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/pages/student/Dashboard.jsx): role views · Student-facing pages for learning and assessment · `frontend/src/pages/student/Dashboard.jsx`
- [Teacher UI](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/pages/teacher/Dashboard.jsx): role views · Teacher-facing pages for course and assessment management · `frontend/src/pages/teacher/Dashboard.jsx`
- [Login](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/pages/auth/Login.jsx): auth page · Client sign-in screen · `frontend/src/pages/auth/Login.jsx`
- [Register](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/frontend/src/pages/auth/Register.jsx): auth page · Client account creation screen · `frontend/src/pages/auth/Register.jsx`

### Backend

PHP REST API and database layer

- [Auth API](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/auth/login.php): session endpoints · Login, register, logout, and current-user session checks · `backend/api/auth/login.php`
- [Courses API](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/courses/index.php): course endpoints · Course CRUD and course-specific listings · `backend/api/courses/index.php`
- [Enrollments API](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/enrollments/enroll.php): enrollment endpoints · Student enrollment and enrollment lookup endpoints · `backend/api/enrollments/enroll.php`
- [Resources API](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/resources/upload.php): content endpoints · Course material upload, listing, and deletion · `backend/api/resources/upload.php`
- [Tests API](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/tests/create.php): assessment endpoints · Test creation, publishing, submission, feedback, and results · `backend/api/tests/create.php`
- [Dashboards](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/dashboard/student.php): aggregate endpoints · Student and teacher summary endpoints · `backend/api/dashboard/student.php`
- [AI API](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/api/ai/chat.php): ai gateway · Chat, quiz generation, and recommendations endpoints · `backend/api/ai/chat.php`
- [MySQL](https://github.com/hrdpaliwal93/ai-based-learning-management-system/blob/main/backend/database/schema.sql): relational store · System of record for users, courses, enrollments, resources, tests, and results · `backend/database/schema.sql`

### External

Outside runtime dependencies

- **Groq AI**: external model · External Llama-based AI provider used through the backend

### Other components

- **Browser users**: actors · Student and teacher users interacting through the web app

## Connections

- Browser users → App entry: loads · Users open the frontend app
- App entry → App shell: boots · App entry renders the router and providers
- App shell → Auth state: shares session · Routes depend on client auth state
- App shell → Route guard: protects routes · Authenticated sections are wrapped by route guards
- App shell → Nav chrome: renders · Application shell includes global navigation
- App shell → Sidebar: renders · Application shell includes role navigation
- App shell → Login: routes to · Unauthenticated users reach login
- App shell → Register: routes to · Unauthenticated users reach registration
- Student UI → API client: reads data · Student pages call backend endpoints through the API client
- Teacher UI → API client: reads data · Teacher pages call backend endpoints through the API client
- API client → Auth API: calls · Client checks and updates session state
- API client → Courses API: calls · Course browsing and management requests
- API client → Enrollments API: calls · Enrollment actions and lookups
- API client → Resources API: calls · Resource listing and upload actions
- API client → Tests API: calls · Assessment creation, submission, and results
- API client → Dashboards: calls · Dashboard summary requests
- API client → AI API: calls · AI-powered chat, quiz, and recommendation requests
- Auth API → MySQL: persists session data · Authentication reads and updates user records
- Courses API → MySQL: reads/writes · Course data is stored in MySQL
- Enrollments API → MySQL: reads/writes · Enrollment state is stored in MySQL
- Resources API → MySQL: reads/writes · Resource metadata and ownership are stored in MySQL
- Tests API → MySQL: reads/writes · Tests, submissions, feedback, and results are stored in MySQL
- Dashboards → MySQL: aggregates · Dashboard views are computed from persistent data
- AI API → Groq AI: invokes · Backend sends prompts to the external model provider
