Skip to main content

Create Module Backend

When it comes to building the backend of your plugin, there is no limitation on what language and framework to use, so feel free to use whatever you feel comfortable with, however there are a set standards to keep in mind while building developing the plugin for MIS. Let's start going through them by building a plugin here. We are going to use Python3/Flask for the demo.

Step 1 ( init project )

In our case, I will do so by running the following commands:

$ mkdir school

I'm creating a plugin for school management and I have already registered my plugin in the web-portal and here is the informations generated for it:

{
"uuid": "6e0108ae-672d-4c6d-959b-2ccf52a3f9f9"
"name": "school",
"title": "School MIS",
"description": "Manage your school in clicks",
"logic_serve": "http://lajward-mis.dev:9001"
}
**Note**: The HTTPS logic_serve by default is always: `http-serve-1000`, so in my case the HTTPS serve would be `https://lajward-mis.dev:8001`

I will go ahead and start a virtualenv for python3.10

$ python3 -m virtualenv env
$ source env/bin/activate

Step 2 ( Install required packages )

Now let's install the required packages to create a simple REST-API app

(env)$ pip3 install flask
(env)$ pip3 install flask-cors

Let's have our requirements.txt generated right now, and we will update if needed.

(env)$ pip3 freeze > requirements.txt

Step 3 ( Write the main application )

It's time for creating our point of entry so I'm going to create the main.py and add the followings to it.

from flask import Flask, jsonify
from flask_cors import CORS

app = Flask(__name__)

CORS(app)

@app.route('/')
def index():
return jsonify({'message': 'Hello School'})

if __name__ == '__main__':
app.run(debug=True, port=9001, host="0.0.0.0")

You may already notice that I'm using the port 9001. Yes, this is not random and it should be the exact port number that is given to you when creating the new plugin in the develoeprs dashboard. In my case it was 9001 and it for sure will differ for you. You will be able to get the port number once you open the management page for this plugin in the developers dashboard.
If I run the application via:

Note: Do not serve the application on the HTTPS port, it is going to be done automatically!

(env)$ python3 main.py

I'm able to see the following results once I hit a request to http://localhost:9001/

{
"message": "Hello School"
}

Connection-To-DB: Whenever you want to interact with the database you may want to use the informations documented in the Create Database Structure page in this dev document.

Step 4 ( Prepare for deployment )

Now that we have our backend application ready we can go ahead and prepare our Dockerfile as it is required by MIS in order to make a successful deployment of the backend-side.
Here I'm going to create the Dockerfile in the root directory and add the followings:

FROM python:3.10-alpine

COPY . /code
WORKDIR /code

RUN pip3 install -r requirements.txt --no-cache-dir

EXPOSE 9001

ENTRYPOINT [ "python" ]

CMD ["main.py"]

The last step before the actual deployment is to create a zip file of the required files, so in my case I would run the following to generate that file

zip school.zip main.py requirements.txt Dockerfile

Step 5 ( Deploy/Publish to MIS marketplace )

Finally let's head our to the developers dashboard ( https://lajward-mis.dev:2002/ ) and click on the school plugin. Here I'm able to see an upload button in the backend-deployment section, this where I should attach my school.zip file and wait for the deployment. After a succesful deployment you should receive a message indicating the sucessful process, If you did get that message you have now succesfully created and deployed the backend side of your module, so head our to the generated (logic_serve - 1000) url ( in my case it's https://lajward-mis.dev:8001/ ) and we should be able to see our API working fine!. This is a deployed version of our module which we can integrate with our frontend-module later on.

Further Topics on backend-side: There is still a lot that MIS standards cover, which we will talk about in the next pages. Topics such as: Authentications, File Uploads and more.

Next: Let's move onto creating our frontend-side of our plugin and integrate it with the backend API.