How create-go-app/cli works
Main components
• CLI Binary (cgapp)
• Command Parser & Root (cmd/root.go)
• “create” command (cmd/create.go)
• “deploy” command (cmd/deploy.go)
• Business-logic packages (pkg/cgapp)
• File generators (files.go)
• Git helper (git.go)
• Shell executor (exec.go)
• Utility functions (utils.go)
• Template Registry (pkg/registry)
• Defaults & configuration (defaults.go, templates)
• Ansible playbook template
• Ansible roles (nginx, traefik, postgres, redis, etc.) with tasks and Jinja2 templates
• External tools
• Git (for repo init)
• npm/vite (for frontend scaffolding)
• Docker (for container images)
• Ansible (for remote deployment)
• Generated project
• Frontend code (React, Vue, etc.)
• Backend code (Go REST API template)
• Ansible inventory & playbook file
• Runtime environment
• Developer’s machine (CLI host)
• Remote server(s) (where Ansible deploys containers)
Relationships and data flow
a. User invokes cgapp create (CLI Binary → Command Parser → Create Command)
b. Create Command calls pkg/cgapp to:
• Initialize Git repo
• Copy/write scaffold files from pkg/registry/templates
• Invoke npm/yarn via exec for frontend
• Write Ansible inventory and playbook files
c. User edits hosts.ini
d. User invokes cgapp deploy (CLI Binary → Deploy Command)
e. Deploy Command triggers pkg/cgapp to:
• Invoke ansible-playbook with generated playbook
• Leverage roles in pkg/registry/roles to launch Docker containers on remote
f. External tools (Docker, Traefik, Nginx, PostgreSQL, Redis) spin up
Architectural patterns & principles
• Modular CLI: commands wired via Cobra-like structure (root + subcommands)
• Separation of concerns:
• cmd/* = interface layer
• pkg/cgapp = orchestration & helpers
• pkg/registry = templates & defaults
• Template-driven codegen: Jinja2/Go templates for config files and playbooks
• External process calls: Git, npm, Ansible, Docker invoked via exec