This is a template repository for building Invopop applications using Go. It provides a clean, modular architecture with web and gateway interfaces, making it easy to create new services that integrate with the Invopop ecosystem.
The template follows a clean architecture pattern with clear separation of concerns:
app/
βββ cmd/ # Application entry points
βββ config/ # Configuration files
βββ internal/ # Private application code
β βββ config/ # Configuration management
β βββ domain/ # Business logic layer
β β βββ models/ # Domain models
β βββ interfaces/ # External interfaces
β βββ gateway/ # NATS gateway for async tasks
β βββ web/ # HTTP web interface
β βββ assets/ # Static assets (embedded)
β βββ components/ # Templ components
βββ pkg/ # Public packages and utilities
- Main Application (
main.go
): Entry point with CLI commands using Cobra - Web Interface: HTTP server built with Echo framework and Templ templates
- Gateway Interface: NATS-based async task processing
- Domain Layer: Business logic and models
- Configuration: YAML-based config with environment variable support
Before using this template, ensure you have the following dependencies installed:
-
Go 1.24.4+
# Check your Go version go version
-
Mage - Build automation tool
go install github.com/magefile/mage@latest
-
Templ - Type-safe Go templating
go install github.com/a-h/templ/cmd/templ@latest
-
Air - Live reload for Go apps (development)
go install github.com/air-verse/air@latest
- Echo v4: HTTP web framework
- Cobra: CLI commands and flags
- Templ: Type-safe Go templating
- Zerolog: Structured logging
- Invopop Client: Integration with Invopop services
- Docker - For containerized development and deployment
- NATS Server - For gateway functionality (can run via Docker)
# Clone the template
git clone https://github.com/invopop/popapp.git my-new-app
cd my-new-app
# Update the module name in go.mod
go mod edit -module github.com/yourorg/my-new-app
# Download dependencies
go get -u
go mod tidy
Remember to replace popapp
with your app name all through the codebase, including in config.yaml
, mage.go
, and Dockerfile
.
Key configuration options:
invopop.client_id
andinvopop.client_secret
: Your Invopop app credentialsnats.url
: NATS server connection stringpublic_base_url
: Your application's public URL
# Start with hot reload
air
This will:
- Watch for file changes
- Automatically rebuild the application
- Restart the server
- Generate Templ templates
# Build the application
mage build
# Start the service
mage serve
# Open a shell in the Docker container
mage shell
# Generate Templ templates
templ generate
# Build and run
go build . && ./popapp serve
The template is organized to make common development tasks straightforward:
Edit internal/interfaces/web/web.go
:
func New(domain *domain.Setup) *Service {
s := new(Service)
s.echo = echopop.NewService()
s.echo.Serve(func(e *echo.Echo) {
e.StaticFS(popui.AssetPath, popui.Assets)
e.StaticFS("/", assets.Content)
// Add your controllers here
s.register = newRegisterController(e.Group("/register"), s)
})
return s
}
Edit internal/interfaces/gateway/gateway.go
:
func (s *Service) executeAction(ctx context.Context, in *gateway.Task) *gateway.TaskResult {
switch in.Action {
case "my_new_action":
return s.handleMyNewAction(ctx, in)
default:
return gateway.TaskKO(errors.New("unknown action"))
}
}
Create new files in internal/domain/
:
// internal/domain/my_service.go
type MyService struct {
// dependencies
}
func (s *MyService) DoSomething(ctx context.Context, req *MyRequest) (*MyResponse, error) {
// Business logic here
}
Create .templ
files in internal/interfaces/web/components/
:
// components/my_component.templ
package components
templ MyComponent(title string) {
<div class="my-component">
<h1>{ title }</h1>
</div>
}
The template includes Docker support for consistent development environments:
# Build and run with Docker
mage serve
# This runs the equivalent of:
docker run --rm --name popapp \
--network invopop-local \
-v $PWD:/src -w /src \
--label traefik.enable=true \
--label traefik.http.routers.popapp.rule=Host\`popapp.invopop.dev\` \
--label traefik.http.routers.popapp.tls=true \
--expose 8080 \
golang:1.24.4-alpine \
/src/popapp serve
s## βοΈ GitHub Workflows
This template includes three GitHub Actions workflows to automate testing, linting, and deployment:
Triggers: Push to main, tags (v*), and pull requests
What it does:
- Sets up Go environment using the version from
go.mod
- Configures authentication for private Invopop dependencies
- Downloads all Go modules
- Runs unit tests with race detection:
go test -tags unit -race ./...
- Builds the application to verify compilation
Required Secrets:
GO_MOD_USER
: GitHub username for accessing private repositoriesGO_MOD_PASS
: GitHub token/password for private repository access
Triggers: Push to main, tags (v*), and pull requests
What it does:
- Sets up Go environment
- Configures authentication for private dependencies
- Runs
golangci-lint
to check code quality and style - Ensures code follows Go best practices
This template is provided under the same license as your Invopop application.