Objective
In this post you will learn how to generate code against a sequelize model with Monstarillo. We will generate some documentation on the model in markdown format.
Requirements
To follow along you will need:
- A models.json file describing your sequelize model. You can generate this file following Export Sequelize Model Data For Use With Monstarillo. I will also provide a sample file.
- Monstarillo installed. How To Install Monstarillo
- A text editor. I will be using Visual Studio Code
Create the Template
Create a folder with two text files in it named templates.json and model.tmpl. The templates.json file is use by Monstarillo to know which templates to run and where to put the generated code. The model.tmpl will be the template we run to generate our sequelize model documentation. The follow code will create a directory named model-doc, the two files and open the new directory in Visual Studio Code.
mkdir model-doc
cd model-doc
touch templates.json
touch model.tmpl
code .

Add the following code to the templates.json.
{
"templates": [
{
"templateFile": "{{getTag .Tags \"TemplateRoot\"}}/model.tmpl",
"generatedFileName": "{{ .CurrentModel.ModelName}}.md",
"generatedFolderName": "models",
"minimumGeneratedFileLength": 0,
"outputPath": "{{getTag .Tags \"OutputPath\"}}/",
"overwriteFile": true
}
],
"tags": [
{
"tagName": "TemplateRoot",
"value": "/Users/patrickwright/code/model-doc"
},
{
"tagName": "OutputPath",
"value": "/Users/patrickwright/code/model-doc/output"
}
]
}
The values you set for the two tags will need to be modified for your system. The templates array in the json file is the list of templates that we want Monstarillo to process. The tags array is a list of tags that we can use in our template definitions. In this case we are defining two tags. The first tag “TemplateRoot” should point to the folder containing the templates we want to run. model.tmpl is the template we will be running so the value of “TemplateRoot” should be the location of the folder you created in the previous step. The value of the second tag “OutputPath” should point to the folder you want the files that Monstarillo creates to be created in. In my case I want the generated files to be in a output folder that resides in the folder I created in the previous step.
Make sure you update the values of the two tags, and templateFile to match the folder and files you created.
Template Definition
- templateFile – The location of the template we want Monstarillo to run. In this case “{{getTag .Tags \”TemplateRoot\”}} returns the value we set for the tag TemplateRoot “/Users/patrickwright/code/model-doc”
- generatedFileName – The name of the file that Monstarillo will generate. Monstarillo will execute each template once for each table in your database. {{ .CurrentModel.ModelName}} will return the name of the model being processed.
- generatedFolderName – (optional) the name of the folder you would like to have the output generated in. In this case we are putting the files in a folder called models. This folder will be created in the folder set in the template’s outputPath.
- minimumGeneratedFileLength – (optional) If set Monstarillo will only create a file if the length of the output is greater than this number.
- outputPath – The folder that Monstarillo will create the generated files in. {{getTag .Tags \”OutputPath\”}} returns the value of the tag OutputPath
- overwriteFile – If true Monstarillo will overwrite a generated file if it already exists.
Locate your models.json file
Next find the models.json file you want to use and take note of it’s location. I will copy mine to the root of the model-doc folder to make things easy.
Test the templates.json File by Running Monstarillo
Next we will run Monstarillo against the models.json file. Our model.tmpl is empty so Monstarillo will generate an empty file for each model in our sequelize model.
Execute Monstarillo against the models.json file with the following command :
monstarillo js-orm \
--t /Users/patrickwright/code/model-doc/templates.json \
--m /Users/patrickwright/code/model-doc/models.json
You will need to modify the command to match your system. The –t parameter needs to point to your templates.json file. the –m parameter needs to point to your models.json file.
Your output should be similar to the image below.

You should also see that files have been created for each model in your output folder.

Print Model Names
Next we will modify the template to print out the model name in the markdown file we generate. Add the following to the model.tmpl
# {{.CurrentModel.ModelName}}
.CurrentModel is the model object that Monstarillo uses to generate code. The ModelName property will return the model’s name.
Print Column Information
Next we will add some column information to the generated markdown files we create. Add the following to the model.tmpl
## Columns
|ColumnName|OrmType| DatabaseType| PropertyName|IsPrimaryKey| IsNullable| IsAutoIncrement|
| ---- |---- |---- |---- |---- |---- |---- |{{range .CurrentModel.Columns}}
|{{.GetColumnNameInCase "camel"}}|{{.OrmType}}| {{.DatabaseType}}| {{.PropertyName}}|{{.IsPrimaryKey}}| {{.IsNullable}}| {{.IsAutoIncrement}}| {{end}}
|ColumnName|OrmType| DatabaseType| PropertyName|IsPrimaryKey| IsNullable| IsAutoIncrement|
| ---- |---- |---- |---- |---- |---- |---- |
Adds a header
{{range .CurrentModel.Columns}}
{{end}}
This loops through all of the columns for the model.
|{{.GetColumnNameInCase "camel"}}|{{.OrmType}}| {{.DatabaseType}}| {{.PropertyName}}|{{.IsPrimaryKey}}| {{.IsNullable}}| {{.IsAutoIncrement}}|
The code inside of the loop prints out information about the column being processed in the loop. All of the properties of a Monstarillo column can be found in the documentation at https://monstarillo.com/docs/api/orm-model/
Executing the monstarillo command again now will generate the markdown files again including the column information.

You have created a Monstarillo template that runs against the models.json file that defines the sequelize model you chose. The template created basic documentation for each model. And finally you generated code against the sequelize model you chose.