hodur/visualizer-schema

Hodur is a domain modeling approach and collection of libraries to Clojure. By using Hodur you can define your domain model as data, parse and validate it, and then either consume your model via an API or use one of the many plugins to help you achieve mechanical results faster and in a purely functional manner.


Keywords
clojure, data, modeling, schema, visualization
License
MIT

Documentation

Hodur Visualizer Schema

https://img.shields.io/clojars/v/hodur/engine.svg https://img.shields.io/clojars/v/hodur/visualizer-schema.svg https://img.shields.io/badge/License-MIT-blue.svg https://img.shields.io/badge/project%20status-experimental-brightgreen.svg

./docs/logo-tag-line.png

Hodur is a descriptive domain modeling approach and related collection of libraries for Clojure.

By using Hodur you can define your domain model as data, parse and validate it, and then either consume your model via an API making your apps respond to the defined model or use one of the many plugins to help you achieve mechanical, repetitive results faster and in a purely functional manner.

This Hodur plugin provides the ability to visualize your Hodur model on a dynamically, hot-reloaded web page.

Motivation

For a deeper insight into the motivations behind Hodur, check the motivation doc.

Getting Started

Hodur has a highly modular architecture. Hodur Engine is always required as it provides the meta-database functions and APIs consumed by plugins.

Therefore, refer the Hodur Engine’s Getting Started first and then return here for Lacinia-specific setup.

After having set up hodur-engine as described above, we also need to add hodur/visualizer-schema, a plugin that creates and shows Hodur models on a web browser to the deps.edn file:

{:deps {hodur/engine            {:mvn/version "0.1.2"}
        hodur/visualizer-schema {:mvn/version "0.1.1"}}}

While you are at your deps.edn file also make sure you have both ~”src”~ and ~”resources”~ to your :paths:

{:paths ["src" "resources"]}

Visualizer utilizes a JavaScript library called GoJS for the rendering and interactive bits. This library is unfortunately under a proprietary license so it can’t be embedded in an Open Source project directly. You have to download a personal evaluation copy and to your project:

$ mkdir -p resources/public/scripts
$ curl https://gojs.net/latest/release/go.js -o resources/public/scripts/go.js

It is also recommended that you list resources/public/scripts/go.js out of your SCM (i.e. GitHub) to avoid legal issues.

If you have suggestions of more Open Source-friendly libraries with equivalent features please DM me at @tiagoluchini

Create a cljs main file that will bootstrap your visualizer app. For instance, if you want to call it hello.core, add the file core.cljs to src/hello:

(ns hello.core
  (:require [hodur-engine.core :as engine]
            [hodur-visualizer-schema.core :as visualizer]))

(def meta-db (engine/init-schema
              '[Person
                [^String first-name
                 ^String last-name
                 ^Gender gender]

                ^:enum
                Gender
                [MALE FEMALE IRRELEVANT]]))

(-> meta-db
    visualizer/schema
    visualizer/apply-diagram!)

We are creating a simple Hodur model with an Entity called Person and an enum called Gender and putting it in a meta database on meta-db.

Before explaining the last function calls on this document, let’s fire up a figwheel environment with the following helper main (where hello.core is the name of the main cljs namespace you created above:

$ clojure -m hodur-visualizer-schema.main hello.core

Figwheel will bootstrap a browser-connected repl and launch a browser pointing to localhost:9500 after while. You should see something like this:

./docs/diagram.png

Feel free to interact with the diagram. You can drag entities around, collapse them and there’s a handy tooltip when you hover over entities and fields.

Hot-reload is also enabled, if you change your model on hello.core you should see the changes reflected on your browser immediately.

As for the last two functions of the hello.core we are using the meta-database on meta-db to get a visualizer-parsed version of the schema (through the function visualizer/schema) and, at last, we call visualizer’s side-effect function visualizer/apply-diagram! that updates the diagram on your browser.

Model Definition

All Hodur plugins follow the Model Definition as described on Hodur Engine’s documentation.

Bugs

If you find a bug, submit a GitHub issue.

Help!

This project is looking for team members who can help this project succeed! If you are interested in becoming a team member please open an issue.

License

Copyright © 2018 Tiago Luchini

Distributed under the MIT License (see LICENSE).