Skip to content

How the CLI works

Vic Shóstak edited this page Jun 28, 2023 · 27 revisions

Probably you think that Create Go App CLI is a "black box" that magically creates objects out of thin air. But that's not really true. The whole project is built on UNIX principles that each element must have a clear function that it does well.

So, basically the CLI contains three main parts, which we will describe in more detail below:

  • Pre-configured backend part
  • Frontend part generated by Vite.js
  • Deploy-ready Ansible roles

The backend part

The backend part is full-fledged prepared templates with popular Go web frameworks, which were created by the authors of Create Go App and placed in the project organization on GitHub.

In the background, the usual git clone <URL> will happen, but followed by a cleanup of unnecessary folders so that you can start implementing your logic right away. You get right out of the box: CRUD methods with implementation examples, JWT authorization and token update, database configuration, auto-generated documentation for REST API from Swagger, clear, and simple project structure.

Make sure that you have Golang version 1.17.x or higher installed on your computer.

You can choose between:

Name Version Link to Go template
Fiber latest create-go-app/fiber-go-template
net/http latest create-go-app/net_http-go-template

The frontend part

The frontend part will be generated using wonderful tool Vite.js under the hood.

Note that the CLI does not do any transformations with this part of your project. That is, you have to write the frontend yourself from scratch, Create Go App only helps in organizing the structure and simplifies project generation.

This will use the usual Node.js command npm init vite@latest <FOLDER> -- --template <TEMPLATE>.

Make sure that you have Node.js version 12.x or higher and npm 7.x or higher installed on your computer.

You can choose between:

Name Version Link to JavaScript template Link to TypeScript template
Pure (vanilla) - vanilla vanilla-ts
React latest react react-ts
Preact latest preact preact-ts
Vue.js latest vue vue-ts
Svelte latest svelte svelte-ts
Lit latest lit lit-ts

And the latest Next.js and Nuxt 3 frontend parts will be generated using the create-next-app and nuxi utilities.

Deploy-ready Ansible roles

The most interesting part, which contains several atomic Ansible roles, inventory, and playbook for successful deployment of your project to a remote server. All the necessary role files are stored in the binary itself and are copied instantly, which is why the CLI is so fast! Roles were created by the authors of Create Go App and verified by numerous test and production runs on real servers.

The CLI currently includes roles for:

  • Initial configuration of the remote server;
  • Docker settings to create containers;
  • Proxy server settings (Traefik Proxy, Nginx);
  • Settings for creating a container with the backend part;

Make sure you have Ansible version 2.9 or higher and Python 3.8 or higher installed to work successfully.

After filling out the inventory in the hosts.ini file and running the cgapp deploy command from the project root folder, the roles are analyzed and Ansible is called to do the rest of the work. Be patient because this process can take anywhere from 30 seconds, depending on the performance of your remote server.

Clone this wiki locally