# learnwiseai/moodle-local_learnwise architecture

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

- Interactive diagram: https://gitdiagram.com/learnwiseai/moodle-local_learnwise
- Repository: https://github.com/learnwiseai/moodle-local_learnwise

## Overview

LearnWise is a single-tenant Moodle plugin connecting Moodle courses and users to the LearnWise AI assistant. The main administrator workflow configures the assistant or LTI tool, optionally enables Moodle web services for course-content ingestion, and can enable live Moodle APIs and AI-assisted grading. The plugin also implements OAuth2/OpenID authorization for live API access. Several capabilities are documented but their runtime wiring is not shown in the sampled source, so those links are documented or left unconnected rather than inferred.

Main entry points: [`classes/local/OAuth2/Server.php`](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/Server.php) (OAuth server), [`classes/output/setup.php`](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/output/setup.php) (Integration setup), [`auth.php`](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/auth.php) (OAuth entry), [`classes/form/updatelti.php`](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/form/updatelti.php) (LTI configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_admin["Moodle setup"]
  node_settings["Integration setup<br/>[setup.php]"]
  node_lti_config["LTI configuration<br/>[updatelti.php]"]
  node_webservice_setup["Web-service setup"]
end

subgraph group_assistant["Assistant features"]
  node_assistant_launch["Assistant launch<br/>[setup.js]"]
  node_course_content["Course-content ingestion"]
  node_ai_assessment["AI assessment<br/>[grade.php]"]
end

subgraph group_api["Moodle APIs"]
  node_live_api["Live Moodle API"]
  node_api_dispatch["API dispatch<br/>[api_server.php]"]
end

subgraph group_oauth["OAuth security"]
  node_oauth_entry["OAuth entry<br/>[auth.php]"]
  node_oauth_server["OAuth server<br/>[Server.php]"]
  node_oauth_authorize["Authorization controller"]
  node_oauth_token["Token controller"]
  node_oauth_resource["Resource controller"]
  node_oauth_userinfo["OpenID user info"]
  node_oauth_storage[("Token storage<br/>[storage.php]")]
  node_oauth_library["OAuth request handler<br/>[server.php]"]
end

node_administrator(("Site administrator"))
node_learnwise(("LearnWise platform"))
node_course_user(("Course user"))

node_administrator -->|"configures"| node_settings
node_settings -->|"configures LTI"| node_lti_config
node_settings -->|"offers setup"| node_webservice_setup
node_webservice_setup -->|"issues access token"| node_learnwise
node_learnwise -->|"selects content"| node_course_content
node_course_user -->|"opens assistant"| node_assistant_launch
node_lti_config -->|"sets up LTI link"| node_learnwise
node_learnwise -->|"requests Moodle data"| node_live_api
node_learnwise -->|"requests grading"| node_ai_assessment
node_oauth_entry -->|"creates server"| node_oauth_library
node_oauth_library -->|"uses server"| node_oauth_server
node_oauth_server -->|"dispatches authorization"| node_oauth_authorize
node_oauth_server -->|"dispatches token requests"| node_oauth_token
node_oauth_server -->|"dispatches resource requests"| node_oauth_resource
node_oauth_server -->|"dispatches user info"| node_oauth_userinfo
node_oauth_entry -->|"uses controller"| node_oauth_authorize
node_oauth_server -.->|"uses storage"| node_oauth_storage

click node_settings "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/output/setup.php"
click node_lti_config "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/form/updatelti.php"
click node_webservice_setup "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/form/webservicesetup.php"
click node_assistant_launch "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/amd/src/setup.js"
click node_course_content "https://github.com/learnwiseai/moodle-local_learnwise/tree/main/classes/external"
click node_live_api "https://github.com/learnwiseai/moodle-local_learnwise/tree/main/classes/external"
click node_ai_assessment "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/external/assign/grade.php"
click node_api_dispatch "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/api_server.php"
click node_oauth_entry "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/auth.php"
click node_oauth_server "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/Server.php"
click node_oauth_authorize "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/Controller/AuthorizeController.php"
click node_oauth_token "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/Controller/TokenController.php"
click node_oauth_resource "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/Controller/ResourceController.php"
click node_oauth_userinfo "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/OpenID/Controller/UserInfoController.php"
click node_oauth_storage "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/storage.php"
click node_oauth_library "https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/server.php"

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_settings,node_lti_config,node_webservice_setup,node_course_user toneBlue
class node_assistant_launch,node_course_content,node_ai_assessment toneAmber
class node_live_api,node_api_dispatch toneMint
class node_oauth_entry,node_oauth_server,node_oauth_authorize,node_oauth_token,node_oauth_resource,node_oauth_userinfo,node_oauth_storage,node_oauth_library toneRose
class node_administrator,node_learnwise toneIndigo
```

## Components

### Moodle setup

- [Integration setup](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/output/setup.php): `classes/output/setup.php`
- [LTI configuration](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/form/updatelti.php): `classes/form/updatelti.php`
- [Web-service setup](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/form/webservicesetup.php): `classes/form/webservicesetup.php`

### Assistant features

- [Assistant launch](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/amd/src/setup.js): `amd/src/setup.js`
- [Course-content ingestion](https://github.com/learnwiseai/moodle-local_learnwise/tree/main/classes/external): `classes/external`
- [AI assessment](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/external/assign/grade.php): `classes/external/assign/grade.php`

### Moodle APIs

- [Live Moodle API](https://github.com/learnwiseai/moodle-local_learnwise/tree/main/classes/external): `classes/external`
- [API dispatch](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/api_server.php): `classes/api_server.php`

### OAuth security

- [OAuth entry](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/auth.php): `auth.php`
- [OAuth server](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/Server.php): `classes/local/OAuth2/Server.php`
- [Authorization controller](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/Controller/AuthorizeController.php): `classes/local/OAuth2/Controller/AuthorizeController.php`
- [Token controller](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/Controller/TokenController.php): `classes/local/OAuth2/Controller/TokenController.php`
- [Resource controller](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/Controller/ResourceController.php): `classes/local/OAuth2/Controller/ResourceController.php`
- [OpenID user info](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/local/OAuth2/OpenID/Controller/UserInfoController.php): `classes/local/OAuth2/OpenID/Controller/UserInfoController.php`
- [Token storage](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/storage.php): `classes/storage.php`
- [OAuth request handler](https://github.com/learnwiseai/moodle-local_learnwise/blob/main/classes/server.php): `classes/server.php`

### Other components

- **Site administrator**
- **LearnWise platform**
- **Course user**

## Connections

- Site administrator → Integration setup: configures
- Integration setup → LTI configuration: configures LTI (evidence: `classes/output/setup.php`)
- Integration setup → Web-service setup: offers setup (evidence: `classes/output/setup.php`)
- Web-service setup → LearnWise platform: issues access token
- LearnWise platform → Course-content ingestion: selects content
- Course user → Assistant launch: opens assistant
- LTI configuration → LearnWise platform: sets up LTI link
- LearnWise platform → Live Moodle API: requests Moodle data
- LearnWise platform → AI assessment: requests grading
- OAuth entry → OAuth request handler: creates server (evidence: `classes/server.php`)
- OAuth request handler → OAuth server: uses server (evidence: `classes/server.php`)
- OAuth server → Authorization controller: dispatches authorization (evidence: `classes/local/OAuth2/Server.php`)
- OAuth server → Token controller: dispatches token requests (evidence: `classes/local/OAuth2/Server.php`)
- OAuth server → Resource controller: dispatches resource requests (evidence: `classes/local/OAuth2/Server.php`)
- OAuth server → OpenID user info: dispatches user info (evidence: `classes/local/OAuth2/Server.php`)
- OAuth entry → Authorization controller: uses controller (evidence: `auth.php`)
- OAuth server → Token storage: uses storage
