Skip to content
/ hatch Public

A CLI tool that scaffolds production-ready event-driven services with a beautiful terminal UI.

License

Notifications You must be signed in to change notification settings

DrBlury/hatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hatch

CI codecov Go Version License Go Report Card

A beautiful, interactive CLI tool for Protoflow - built with Charm components for an exceptional developer experience.

Hatch scaffolds production-ready event-driven services with:

  • πŸ—οΈ Complete project structure - App orchestration, use cases, events, database support
  • πŸ“Š OpenTelemetry integration - Tracing, metrics, and structured logging out of the box
  • πŸ”§ Viper configuration - Environment-driven config with sensible defaults
  • 🎯 Best practices - Pre-commit hooks, Taskfile automation, comprehensive documentation
  • πŸš€ Multiple transports - Kafka, RabbitMQ, NATS, AWS, HTTP, and more

Features

  • 🎨 Beautiful UI: Built with Charm's Bubble Tea and Lip Gloss for a delightful terminal experience
  • πŸš€ Project Scaffolding: hatch init - Generate new Protoflow projects instantly
  • πŸ“ Handler Generation: hatch handler add - Create type-safe handlers with boilerplate
  • βœ… Configuration Validation: hatch validate - Validate configs before runtime
  • 🎯 Interactive Prompts: Charm's survey components for guided workflows

Installation

From Source

git clone https://github.com/drblury/hatch.git
cd hatch
go install ./cmd/hatch

Via Go Install

go install github.com/drblury/hatch/cmd/hatch@latest

Via Homebrew (Coming Soon)

brew install hatch

Quick Start

Initialize a New Project

hatch init my-service

This will create a production-ready project with:

  • Application Structure: main.go with build metadata, internal/app for lifecycle management
  • Business Logic: internal/usecase package for clean architecture
  • Event Handling: internal/events with middleware, validation, and retries
  • Database Support: internal/database with MongoDB integration and health checks
  • Observability: pkg/logging with OTEL tracing, metrics, and structured logging
  • Configuration: Viper-based config with .env.example template
  • Development Tools: Pre-commit hooks, Taskfile, comprehensive documentation

Add a Handler

hatch handler add OrderCreated --type proto --consume orders.created

Validate Configuration

hatch validate .env

Commands

hatch init [name]

Scaffold a new Protoflow service project.

Options:

  • --transport <name> - Select transport (kafka, rabbitmq, nats, aws, http, io, sqlite, postgres, channel)
  • --with-examples - Include example handlers
  • --with-simulator - Include event simulator
  • --interactive - Use interactive mode (default when no args provided)

Example:

hatch init my-service --transport kafka

hatch handler add <name>

Generate boilerplate for a new handler.

Releases

Releases are automatically created when a git tag is pushed. The CI pipeline uses GoReleaser to build binaries for multiple platforms and create GitHub releases.

Creating a Release

  1. Update version numbers and changelog
  2. Commit your changes
  3. Create and push a git tag:
    git tag -a v1.0.0 -m "Release v1.0.0"
    git push origin v1.0.0

The GitHub Actions workflow will automatically:

  • Build binaries for Linux, macOS, and Windows (amd64 and arm64)
  • Create a GitHub release with release notes
  • Upload all binaries and checksums
  • Generate Homebrew formula (if configured)

Manual Release

You can also trigger a release manually via GitHub Actions:

  1. Go to Actions β†’ Release workflow
  2. Click "Run workflow"
  3. Enter the tag name (e.g., v1.0.0)
  4. Click "Run workflow"

Options:

  • --type <proto|json|cloudevents> - Handler type (default: proto)
  • --consume <queue> - Consume queue/topic (required)
  • --publish <queue> - Publish queue/topic (optional)
  • --interactive - Use interactive mode (default)

Example:

hatch handler add ProcessPayment \
  --type json \
  --consume payments.process \
  --publish payments.completed

hatch validate [config-file]

Validate Protoflow configuration without running the service.

Options:

  • --config <file> - Configuration file path (default: .env)
  • --transport <name> - Validate transport-specific config
  • --verbose - Show detailed validation results

Example:

hatch validate .env
hatch validate --config .env --verbose

Architecture

Built with Charm libraries:

Development

Prerequisites

  • Go 1.21+
  • Protoflow library (for validation)

Building

go build -o hatch ./cmd/hatch

Running Tests

# Run all tests
go test ./...

# Run tests with coverage
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -func=coverage.out
go tool cover -html=coverage.out -o coverage.html

# Run tests with verbose output
go test -v ./...

Generated Project Structure

When you run hatch init, you get a complete production-ready structure:

my-service/
β”œβ”€β”€ main.go                  # Entry point with build metadata
β”œβ”€β”€ go.mod                   # Dependencies
β”œβ”€β”€ .env.example             # Environment configuration template
β”œβ”€β”€ .pre-commit-config.yaml  # Pre-commit hooks
β”œβ”€β”€ taskfile.yml             # Task automation
β”œβ”€β”€ handlers/
β”‚   β”œβ”€β”€ registry.go         # Handler registration
β”‚   └── *.go                # Your event handlers
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ app/                # Application orchestration
β”‚   β”‚   β”œβ”€β”€ app.go          # Main app lifecycle
β”‚   β”‚   β”œβ”€β”€ bootstrap.go    # Initialization
β”‚   β”‚   β”œβ”€β”€ config.go       # Viper-based config
β”‚   β”‚   └── http_server.go  # HTTP server setup
β”‚   β”œβ”€β”€ usecase/            # Business logic layer
β”‚   β”‚   └── usecase.go      # Use case implementation
β”‚   β”œβ”€β”€ events/             # Event handling
β”‚   β”‚   β”œβ”€β”€ events_setup.go # Event service setup
β”‚   β”‚   β”œβ”€β”€ validator.go    # Event validation
β”‚   β”‚   └── config.go       # Events config
β”‚   └── database/           # Database support
β”‚       β”œβ”€β”€ db.go           # MongoDB connection
β”‚       └── config.go       # Database config
└── pkg/
    └── logging/            # Logging & observability
        β”œβ”€β”€ logging.go      # Structured logging
        β”œβ”€β”€ tracing/        # OTEL tracing
        └── metrics/        # OTEL metrics

CLI Project Structure

hatch/
β”œβ”€β”€ cmd/hatch/          # CLI entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ commands/           # Command implementations
β”‚   β”œβ”€β”€ ui/                 # Charm UI components
β”‚   └── scaffold/           # Code generation & templates
β”œβ”€β”€ docs/                   # Documentation
└── README.md

Testing

The project maintains high test coverage with comprehensive unit tests:

# Run all tests with coverage
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -func=coverage.out
go tool cover -html=coverage.out -o coverage.html

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Development Setup

  1. Clone the repository
  2. Install dependencies: go mod download
  3. Run tests: go test ./...
  4. Build: go build ./cmd/hatch

License

MIT License - see LICENSE file.

What Gets Generated

The CLI generates a production-ready event-driven service with:

  • App Orchestration (internal/app) - Lifecycle management, graceful shutdown, initialization
  • Use Case Layer (internal/usecase) - Business logic separation from handlers
  • Event Handling (internal/events) - Event service setup with middleware, validation, retries
  • Database Support (internal/database) - MongoDB integration with health checks
  • Observability (pkg/logging) - Structured logging, OTEL tracing & metrics (stubs ready for implementation)
  • Configuration - Viper-based config with environment variable support
  • Development Tools - Pre-commit hooks, Taskfile, comprehensive .env.example

Related Projects

About

A CLI tool that scaffolds production-ready event-driven services with a beautiful terminal UI.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages