How to generate a typical micro service using app-gen
Edit me

Introduction

It is trivial to generate a micro service using gen.sh that is shipped within app-gen. However, you do need a shell environment such as bash or powershell .

Dependencies

You need the following in your machine to execute gen.sh

  1. Node must be installed in your machine. gen.sh uses mustache (which it downloads automatically)
  2. UNIX/LINUX make is required to make the executable first time.
  3. mvn for the build

In this page, we will see how exactly this is done.

Steps

First download and set up app-gen

Comments are given below each instruction preceded by #

$ mkdir code; cd code # wherever you want to create these folders
$ # Hence forth all references will be with respect to this folder
$ git clone https://github.com/rajakolluru/chenile-gen.git
$ cd app-gen
$ make 
$ # this will compile all the programs to app-gen/bin. It also downloads mustache
$ export PATH=$PATH:<path-to-app-gen>/bin
$ # puts app gen in the path

Services in Chenile are plain POJO code. They implement a service interface. The service interface is visible to all the consumers of the service. The service code itself is not made accessible. This is in compliance with the DIP (Dependency Inversion Principle) which states that higher modules must not depend on lower modules. Instead, they must depend on the interface that is exposed by the lower modules.

For example, for service s1 the interface is defined in a module called s1-api. The service implementation is defined in a module s1-service. If a serice s2 needs to consume s1, it needs to depend on s1-api (and not s1-service)

Service modules are not designed to be deployed. They are packaged as libraries.

Prepare gen.sh

gen.sh must always be executed from the same folder (typically $HOME).

$ cd 
$ # this will take you to your home folder
$ gen.sh
$ # this gives you a bunch of options. Choose option to "create a local config".

The above creates a folder called config under the $HOME folder. This folder contains a file setenv.sh thst needs to be edited to make sure that the code generated uses the correct value for company and org. company is the name of your company and org is the org (or product) within the company. Now you are all set to generate the service.

Generate the Service

$ cd 
$ # this will take you to your home folder
$ gen.sh
$ # this gives you a bunch of options. Choose option to "create a normal service and monolith".
$ # When prompted input "stringdemo" for the service name. You can go with the defaults for service version and output folder
$ # which is typically ./output. We will call it $code_dir in this document.
$ # When prompted for monolith name use "stringdemodeploy".
$ # gen.sh does the rest!

What Got Generated?

gen.sh creates two folders - stringdemo and stringdemodeploy. Both these folders contain other folders that will be described below.

What do you do next?

$ cd $code_dir/stringdemo
$ make build
$ # makes the service 
$ cd $code_dir/stringdemodeploy
$ make build
$ # makes the deployable.

This executes mvn to generate the entire structure.