Our framework is based on four parts: data, views, listeners, and users.
Lenra uses a simple but efficient realtime MVC pattern. This means that any data changes will update the view in real time for every connected users.
The data in Lenra is simply a mongo database. In this database you will store documents that are basically JSON objects. Those JSON objects will be stored in collections. For example, create a
ingredients collection that will store all the ingredients of your cooking app. Then create a
recipes collection to store your recipes…
You can also query into your documents using the mongo query language.
The views are simple functions with optional arguments:
- the data query result
- a property object (props)
- the context of the view
This function will return a JSON tree. If one of the two argument changes, the view is rebuilt.
There is two kind of views in Lenra apps:
- the JSON views that are used by external clients. They let you define any kind of JSON structure as output. The JSON views are recommended for front-end developers.
- the Lenra views that are used by the Lenra client. Their output needs to be a Lenra component. The Lenra views are recommended for back-end developers.
We have integrated the users management in our framework since the apps are made for them. So we handle account management, authentication, authorization, and user data for you.
The users will have a single Lenra account that will be used for all the apps they use, but we a specific ID for each app. This system make it simpler for you to handle user data and give the users the a protection over there personnals data.
To link a data to the current user, just use the
@me string as the user ID in your data and queries, and it will be replaced by the unique user ID of the current user for your app.
The listeners are event based workflows and are the only way to change the data. A listener is a function that is able to call the data API to get/create/update/delete documents. They are called when an action is performed by the user on the UI (button pressed, click, checkbox checked…) or by external events (CRON, WebHooks…).
A listener takes 3 arguments: a property object (props), the event that triggered this listener and an api object that contains all the informations needed to call the API.
To update the model, simply call the HTTP data API in your listener.