Pheix CMS
German Perl & Raku Workshop, 24th March 2021
About Pheix CMS

Pheix – Artistic 2.0 license compliant, Rakulang driven content management system with data storing on Ethereum blockchain. It is extremely lightweight, fast & scalable.

Modern Pheix is the CMS for Web3.0 oriented projects. The system basics are: decentralized modules, security and storing the content in different target storages: regular databases, private and public ethereum networks.

Pheix public β-release suggestions

As the private β-release has shown, Pheix had the generic render time problem. We were wasting ~5 seconds while rendering content on server-side with Template::Mustache. Suggested improvements:

  1. FastCGI;
  2. Careful object management;
  3. Client-side content rendering;
  4. Public ethereum test networks integration.

👉   https://narkhov.pro/pheix-public-beta-release-suggestions.html

Pheix public β-release breaking changes

And finally public β-release has the next major breaking changes:

  1. Headless architecture;
  2. Templating engine improvements;
  3. Code refactoring: efficient objects management;
  4. Integration with public Görli Testnet;
  5. Scalability with external modules.

TL;DR Pheix CMS public β-release related issues

Looking back
Private β-release 20 Jun, 2020
Public β-release
19 February 2021
Late α-release 06 Apr, 2020
One step to β-release

Traditionally the beta version is published once all scheduled major features have been implemented and released. As with any program beta release, now you have got the access to new features, so you are likely to try Pheix as less stable, but closer to final version. The major Pheix beta release improvements are related to content rendering performance, blockchain support and overall design.

As with any program beta release, now you have early access to new features and able to test them and give your feedback. It's very valuable for the future development.

Private β-release major issues

Pheix private β-release has supported private ethereum PoA networks, ~100% coverage tests and representation layer basic implementation. The network setup and instructions were published and you could run your own test net or get access to our private network for testings.

But:

  1. It was slow: average content render time was ~5 seconds;
  2. It was incompatible with public ethereum networks;
  3. It was unscalable — no any flexible tools to add new features;
  4. It has legacy CMS design.
Make it headless

👉   The general benefit of headless architecture: you can make your access much more secure with presentation and administration layers on different ethereum nodes.

Templating engine improvements

A templating engine basically provides tools for effective metadata interpolation inside static files (templates). At web application runtime, the engine parses and replaces variables with actual content values.

I have done the humble research, where Template::Mustache, Template6 and HTML::Template were compared. Also there were a few tricky techniques with grammars, regular expressions and XML trees.

👉   Raku web templating engines: boost up the parsing performance

The results

Before:

Render time: 1.85553481 sec.

So, if the web application works as the classic CGI instance (no caching, no available workers, no proxies — every run is from the scratch), the request will be rendered at least in 2 seconds (network latency + duty cycle + templating [+ server resource throttling]). Actually this time may be more than 10 seconds (a few parallel clients case) — absolutely bad.

After:

Render time: 0.00972673 sec.
CGI → FastCGI

Private β-release used legacy CGI approach. It means: on every request we start Pheix instance proccess, create and initialize all objects, prepeare everything for the usual run (read configs, try blockchain nodes, fetch templates).

Migration to FastCGI requires much more strict objects and data management:

  1. All static objects should created on the first run;
  2. All config data, templates, etc... should be retrieved on the first run;
  3. Objects should be reusable;
  4. Data and objects should be accessible submodules and addons.
Request summary timings

First run:

Every next run (approximately):

Rendering content in browser

Introduce Riot JavaScript components library for rendering content with JS in browser, it's based on REST API and in future will lead Pheix to true headless CMS.

Embedded API debugger is available at https://pheix.org/api-debug.

You can try the sample request:

{
  "token": "94a08da1fecbb6e8b46990538c7b50b2",
  "method": "GET",
  "route": "/",
  "httpstat": "200",
  "message": ""
}
Backend response

Response for the sample request:

{
  "msg": "/ fetch is successful",
  "render": "0.0123497",
  "status": 1,
  "content": {
    "component_render": "0.0120643",
    "component": "SGVsbG8sIHdvcmxkISBJJ20gd29ya2luZyA7LSk=",
    "tparams": {
      "tmpl_paragraph": "Hello, world! I'm working ;-)",
      "tmpl_pageheader": "Welcome to Pheix!",
      "tmpl_decaptcha": "6211230981",
      "tmpl_modcode": "",
      "tmpl_update_full": "24 March, 2021",
      "tmpl_debug": "",
      "tmpl_rakudo_ver": "Rakudo compiler v2020.05.1, Raku 6.d",
      "tmpl_extrametas": "",
      "tmpl_env_vars": [],
      "tmpl_modname": "Pheix::View::Pages"
    }
  }
}
Riot JS library example

Try it: https://plnkr.co/edit/bh3mGY1oXbm9h6VU

As you see from request, backend sends content template as component in base64 and variables to be rendered as tparams collection.

More details about Riot JavaScript components library: https://riot.js.org/

Görli Testnet support

Görli Testnet is the first proof-of-authority cross-client testnet, synching Parity Ethereum, Geth, Nethermind, Hyperledger Besu, and EthereumJS. We use Infura.io node as gateway for Görli Testnet — the Infura API suite provides instant access over HTTPS and WebSockets to the Ethereum networks.

Pheix config for Görli Testnet:

{
  "type": "1",
  "path": "conf/system/abi",
  "strg": "PheixDatabase",
  "extn": "abi",
  "prtl": "https://",
  "host": "goerli.infura.io",
  "port": "443/v3/<infura-api-token>",
  "hash": "0xd47613544f54dd26afe3edcae19e87c788b3ac321df0562244645d21af76b399",
  "user": "",
  "pass": "",
  "data": "undefined"
},
Inspect transactions with Etherscan service

List of related transactions is available via https://goerli.etherscan.io/

Pinned blog record at PHEIX.org
Pinned blog record transaction details
Addons

Pheix addons/modules are installing as regular Raku modules and need to be set up in Pheix global configuration file as the dependencies.

Pheix is based on concept of hybrid CMS. On one hand, it works as a legacy CMS while global templates rendering, on other — content for each page is fetching via async API requests and this is the case of headless CMS.

Sample addon module: Pheix::Addons::Embedded::User

Addon configuration

Let's consider the DAS module configuration. Routes are specified as:

  1. Route for file upload form, e.g. /das/upload;
  2. Route for uploaded files index, e.g. /das;
  3. Route for file details, e.g. /das/{fileid:<\d>+}.

Pheix uses Router::Right module as routing engine.

Router::Right is well-documented, you can find docs, examples, best-practices and demo routes on wiki pages.

Add the routes
{
  "routes":{
    "das":{
      "route":{
        "path":"/das",
        "hdlr":{ "default":"das_index", "/api":"das_index_api" }
      }
    },
    "upload":{
      "route":{
        "path":"/das/upload",
        "hdlr":{ "default":"das_upload", "/api":"das_upload_api" }
      }
    },
  "browsefile":{
      "route":{
        "path":"/das/{fileid:<\d>+}",
        "hdlr":{ "default":"das_browsefile", "/api":"das_browsefile_api" }
      }
    }
  }
}
Addon API structure

Eventually to integrate any features to Pheix you should implement them, cover them with the route related API calls and wrap into the new class.

Your class also should have a few specific methods required by Pheix:

method init_json_config returns Pheix::Model::JSОN;
method get(:$ctrl!) returns Pheix::Addons::Embedded::User;
method get_class returns Str;
method get_name returns Str;
method get_sm returns List;
method fill_seodata(:%matchctrl!) returns Hash;
Night skin

Pheix embedded skin now has night mode. Yep, geeks like to dig web sites after midnight 😄.

Ok, β-release is happened, what's next?

Release Candidate 1 😇

There will be next general breaking changes:

  1. Migration from LZW::Revolnet to Compress::Bzip2;
  2. Split up a distro to Pheix module and Pheix deployment stuff;
  3. Naive implementation of administration layer.

👉   RC1 related issues list

Update compression stuff

I have done the compression efficiency investigation and finally compared LZW::Revolnet and Compress::Bzip2: the last one provides 3x better compression rate. Great boost up for the blockchain performance.

This step requires:

  1. Update smart contract: migrate from strings to bytes;
  2. Create sample datasets;
  3. Update unit tests: wrap transactions with functions, do transform there;
  4. Add handy tools for data inspection, JS module with CRUD funcs;
  5. Add Raku script for Bzip2 compressed data inspection.

👉   Migration workflow

Update distributive

The next important update is related to Pheix distributive.

Now Pheix includes everything you needed for deployment: generic module, start up script, web resources, configuration files, etc… I'm planning to split up a distro to Pheix raku module as the generic entity and Pheix deployment stuff as the dependency or addon.

Administration layer

Pheix RC1 UI will be extended with naive implementation of administration layer. Actually the big deal is to add this layer as Ethereum node interface, in this case we will got such node features as authorization and access level model out of the box.

On other hand, this idea is required available private Ethereum node or full implementation of transaction signing at Net::Ethereum.

So, this is still the point of discussion 🧐

Pheix in production

DAS (Digital Audio Server) backend is driven by Pheix, the details were discussed at Perl development room at FOSDEM2021. There are a few interesting tricks and hacks related to digital signal processing, native calls from Raku applications and Pheix integrations.

In general audio backend handles requests from clients, routes them to audio engine and performs the responses. DAS relies on JUCE, Raku and Pheix.

ETHELIA Early alfa draft of Ethelia service specification

Open call and donate

I would like to invite you to Pheix development process — code review, forks and merge requests are very welcome:

https://pheix.org

https://gitlab.com/pheix/dcms-raku

https://gitlab.com/pheix/net-ethereum-perl6/

https://gitlab.com/pheix/router-right-perl6/

If you like any ideas or concepts presented in this talk — let's get in touch and discuss or just donate at: https://pheix.org/#donate

The End