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
(Started V3 quickstart and config)
m (Added "Copy assets" step to developer instructions)
 
(12 intermediate revisions by 4 users not shown)
Line 3: Line 3:
[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].
[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].


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].
If you are looking to get started as a MoodleNet developer, we have some courses on Moodle Academy. Both are a bit old but will be updated soon.
* [https://moodle.academy/course/view.php?id=13# Introduction to MoodleNet]
* [https://moodle.academy/course/view.php?id=74 MoodleNet for Developers course with Moodle Academy]  
Checkout issues and releases on https://github.com/moodle/moodlenet
 
== Current status ==
== 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].  
We have just released MoodleNet 4.0.0. You can follow the releases on Moodle's Jira tracker at [https://tracker.moodle.org/projects/MDLNET?selectedItem=com.atlassian.jira.jira-projects-plugin%3Arelease-page&status=unreleased MDLNET].  
== Roadmap ==
== 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].
See [https://tracker.moodle.org/secure/RapidBoard.jspa?rapidView=120&projectKey=MDLNET&view=detail our work on new features in the tracker].
== Quick start guide ==
== Quick start guide ==
====System Requirements====
MoodleNet currently runs on
*[https://nodejs.org NodeJS] v20
*[https://nodejs.org/en/knowledge/getting-started/npm/what-is-npm/ npm] v10
MoodleNet supports these [https://github.com/moodle/moodlenet/issues/57 specific versions only], previous version are not supported


==== System Requirements ====
The system also needs a reachable instance of [https://www.arangodb.com/ ArangoDB] v3.10 for data storage
MoodleNet requires the followings to be available on your system
* NodeJs ^16 [https://nodejs.org]
* npm ^8 [https://nodejs.org/en/knowledge/getting-started/npm/what-is-npm/]
* ArangoDB [https://www.arangodb.com/]
Notice that the current nodejs LTSs frameworks are nodejs ^18 and npm ^9


We tested so far with the previous LTSs nodejs ^16 and npm ^8
[Note]: prior to [https://github.com/moodle/moodlenet/releases/tag/untagged-d15332267fd1a286eada version 4.2.1,] MoodleNet supported nodejs@v16 and npm@v8


Make sure to have nodejs ^16 installed and you should get npm ^8 as well
====Deploy an ArangoDB instance====
MoodleNet uses [https://www.arangodb.com/ ArangoDB] as main database


==== Deploy an ArangoDB instance ====
You can choose how and where to deploy your ArangoDB, as long as it can be reached by MoodleNet process
You can choose how and where to deploy your ArangoDB, as long as it can be reached by MoodleNet process


An easy way to install ArangDB locally as a service is by using Docker[https://hub.docker.com/_/arangodb] e.g. :
An easy way to install run ArangDB locally as a service is by using Docker[https://hub.docker.com/_/arangodb] e.g. :
  docker run -d --restart unless-stopped -e ARANGO_NO_AUTH=1 -p 8529:8529 --name=mn-3-db arangodb:3.10
  docker run -d --restart unless-stopped -e ARANGO_NO_AUTH=1 -p 8529:8529 --name=mn-3-db arangodb:3.10
Possibly tweaking some options as you like, e.g. mounting a volume or a directory for data or setting a password
Possibly tweaking some options as you like, e.g. mounting a volume|directory for data or setting a password
 
====Install MoodleNet ====
==== Install MoodleNet ====
Install Moodlenet by simply issuing the following npm command
to install Moodlenet you simply need to issue the following npm command
  npm create @moodlenet@latest path/to/installation/folder
  npm create @moodlenet@latest path/to/installation/folder
this will install all MoodleNet core packages in the choosen folder
That will install all MoodleNet core packages in the chosen folder
 
it will also create a default configuration file ('''default.config.json''') and a default cryptographic key pair for the system ('''default.crypto.privateKey , default.crypto.publicKey''')


==== Start MoodleNet process ====
it will also create a default configuration file ('''default.config.json''') and a default cryptographic key-pair for the system ('''default.crypto.privateKey , default.crypto.publicKey''')
====Start MoodleNet process ====
To start MoodleNet issue the following command from within the installation directory
To start MoodleNet issue the following command from within the installation directory
  npm start
  npm start
open your browser on http://localhost:8080  
open your browser on http://localhost:8080


'''notice:''' on the first run the system will have to compile the webapp, so you'll get a 404 until ready. It should take a few minutes
'''Notice:''' on the first run the system will have to compile the webapp, so you'll get a 404 until ready. It should take a few minutes.
====MoodleNet configuration file====
MoodleNet configuration file ('''default.config.json''') holds all static system configs.


==== MoodleNet configuration file ====
Here's how the default config looks like after install:
MoodleNet configuration file ('''default.config.json''') holds all static system configs.
  {
  {
   "pkgs": {
   "pkgs": {
     "@moodlenet/core": {
     "@moodlenet/core": {
       "baseFsFolder": "/home/alec/MOODLENET/repo/moodlenet3/.dev-machines/1/fs",
       "baseFsFolder": "/path/to/installation/dir/fs",
       "instanceDomain": "<nowiki>http://localhost:8080</nowiki>",
       "instanceDomain": "<nowiki>http://localhost:8080</nowiki>",
       "npmRegistry": "<nowiki>https://registry.npmjs.org</nowiki>",
       "npmRegistry": "<nowiki>https://registry.npmjs.org</nowiki>",
       "mainLogger": {
       "mainLogger": {
         "consoleLevel": "debug",
         "consoleLevel": "info",
         "file": {
         "file": {
           "path": "./log/moodlenet.%DATE%.log",
           "path": "./log/moodlenet.%DATE%.log",
           "level": "debug"
           "level": "info"
         }
         }
       }
       }
Line 62: Line 65:
         "alg": "RS256",
         "alg": "RS256",
         "type": "PKCS8",
         "type": "PKCS8",
         "private": "/home/alec/MOODLENET/repo/moodlenet3/.dev-machines/default.crypto.privateKey",
         "private": "/path/to/installation/dir/default.crypto.privateKey",
         "public": "/home/alec/MOODLENET/repo/moodlenet3/.dev-machines/default.crypto.publicKey"
         "public": "/path/to/installation/dir/default.crypto.publicKey"
       }
       }
     },
     },
Line 87: Line 90:
     },
     },
     "@moodlenet/system-entities": {
     "@moodlenet/system-entities": {
       "rootPassword": "root"
       "rootPassword": "eqhb30x9iq5"
     },
     },
     "@moodlenet/react-app": {
     "@moodlenet/react-app": {
       "noWebappServer": true
       "defaultImageUploadMaxSize": "1MB"
     }
     }
   }
   }
}
Here are some relevant configs you may want to check and tweak:
here's some relevant configs you may want to check and tweak
*'''@moodlenet/arangodb.connectionCfg.url''' : the default config assumes you installed ArangoDB without password with standard port on the same host
*'''@moodlenet/core.baseFsFolder''' : path (better absolute path instead of relative to MoodleNet process cwd) to the system root folder for system filesystem persistency, if you want to change the system-filesystem-root after the system already run, move or clone the existing folder somewhere else and set this config properly to point to the new path
*'''@moodlenet/core.instanceDomain''' : the public domain of your moodlenet instance (e.g. <nowiki>https://moodlenet.example.com</nowiki>) - the default one (<nowiki>http://localhost:8080</nowiki>) is ok for testing and dev
*'''@moodlenet/email-service.nodemailerTransport''' : the [https://nodemailer.com/ nodemailer] [https://nodemailer.com/smtp/ transport configuration] for the system email service. It can be a simple smtp url string, or a [https://nodemailer.com/smtp/ nodemailer standard config object]. '''Notice''': with the default configuration '''{ "jsonTransport": true }''' the system won't send any email, it will simply log them)
*'''@moodlenet/system-entities.rootPassword''' : a static root password for edge cases - you'll use it to give the first admin permission to a user (see below) - this property is optional, if not set the root user is disabled
*'''@moodlenet/http-server.port''' : the HTTP server port to listen
Moodlenet's HTTP service doesn't support HTTPS.


* '''@moodlenet/arangodb.connectionCfg.url''' : the default config assumes you installed ArangoDB without password with standard port on the same host
It's always a good practice to back Moodlenet with a HTTP reverse proxy (e.g. nginx, Apache) and it is a must if you want to publish over HTTPS, configuring TLS on it.
* '''@moodlenet/core.baseFsFolder''' : path to the system root folder for system filesystem persistency (better use absolute paths instead of relative to MoodleNet process cwd)
====Default authentication system====
* '''@moodlenet/core.instanceDomain''' : the public domain for your moodlenet instance (e.g <nowiki>https://myorg.moodle.net</nowiki> )
Moodlenet comes with a simple email+password authentication system (pkg @moodlenet/simple-email-auth) that lets users signup and login with a verified email
* '''@moodlenet/email-service.nodemailerTransport''' : the [https://nodemailer.com/ nodemailer] [https://nodemailer.com/smtp/ transport configuration] for the system email service (notice, with the default configuration the system won't send any email, it will simply log them)


== MoodleNet architecture ==
Users can sign up with their email, receive in their inbox a confirmation link to click and create their user-account
MoodleNet is a full stack TypeScript/JavaScript system using:
====Assign admin privileges to your user====
* NodeJs
As you deploy a new instance, no user is present in the system.
** 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):'''


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:
Signup with your email and create your user.
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.


You’ll find the newly created dev-installation in .dev-machines/my-dev and can create as many dev installations as you wish.
Test login, then logout and browse to the hidden page '''<nowiki>http://localhost:8080/login/root</nowiki>''', here you can type in the '''rootPassword''' (specified in config file) to login as root.


Run development backend:
Open the avatar menu on top right header, and click '''admin''' link
npm run dev-start-backend my-dev
The first run of the system takes some time to install.


Once installed, browse http://localhost:8080
Click on '''Users''' section on the left, and see your user listed there. Activate the '''admin''' icon to give yourself admin privileges


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.
Now you can log out and login back with your email, see you gained the '''admin''' link in your avatar menu
=== 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”.
Admins can directly use that admin page feature anytime to assign and remove admin privileges to other users
== Update the system==
You can easily upgrade MoodleNet keeping system packages always up-to-date with the minor and patch releases by issuing the command
npm update
from within the installation directory, the same where you start the system


It is written in Javascript (EMS) instead of Typescript for a better understanding by newcomers.
Since MoodleNet is npm-package based, it leverages all npm features for upgrades and new packages installation


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.
'''Note:'''
=== 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.
'''npm update''' does not upgrade packages for breaking-change versions (major versions, or minor versions for '''0.x.y''' versions, as from [https://github.com/npm/node-semver#caret-ranges-123-025-004 node-semver specs])


Since no SMTP has been configured, the signup confirmation email supposed to be sent will be logged in the terminal:
In case you need to upgrade MoodleNet system packages to newer major versions you may want to either edit manually the main '''package.json'''
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.
Or, better, use the utility [https://www.npmjs.com/package/npm-check-updates npm-check-updates]:
# for a dry run:
npx npm-check-updates
# to update all packages writing newest version refs in package.json:
npx npm-check-updates -u
npm update
== Migrate from V2==
If you have a v2 running and want to migrate it to v3 , you can use the [https://www.npmjs.com/package/@moodlenet/v2-migrate-v3 @moodlenet/v2-migrate-v3]


The system will install the package and restart.
The v3 system must have access to Moodlenet-V2 persistencies:


It will take some time to rebuild the web-app to see the results
* the running arangoDB instance
* MN2 filesystem folder as configured in [https://gitlab.com/moodlenet/moodlenet/-/tree/1c8c7eb9b9aa2a3ee912871c670480b3e5fa0f70/packages/ce-platform#set-environment-variables V2 env variable '''STATICASSETS_FS_ROOT_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.
V2 persistencies will be used in read-only
== 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.
Note: in case you use the docker setup as proposed above and have it all running at one server, you need to have two Arango DB instances running at the same time. So just forward a different port (here we use localhost:8530 to access the new Arango db instance):
CONTAINER ID  IMAGE          COMMAND                  CREATED        STATUS        PORTS                      NAME
xxxxxx        arangodb      "/entrypoint.sh aran…"  28 hours ago  Up 28 hours  127.0.0.1:8530->8529/tcp    arangodb-new
yyyyyy        arangodb      "/entrypoint.sh aran…"  4 days ago    Up 28 hours  127.0.0.1:8529->8529/tcp    mn-arangodb
Edit the '''default.config.json''' adding a '''@moodlenet/v2-migrate-v3''' section beside the others, it should look like that:
    "@moodlenet/v2-migrate-v3": {
      "v2DbConnectionCfg": {
        "url": "<nowiki>http://your-mn-v2-arangodb-host:8529</nowiki>"
      },
      "v2AssetFolder": "/path/to/v2/asset/folder"
    }
Note that you may also have to adjust the database configuration above for the v3 instance.


When you need to add or remove a dependency for your package to some MoodleNet core package you can issue  
After Moodlenet v3 is installed (as above but choosing the early 3.0 version '''npm create @moodlenet@3.0''' – caution: @3.0.0 wouldn't work!), issue the following command from the installation folder:
  lerna add -P <needed pkg> <packages/your-pkg-dir>
  npm install @moodlenet/v2-migrate-v3@0.5.1
e.g. lerna add -P @moodlenet/react-app packages/my-moodlenet-mjs-pkg-template
Then just (re)start your v3 instance by running "npm start", the migration will be done, services will be restarted and you can log in.


You may also add/remove peerDependencies manually in package.json, in this case remember to execute:
After migration completed this package can be safely uninstalled.
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.
==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 ^16 https://nodejs.org/
*ArangoDB ^3 (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):'''


APIs will be registered in the system with a path-like string, having your package name as prefix and apth following api structure.
Ensure ArangoDB is running on localhost. You may run it in a Docker container issuing a command as below:
  // src/server/main.mjs
docker run -e ARANGO_NO_AUTH=1 -p 8529:8529 --name=mn3-dev arangodb:3.10
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 initialise the project:
npm install
Copy assets
npx lerna run copy-assets
Install a development server:
npm run dev-install-backend my-dev # <- my-dev: an arbitrary dev-installation name
In the example we chose '''my-dev''' as installation name, the tool will then setup a dev installation in '''./.dev-machines/my-dev'''


import { connectPkg, defApi } from '@moodlenet/core'
You can create as many dev installations as you wish.


  const myApis = {
Run development backend:
  npm run dev-start-backend my-dev # <- my-dev : the name you chose when installed
The first run of the system may take some time to install.


   hello:{
The default configuration for dev includes the config '''@moodlenet/react-app.noWebappServer: true''' that prevents the server to expensively build and serve the webapp,


      world: defApi( ctx =>
so you'll get all backend services served on http://localhost:8080, except for the webapp.


         async (p1,p2) => { return // something } ,
Instead, you'll want to run a webpack+HMR serving the webapp issuing
npm run dev-start-webapp my-dev # <- my-dev: the installation server to point to
Once all started, browse http://localhost:3000, any edits to webapp related code will be Hot-Module-Replaced
=== Mono-Repository management with Lerna.js===
MoodleNet project takes leverages [https://lerna.js.org/ lerna.js] to manage multi-package mono-repository .


        (...params) => { /* … validate params */ }
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.
 
   )
 
}
 
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
<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 … )
 
* (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 [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.
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://moodledev.io/general/development/tracker Using Tracker]  
*[https://www.npmjs.com/package/@moodlenet/ce-platform Code repository]
* [https://www.npmjs.com/package/@moodlenet/ce-platform Code repository]
*[https://docs.moodle.org/moodlenet/Main_Page MoodleNet user documentation]
* [https://docs.moodle.org/moodlenet/Main_Page MoodleNet user documentation]
*[https://moodle.org/mod/forum/view.php?id=8726 MoodleNet news and discussion]
* [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://tracker.moodle.org/secure/RapidBoard.jspa?rapidView=167&view=detail MoodleNet Issue Tracker]
*[https://gitlab.com/moodlenet/moodlenet/-/issues MoodleNet Gitlab Issues]
* [https://gitlab.com/moodlenet/moodlenet/-/issues MoodleNet Gitlab Issues]
[[es:MoodleNet]]
[[es:MoodleNet]]

Latest revision as of 07:41, 24 April 2024

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 have some courses on Moodle Academy. Both are a bit old but will be updated soon.

Checkout issues and releases on https://github.com/moodle/moodlenet

Current status

We have just released MoodleNet 4.0.0. You can follow the releases on Moodle's Jira tracker at MDLNET.

Roadmap

See our work on new features in the tracker.

Quick start guide

System Requirements

MoodleNet currently runs on

MoodleNet supports these specific versions only, previous version are not supported

The system also needs a reachable instance of ArangoDB v3.10 for data storage

[Note]: prior to version 4.2.1, MoodleNet supported nodejs@v16 and npm@v8

Deploy an ArangoDB instance

MoodleNet uses ArangoDB as main database

You can choose how and where to deploy your ArangoDB, as long as it can be reached by MoodleNet process

An easy way to install run ArangDB locally as a service is by using Docker[1] e.g. :

docker run -d --restart unless-stopped -e ARANGO_NO_AUTH=1 -p 8529:8529 --name=mn-3-db arangodb:3.10

Possibly tweaking some options as you like, e.g. mounting a volume|directory for data or setting a password

Install MoodleNet

Install Moodlenet by simply issuing the following npm command

npm create @moodlenet@latest path/to/installation/folder

That will install all MoodleNet core packages in the chosen folder

it will also create a default configuration file (default.config.json) and a default cryptographic key-pair for the system (default.crypto.privateKey , default.crypto.publicKey)

Start MoodleNet process

To start MoodleNet issue the following command from within the installation directory

npm start

open your browser on http://localhost:8080

Notice: on the first run the system will have to compile the webapp, so you'll get a 404 until ready. It should take a few minutes.

MoodleNet configuration file

MoodleNet configuration file (default.config.json) holds all static system configs.

Here's how the default config looks like after install:

{
  "pkgs": {
    "@moodlenet/core": {
      "baseFsFolder": "/path/to/installation/dir/fs",
      "instanceDomain": "http://localhost:8080",
      "npmRegistry": "https://registry.npmjs.org",
      "mainLogger": {
        "consoleLevel": "info",
        "file": {
          "path": "./log/moodlenet.%DATE%.log",
          "level": "info"
        }
      }
    },
    "@moodlenet/crypto": {
      "keys": {
        "alg": "RS256",
        "type": "PKCS8",
        "private": "/path/to/installation/dir/default.crypto.privateKey",
        "public": "/path/to/installation/dir/default.crypto.publicKey"
      }
    },
    "@moodlenet/arangodb": {
      "connectionCfg": {
        "url": "http://localhost:8529"
      }
    },
    "@moodlenet/http-server": {
      "port": 8080,
      "defaultRpcUploadMaxSize": "5MB"
    },
    "@moodlenet/ed-resource": {
      "resourceUploadMaxSize": "1.2GB"
    },
    "@moodlenet/simple-email-auth": {
      "newUserNotPublisher": false
    },
    "@moodlenet/email-service": {
      "nodemailerTransport": {
        "jsonTransport": true
      }
    },
    "@moodlenet/system-entities": {
      "rootPassword": "eqhb30x9iq5"
    },
    "@moodlenet/react-app": {
      "defaultImageUploadMaxSize": "1MB"
    }
  }

Here are some relevant configs you may want to check and tweak:

  • @moodlenet/arangodb.connectionCfg.url : the default config assumes you installed ArangoDB without password with standard port on the same host
  • @moodlenet/core.baseFsFolder : path (better absolute path instead of relative to MoodleNet process cwd) to the system root folder for system filesystem persistency, if you want to change the system-filesystem-root after the system already run, move or clone the existing folder somewhere else and set this config properly to point to the new path
  • @moodlenet/core.instanceDomain : the public domain of your moodlenet instance (e.g. https://moodlenet.example.com) - the default one (http://localhost:8080) is ok for testing and dev
  • @moodlenet/email-service.nodemailerTransport : the nodemailer transport configuration for the system email service. It can be a simple smtp url string, or a nodemailer standard config object. Notice: with the default configuration { "jsonTransport": true } the system won't send any email, it will simply log them)
  • @moodlenet/system-entities.rootPassword : a static root password for edge cases - you'll use it to give the first admin permission to a user (see below) - this property is optional, if not set the root user is disabled
  • @moodlenet/http-server.port : the HTTP server port to listen

Moodlenet's HTTP service doesn't support HTTPS.

It's always a good practice to back Moodlenet with a HTTP reverse proxy (e.g. nginx, Apache) and it is a must if you want to publish over HTTPS, configuring TLS on it.

Default authentication system

Moodlenet comes with a simple email+password authentication system (pkg @moodlenet/simple-email-auth) that lets users signup and login with a verified email

Users can sign up with their email, receive in their inbox a confirmation link to click and create their user-account

Assign admin privileges to your user

As you deploy a new instance, no user is present in the system.

Signup with your email and create your user.

Test login, then logout and browse to the hidden page http://localhost:8080/login/root, here you can type in the rootPassword (specified in config file) to login as root.

Open the avatar menu on top right header, and click admin link

Click on Users section on the left, and see your user listed there. Activate the admin icon to give yourself admin privileges

Now you can log out and login back with your email, see you gained the admin link in your avatar menu

Admins can directly use that admin page feature anytime to assign and remove admin privileges to other users

Update the system

You can easily upgrade MoodleNet keeping system packages always up-to-date with the minor and patch releases by issuing the command

npm update

from within the installation directory, the same where you start the system

Since MoodleNet is npm-package based, it leverages all npm features for upgrades and new packages installation

Note:

npm update does not upgrade packages for breaking-change versions (major versions, or minor versions for 0.x.y versions, as from node-semver specs)

In case you need to upgrade MoodleNet system packages to newer major versions you may want to either edit manually the main package.json

Or, better, use the utility npm-check-updates:

# for a dry run:
npx npm-check-updates

# to update all packages writing newest version refs in package.json:
npx npm-check-updates -u
npm update

Migrate from V2

If you have a v2 running and want to migrate it to v3 , you can use the @moodlenet/v2-migrate-v3

The v3 system must have access to Moodlenet-V2 persistencies:

V2 persistencies will be used in read-only

Note: in case you use the docker setup as proposed above and have it all running at one server, you need to have two Arango DB instances running at the same time. So just forward a different port (here we use localhost:8530 to access the new Arango db instance):

CONTAINER ID   IMAGE          COMMAND                  CREATED        STATUS        PORTS                       NAME
xxxxxx         arangodb       "/entrypoint.sh aran…"   28 hours ago   Up 28 hours   127.0.0.1:8530->8529/tcp    arangodb-new
yyyyyy         arangodb       "/entrypoint.sh aran…"   4 days ago     Up 28 hours   127.0.0.1:8529->8529/tcp    mn-arangodb

Edit the default.config.json adding a @moodlenet/v2-migrate-v3 section beside the others, it should look like that:

    "@moodlenet/v2-migrate-v3": {
      "v2DbConnectionCfg": {
        "url": "http://your-mn-v2-arangodb-host:8529"
      },
      "v2AssetFolder": "/path/to/v2/asset/folder"
    }

Note that you may also have to adjust the database configuration above for the v3 instance.

After Moodlenet v3 is installed (as above but choosing the early 3.0 version npm create @moodlenet@3.0 – caution: @3.0.0 wouldn't work!), issue the following command from the installation folder:

npm install @moodlenet/v2-migrate-v3@0.5.1

Then just (re)start your v3 instance by running "npm start", the migration will be done, services will be restarted and you can log in.

After migration completed this package can be safely uninstalled.

MoodleNet architecture

MoodleNet is a full stack TypeScript/JavaScript system using:

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

MoodleNet development environment

Setup development environment

From the command line interface (CLI):

Ensure ArangoDB is running on localhost. You may run it in a Docker container issuing a command as below:

docker run -e ARANGO_NO_AUTH=1 -p 8529:8529 --name=mn3-dev arangodb:3.10

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 initialise the project:

npm install

Copy assets

npx lerna run copy-assets

Install a development server:

npm run dev-install-backend my-dev # <- my-dev: an arbitrary dev-installation name

In the example we chose my-dev as installation name, the tool will then setup a dev installation in ./.dev-machines/my-dev

You can create as many dev installations as you wish.

Run development backend:

npm run dev-start-backend my-dev # <- my-dev : the name you chose when installed

The first run of the system may take some time to install.

The default configuration for dev includes the config @moodlenet/react-app.noWebappServer: true that prevents the server to expensively build and serve the webapp,

so you'll get all backend services served on http://localhost:8080, except for the webapp.

Instead, you'll want to run a webpack+HMR serving the webapp issuing

npm run dev-start-webapp my-dev # <- my-dev: the installation server to point to

Once all started, browse http://localhost:3000, any edits to webapp related code will be Hot-Module-Replaced

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.

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