Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

MoodleNet: Difference between revisions

From MoodleDocs
No edit summary
(45 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[File:Moodlenet-logo.png|400px]]
[[File:Moodlenet-logo.png|400px]]
== What is MoodleNet? ==
[https://moodle.net/ MoodleNet] is a flexible Open Education Technology platform for curating collections of the best known Open Educational (and other) Resources. You'll find more general information in the [https://docs.moodle.org/moodlenet/Main_Page MoodleNet user documentation].


<div style="background-color:yellow; padding:10px; text-align:center; font-size:1.2em; margin-bottom:1%;">Interested in contributing to this project? [https://docs.moodle.org/dev/MoodleNet/Contributing Click here!]</div>
If you are looking to get started as a MoodleNet developer, we recommend taking the [https://moodle.academy/course/view.php?id=74 MoodleNet for Developers course with Moodle Academy].
== Current status ==
Take a look at MoodleNet [https://tracker.moodle.org/projects/MDLNET?selectedItem=com.atlassian.jira.jira-projects-plugin%3Arelease-page&status=unreleased releases in our Tracker].
== Roadmap ==
* The MoodleNet release schedule is available on the [https://tracker.moodle.org/projects/MDLNET?selectedItem=com.atlassian.jira.jira-projects-plugin%3Arelease-page&status=unreleased MoodleNet Roadmap].
== MoodleNet architecture ==
MoodleNet is a full stack TypeScript/JavaScript system using:
* NodeJs
** NPM Packages [https://nodejs.org/en/knowledge/getting-started/npm/what-is-npm/]
** ESM Modules [https://nodejs.org/api/esm.html#introduction]
* Browsers
** ReactJs 18 [https://reactjs.org/]
** HTML5 [https://html.spec.whatwg.org/multipage/]
** CSS3 [https://www.w3.org/Style/CSS/]
== MoodleNet development environment ==
* NodeJs v16+ https://nodejs.org/
* ArangoDB (we suggest using [https://www.docker.com/ Docker])
* We recommend the open source IDE Visual Studio Code https://code.visualstudio.com/
=== Setup development environment ===
'''From the command line interface (CLI):'''


''Note: MoodleNet has now replaced the previous moodle.net site, which is now available at https://archive.moodle.net''
Ensure ArangoDB is running on localhost. You may use Docker with a command as below that can be tweaked as needed to ensure it is listening locally on port 8529:
docker run -e ARANGO_NO_AUTH=1 -p 8529:8529 --rm --name=mn3arango arangodb
Clone the repository, you may wish to fork it, but that's not required:
git clone <nowiki>https://gitlab.com/moodlenet/moodlenet.git</nowiki>
Change to the project's folder:
cd moodlenet
Install and initialize the project:
npm install
Install a development deployment:
npm run dev-install-backend [install dir name]
We have used "my-dev" as [install dir name] in the following instructions.


== What is MoodleNet? ==
You’ll find the newly created dev-installation in .dev-machines/my-dev and can create as many dev installations as you wish.
 
Run development backend:
npm run dev-start-backend my-dev
The first run of the system takes some time to install.
 
Once installed, browse http://localhost:8080
 
Questions? Please take a look in the [https://moodle.org/mod/forum/view.php?id=8726 MoodleNet Community] and [https://tracker.moodle.org/projects/MDLNET/summary Tracker] for answers or to ask for help.
=== The moodlenet extension package template ===
You can use core MoodleNet development environment and processes to develop your packages.
 
We recommend to start understanding the extension framework tweaking the template package “my-moodlenet-mjs-pkg-template” you’ll find it in the folder “packages”.
 
It is written in Javascript (EMS) instead of Typescript for a better understanding by newcomers.
 
Using typescript for package development is strongly recommended, as ts-experienced-devs will take advantage of the strongly-typed framework. However this requires good typescript knowledge, and some measures and ceremonies as all MoodleNet official packages are written in Typescript.
=== Install my-moodlenet-mjs-pkg-template ===
Signup using the web-app .
 
Note: Do not use sensible passwords as the system saves the email-password credentials unencrypted in the database.
 
Since no SMTP has been configured, the signup confirmation email supposed to be sent will be logged in the terminal:
hey {display name} confirm your email with /.pkg/@moodlenet/simple-email-auth/confirm-email/{LONG_HASH}
Copy the url path (/.pkg/@moodlenet/simple-email-auth/confirm-email/{LONG_HASH}) apply the localhost and paste it to the browser to confirm your email
localhost:8080/.pkg/@moodlenet/simple-email-auth/confirm-email/{LONG_HASH}
You’ll be logged in automatically and will be able to use the chosen credentials to login other times
When logged-in, navigate to the settings page in advanced section, where you can enable "dev mode”.
 
Then proceed to extensions / install extension section and submit the package absolute path to your package local folder.
 
The system will install the package and restart.
 
It will take some time to rebuild the web-app to see the results
 
Questions? Please take a look in the [https://moodle.org/mod/forum/view.php?id=8726 MoodleNet Community] and [https://tracker.moodle.org/projects/MDLNET/summary Tracker] for answers or to ask for help.
== Creating custom MoodleNet packages ==
A Moodlenet package is a standard [https://nodejs.org/api/esm.html#introduction ESM] package defining a main [https://nodejs.org/api/esm.html#introduction ESM] module.
@moodlenet/core will import it at startup.<syntaxhighlight lang="javascript" line="1" start="1">
// package.json
{
"name”: "my-moodlenet-package”,
"version”: "1",
 "type": "module",
"exports": {
  ".": "./src/server/main.mjs"
}
}
</syntaxhighlight>
===== Declare dependency =====
Your MN package must declare its dependency to the @moodlenet/core and other relevant packages package.json.
The core will import the main module at startup. The package "connects” to the core:<syntaxhighlight lang="javascript" line="1" start="1">
// package.json
{
  "peerDependencies”: {
    "@moodlenet/core”: "^0.2.0”
}
}
</syntaxhighlight>
=== Mono-Repository management with Lerna.js ===
MoodleNet project takes leverages [https://lerna.js.org/ lerna.js] to manage multi-package mono-repository .
 
Please refer to [https://lerna.js.org/ Lerna documentation] to understand how it manages mono-repo and project-packages dependency linking in the development environment.
 
When you need to add or remove a dependency for your package to some MoodleNet core package you can issue
lerna add -P <needed pkg> <packages/your-pkg-dir>
e.g. lerna add -P @moodlenet/react-app packages/my-moodlenet-mjs-pkg-template
 
You may also add/remove peerDependencies manually in package.json, in this case remember to execute:
npm run bs
From the root folder to update links to dependent packages.
=== Extend the web application ===
 
Use @moodlenet/react-app "plugin” api, during initialization to extend the web-app with a custom set of components.<syntaxhighlight lang="javascript" line="1" start="1">
import { pkgConnection } from '@moodlenet/core'
import reactApp from '@moodlenet/react-app'
const reactAppPkg = await pkgConnection(import.meta, reactApp)
await reactAppPkg.api('plugin')({
 mainComponentLoc:
    [‘path’, 'to', 'MainComponent.jsx']
})
</syntaxhighlight>
=== Define and deploy APIs ===
Your package will probably need to define and deploy its own APIs.
 
APIs are simply a collection of async functions - along with a params formal validation function - organized in a structured Js object.
 
APIs will be registered in the system with a path-like string, having your package name as prefix and apth following api structure.
// src/server/main.mjs
 
import { connectPkg, defApi } from '@moodlenet/core'
 
const myApis = {
 
   hello:{
 
      world: defApi( ctx =>
 
         async (p1,p2) => { return // something } ,
 
        (...params) => { /* … validate params */ }
 
   )
 
}
 
const connection = await connectPkg(import.meta, {


MoodleNet is a new open social media platform for educators, focussed on professional development and open content. It sustainably empowers communities of educators to share and learn from each other to improve the quality of education. It is an integral part of the Moodle ecosystem.
   apis: myApis


[[File:mn-presentation-march-20.png|thumb|Overview presentation (March 2020)|link=http://bit.ly/MNmarch20]]
})


* [https://new.moodle.net/ Project home]
// will register 1 api:  
* [https://gitlab.com/moodlenet Code repository]
* [https://gitlab.com/moodlenet/meta/-/boards/1477927 Issue tracker (federation testing)]
* [https://blog.moodle.net/ Blog]


== Current status ==
// my-moodlenet-package/1.0/hello/world
''Last updated: 21 April 2020''
=== APIs access ===
Apis can be accessed by any package running in NodeJs processes using specific @moodlenet/core functions pointing to the path of the desired API.
// from within the backend:


[https://docs.moodle.org/dev/MoodleNet/team The team] is working on ensuring the federation testing programme begins ASAP. You can follow our progress on [https://gitlab.com/moodlenet/meta/-/boards/1477927 this GitLab board]
// locate an package api by path


We are also liaising with the Moodle LMS team to ensure integration is ready for the 3.9 release, scheduled for June 2020.
import myMNPkgConn from


== Roadmap ==
   ‘my-moodlenet-package’


* '''Q1 2020''' - federation testing
const myMNPkg = await pkgConnection(import.meta, myMNPkgConn)
* '''Q2 2020''' - user testing


More detail on the [https://docs.moodle.org/dev/MoodleNet/Roadmap Roadmap] page.
const helloWorldApi =


== Documentation ==
  myMNPkg.api(‘hello/world’)


* [http://bit.ly/MN-planning Planning]
// call api as an async function
* [https://docs.moodle.org/dev/MoodleNet/tech/ Tech choices]
* [https://docs.moodle.org/dev/MoodleNet/VPD Value Proposition Design]
* [https://docs.moodle.org/dev/MoodleNet_whitepaper White paper] (2018)
* [https://docs.moodle.org/dev/MoodleNet/Sustainability Sustainability]
* [https://docs.moodle.org/dev/MoodleNet/Security Security]
* [https://docs.moodle.org/dev/MoodleNet/FAQ FAQ]
* [https://docs.moodle.org/dev/MoodleNet/scenarios Scenarios] (WIP)


== Community ==
const result = await


* [https://docs.moodle.org/dev/MoodleNet/Contributing Contributing]
  helloWorldApi(helloParam, worldParam)
* [https://changemap.co/moodle/moodlenet/ Suggestions from users]
=== APIs Primary Adapters ===
* [https://moodle.org/mod/forum/view.php?id=8657 Discussion forum]
Primary adapters implement API accessibility from external processes using some transport and protocols. Currently MoodleNet provides one Api-primary-adapter to access APIs by HTTP, which is implemented by @moodlenet/http-server. @moodlenet/http-server API HTTP adapter exposes package APIs as HTTP-POST endpoints. That endpoint is a path comprising the package name and the defined API path base, after the base API endpoint ( currently .pkgs ), having a JSON object body representing the api arguments. For example,
.pkgs/my-moodlenet-package/1.0/hello/world
<blockquote>
body:
</blockquote>
{
<blockquote>
 "args” : [
</blockquote>
   "hello-param1”,
<blockquote>
   "world-param2”
</blockquote>
 ]
<blockquote>
}
</blockquote>
Furthermore, in the web-app, @moodlenet/react-app provides libraries to use a syntax similar to within-backend-access for easy and strongly typed API calls to the server.
=== APIs Access Control ===
Packages register apis to @moodlenet/core which mediates api-call requests and responses, performing all fundamental checks and access controls.
* checks requested pkg version against deployed pkg version for granting compatibility
* calls api’s params formal validation function before forwarding to actual api function
* (TBD) checks matching of scopes associated with api and caller (user or package)
* provides the api a call-context holding an extensible set of metadata (e.g. user session, caller pkg … )


== Archive ==
* (TBD) any package can register for adding context metadata to an api call
* [https://docs.moodle.org/dev/MoodleNet/inspiration Inspiration]
=== APIs Authorization Scopes (TBD) ===
* [https://docs.moodle.org/dev/MoodleNet-research Other research]
The core will export functions to define package-specific auth-scopes - similar to OAuth specs.
* [https://docs.moodle.org/dev/MoodleNet-consultancy MoodleNet consultancy]
* [https://docs.moodle.org/dev/MoodleNet/Copyright_Directive European Copyright Directive]
* [https://docs.moodle.org/dev/MoodleNet/DPIA Data Protection Impact Assessment]
* [https://docs.moodle.org/dev/MoodleNet/Testing Beta testing]
* [https://docs.moodle.org/dev/MoodleNet/Decision_Log Decision log]


[[File:MoodleNet-technical-diagram.png|thumb|MoodleNet tech stack|link=https://docs.moodle.org/dev/MoodleNet/tech/]]
defApi() will provide options to apply own or other-pkg’s auth-scopes to api.


== Meetings and events ==
All Api accesses will be authorized at core level checking scopes assigned to api against scopes assigned to caller. Note that the caller may be a user using some primary adapter e.g. HTTP or can be simply another package, on its behalf, from within the system.


* [https://docs.moodle.org/dev/MoodleNet/globalmoot19 Global MoodleMoot (November 2019)]
Packages will have to declare which scopes they will need to be granted in order to perform their functionalities.
* [https://docs.moodle.org/dev/MoodleNet/mootieuk19-workshop MoodleMoot UK & Ireland (April 2019)]
* [https://blog.moodle.net/2018/sign-up-feedback/ Barcelona workweek (November 2018)]
* [https://docs.moodle.org/dev/MoodleNet/MootUS18-workshop MoodleMoot US (October 2018)]
* [https://docs.moodle.org/dev/MoodleNet/MozFest18-workshop Mozilla Festival workshop (October 2018)]
* [https://docs.moodle.org/dev/MoodleNet/Front-end_dev_workshop Front-end development workshop (September 2018)]
* [https://blog.moodle.net/2018/alt-c/ ALT-C presentation (September 2018)]
* [https://docs.moodle.org/dev/MountainMoot18 MountainMoot session (July 2018)]
* [https://docs.moodle.org/dev/MoodleNet-MootES18 MoodleMoot Spain session (June 2018)]
* [https://docs.moodle.org/dev/MoodleNet/Design_Sprint Design Sprint (May 2018)]
* [https://blog.moodle.net/2018/project-moodlenet-overview-v0-4/ UK & Ireland MoodleMoot sessions (March 2018)]
* [https://docs.moodle.org/dev/MoodleNet-MootUS17  Miami MoodleMoot sessions (Nov 2017)]


== Credits ==
Package scope-dependencies should be granted by the admin at installation time in order to complete the installation - similar to what happens on smartphones.
Icons from [https://www.flaticon.com flaticon.com]
== Testing MoodleNet packages ==
Once we’re happy with package development on dev-environment, we can try to install it on a real MoodleNet installation, using the admin UI.


Installation of MoodleNet in a production-like environment is a one liner cmd:
npx install \ @moodlenet/create \ dest/folder
Ensure ArangoDB is running and once inside the "dest/folder" installation directory:
npx @moodlenet/core
Create a user and navigate to the settings page where you can enable "dev mode”. Then proceed to extensions/install section and submit the package absolute path to local folder.


Questions? Please take a look in the [https://moodle.org/mod/forum/view.php?id=8726 MoodleNet Community] and [https://tracker.moodle.org/projects/MDLNET/summary Tracker] for answers or to ask for help.
== Important links ==
* [https://moodledev.io/general/development/tracker Using Tracker]
* [https://www.npmjs.com/package/@moodlenet/ce-platform Code repository]
* [https://docs.moodle.org/moodlenet/Main_Page MoodleNet user documentation]
* [https://moodle.org/mod/forum/view.php?id=8726 MoodleNet news and discussion]
* [https://tracker.moodle.org/secure/RapidBoard.jspa?rapidView=167&view=detail MoodleNet Issue Tracker]
* [https://gitlab.com/moodlenet/moodlenet/-/issues MoodleNet Gitlab Issues]
[[es:MoodleNet]]
[[es:MoodleNet]]

Revision as of 09:39, 7 December 2022

Moodlenet-logo.png

What is MoodleNet?

MoodleNet is a flexible Open Education Technology platform for curating collections of the best known Open Educational (and other) Resources. You'll find more general information in the MoodleNet user documentation.

If you are looking to get started as a MoodleNet developer, we recommend taking the MoodleNet for Developers course with Moodle Academy.

Current status

Take a look at MoodleNet releases in our Tracker.

Roadmap

MoodleNet architecture

MoodleNet is a full stack TypeScript/JavaScript system using:

  • NodeJs
    • NPM Packages [1]
    • ESM Modules [2]
  • Browsers

MoodleNet development environment

Setup development environment

From the command line interface (CLI):

Ensure ArangoDB is running on localhost. You may use Docker with a command as below that can be tweaked as needed to ensure it is listening locally on port 8529:

docker run -e ARANGO_NO_AUTH=1 -p 8529:8529 --rm --name=mn3arango arangodb

Clone the repository, you may wish to fork it, but that's not required:

git clone https://gitlab.com/moodlenet/moodlenet.git

Change to the project's folder:

cd moodlenet

Install and initialize the project:

npm install

Install a development deployment:

npm run dev-install-backend [install dir name]

We have used "my-dev" as [install dir name] in the following instructions.

You’ll find the newly created dev-installation in .dev-machines/my-dev and can create as many dev installations as you wish.

Run development backend:

npm run dev-start-backend my-dev

The first run of the system takes some time to install.

Once installed, browse http://localhost:8080

Questions? Please take a look in the MoodleNet Community and Tracker for answers or to ask for help.

The moodlenet extension package template

You can use core MoodleNet development environment and processes to develop your packages.

We recommend to start understanding the extension framework tweaking the template package “my-moodlenet-mjs-pkg-template” you’ll find it in the folder “packages”.

It is written in Javascript (EMS) instead of Typescript for a better understanding by newcomers.

Using typescript for package development is strongly recommended, as ts-experienced-devs will take advantage of the strongly-typed framework. However this requires good typescript knowledge, and some measures and ceremonies as all MoodleNet official packages are written in Typescript.

Install my-moodlenet-mjs-pkg-template

Signup using the web-app .

Note: Do not use sensible passwords as the system saves the email-password credentials unencrypted in the database.

Since no SMTP has been configured, the signup confirmation email supposed to be sent will be logged in the terminal:

hey {display name} confirm your email with /.pkg/@moodlenet/simple-email-auth/confirm-email/{LONG_HASH}

Copy the url path (/.pkg/@moodlenet/simple-email-auth/confirm-email/{LONG_HASH}) apply the localhost and paste it to the browser to confirm your email

localhost:8080/.pkg/@moodlenet/simple-email-auth/confirm-email/{LONG_HASH}

You’ll be logged in automatically and will be able to use the chosen credentials to login other times When logged-in, navigate to the settings page in advanced section, where you can enable "dev mode”.

Then proceed to extensions / install extension section and submit the package absolute path to your package local folder.

The system will install the package and restart.

It will take some time to rebuild the web-app to see the results

Questions? Please take a look in the MoodleNet Community and Tracker for answers or to ask for help.

Creating custom MoodleNet packages

A Moodlenet package is a standard ESM package defining a main ESM module.

@moodlenet/core will import it at startup.

// package.json
{
"name”: "my-moodlenet-package,
"version”: "1",
 "type": "module",
"exports": {
  ".": "./src/server/main.mjs"
}
}
Declare dependency

Your MN package must declare its dependency to the @moodlenet/core and other relevant packages package.json.

The core will import the main module at startup. The package "connects” to the core:

// package.json
{
  "peerDependencies”: {
    "@moodlenet/core: "^0.2.0
 }
}

Mono-Repository management with Lerna.js

MoodleNet project takes leverages lerna.js to manage multi-package mono-repository .

Please refer to Lerna documentation to understand how it manages mono-repo and project-packages dependency linking in the development environment.

When you need to add or remove a dependency for your package to some MoodleNet core package you can issue

lerna add -P <needed pkg> <packages/your-pkg-dir>

e.g. lerna add -P @moodlenet/react-app packages/my-moodlenet-mjs-pkg-template

You may also add/remove peerDependencies manually in package.json, in this case remember to execute:

npm run bs

From the root folder to update links to dependent packages.

Extend the web application

Use @moodlenet/react-app "plugin” api, during initialization to extend the web-app with a custom set of components.

import { pkgConnection } from '@moodlenet/core'
import reactApp from '@moodlenet/react-app'
const reactAppPkg = await pkgConnection(import.meta, reactApp)
await reactAppPkg.api('plugin')({
 mainComponentLoc:
    [path, 'to', 'MainComponent.jsx']
})

Define and deploy APIs

Your package will probably need to define and deploy its own APIs.

APIs are simply a collection of async functions - along with a params formal validation function - organized in a structured Js object.

APIs will be registered in the system with a path-like string, having your package name as prefix and apth following api structure.

// src/server/main.mjs
import { connectPkg, defApi } from '@moodlenet/core'
const myApis = {
  hello:{
     world: defApi( ctx => 
        async (p1,p2) => { return // something } , 
       (...params) => { /* … validate params */ }
  )
}
const connection = await connectPkg(import.meta, { 
  apis: myApis 
})
// will register 1 api: 
// my-moodlenet-package/1.0/hello/world

APIs access

Apis can be accessed by any package running in NodeJs processes using specific @moodlenet/core functions pointing to the path of the desired API.

// from within the backend:
// locate an package api by path
import myMNPkgConn from
   ‘my-moodlenet-package’
const myMNPkg = await pkgConnection(import.meta, myMNPkgConn)
const helloWorldApi =
  myMNPkg.api(‘hello/world’)
// call api as an async function
const result = await
  helloWorldApi(helloParam, worldParam)

APIs Primary Adapters

Primary adapters implement API accessibility from external processes using some transport and protocols. Currently MoodleNet provides one Api-primary-adapter to access APIs by HTTP, which is implemented by @moodlenet/http-server. @moodlenet/http-server API HTTP adapter exposes package APIs as HTTP-POST endpoints. That endpoint is a path comprising the package name and the defined API path base, after the base API endpoint ( currently .pkgs ), having a JSON object body representing the api arguments. For example,

.pkgs/my-moodlenet-package/1.0/hello/world

body:

{

 "args” : [

   "hello-param1”,

   "world-param2”

 ]

}

Furthermore, in the web-app, @moodlenet/react-app provides libraries to use a syntax similar to within-backend-access for easy and strongly typed API calls to the server.

APIs Access Control

Packages register apis to @moodlenet/core which mediates api-call requests and responses, performing all fundamental checks and access controls.

  • checks requested pkg version against deployed pkg version for granting compatibility
  • calls api’s params formal validation function before forwarding to actual api function
  • (TBD) checks matching of scopes associated with api and caller (user or package)
  • provides the api a call-context holding an extensible set of metadata (e.g. user session, caller pkg … )
  • (TBD) any package can register for adding context metadata to an api call

APIs Authorization Scopes (TBD)

The core will export functions to define package-specific auth-scopes - similar to OAuth specs.

defApi() will provide options to apply own or other-pkg’s auth-scopes to api.

All Api accesses will be authorized at core level checking scopes assigned to api against scopes assigned to caller. Note that the caller may be a user using some primary adapter e.g. HTTP or can be simply another package, on its behalf, from within the system.

Packages will have to declare which scopes they will need to be granted in order to perform their functionalities.

Package scope-dependencies should be granted by the admin at installation time in order to complete the installation - similar to what happens on smartphones.

Testing MoodleNet packages

Once we’re happy with package development on dev-environment, we can try to install it on a real MoodleNet installation, using the admin UI.

Installation of MoodleNet in a production-like environment is a one liner cmd:

npx install \ @moodlenet/create \ dest/folder

Ensure ArangoDB is running and once inside the "dest/folder" installation directory:

npx @moodlenet/core

Create a user and navigate to the settings page where you can enable "dev mode”. Then proceed to extensions/install section and submit the package absolute path to local folder.

Questions? Please take a look in the MoodleNet Community and Tracker for answers or to ask for help.

Important links