AgentSkillsCN

arquitecture-ms-go-skill

采用 Lambda 就绪的六边形架构,快速搭建 Go 微服务项目。适用于用户希望按照六边形/整洁架构模式,创建、生成脚手架,或配置新的 Go 微服务、Lambda 函数,以及后端服务项目时使用。支持 AWS Lambda 处理程序、SQS 事件处理、MySQL 客户端,同时遵循标准项目结构,包含 cmd 目录、internal(核心/驱动/共享/库)、Dockerfile、Makefile 以及 AWS SAM 模板。

SKILL.md
--- frontmatter
name: arquitecture-ms-go-skill
description: Create Go microservice projects with Lambda-ready hexagonal architecture. Use when the user requests to create, scaffold, or set up a new Go microservice, Lambda function, or backend service project following the hexagonal/clean architecture pattern. Supports AWS Lambda handlers, SQS event processing, MySQL clients, and standard project structure with cmd, internal (core/driving/shared/libraries), Dockerfiles, Makefiles, and AWS SAM templates.
license: Complete terms in LICENSE.txt

Go Microservice Architecture Generator

Generates complete Go microservice projects following hexagonal/clean architecture principles, optimized for AWS Lambda with SQS event processing.

Overview

This skill creates production-ready Go microservice projects with:

  • Hexagonal/clean architecture separation (core, driving, libraries, shared)
  • AWS Lambda handler with SQS event processing
  • MySQL database client with connection pooling
  • Docker multi-stage builds
  • AWS SAM templates for deployment
  • Local development setup with Makefile

When to Use

Use this skill when the user:

  • Requests to create a new Go microservice
  • Wants to scaffold a Lambda function in Go
  • Needs an AWS Lambda + SQS event processor
  • Asks for a hexagonal/clean architecture template
  • Wants a production-ready Go service structure

Quick Start

Ask questions like:

  • "Create a new microservice called ms-orders for processing orders"
  • "Generate a Go Lambda function to handle user events"
  • "Set up a new Go service with hexagonal architecture"

The skill will ask for:

  1. Service name (e.g., "ms-everflow", "user-service")
  2. Domain entity (e.g., "event", "user", "order")
  3. Go module path (e.g., "github.com/company/project")

Generated Structure

code
project-name/
├── buildspec-ecs.yaml        # AWS CodeBuild/ECS deployment
├── Dockerfile                # Production multi-stage build
├── Dockerfile.local          # Local development
├── Makefile                  # Development commands
├── template.yaml             # AWS SAM template
├── sqs_event.json           # Sample SQS event for testing
└── src/
    ├── go.mod               # Go module definition
    ├── cmd/
    │   └── lambda-{service}/
    │       └── main.go      # Lambda entrypoint
    └── internal/
        ├── core/            # Business logic (domain entities)
        │   └── {domain}/
        │       └── domain/
        ├── driving/         # Inbound adapters (handlers)
        │   └── lambda_handler/
        │       ├── lambda.go
        │       ├── database.go
        │       ├── timeout.go
        │       └── types.go
        ├── libraries/       # Infrastructure clients
        │   └── mysql/
        │       └── mysql_client.go
        └── shared/          # Shared domain utilities
            └── domain/
                ├── error.go
                └── log.go

Implementation Process

  1. Gather Requirements: Confirm service name, domain, and module path with user
  2. Copy Templates: Use files from assets/skeleton/ directory
  3. Replace Placeholders: Substitute all template variables:
    • {MODULE_PATH}: Go module path
    • {SERVICE_NAME}: Service name
    • {DOMAIN}: Domain name (lowercase)
    • {ENTITY}: Entity name (PascalCase)
    • {LAMBDA_FUNCTION_NAME}: CloudFormation resource name
  4. Create Structure: Build complete directory tree
  5. Verify: Ensure all imports and references are correct

Key Components

Lambda Handler

  • SQS batch event processing
  • Structured logging with slog
  • Database connection lifecycle
  • Timeout handling with graceful shutdown
  • Batch failure reporting

Database Layer

  • MySQL client with configurable pools
  • Environment-based configuration
  • Connection verification
  • Graceful closure

Domain Layer

  • Clean business entities
  • No infrastructure dependencies
  • Custom error types

Infrastructure

  • Dockerfile: Multi-stage with Lambda runtime and Lambda Insights
  • Makefile: Local SAM invocation
  • SAM Template: Lambda configuration with SQS trigger
  • Buildspec: ECS deployment automation

Template Placeholders

All templates in assets/skeleton/ use these placeholders:

PlaceholderExampleDescription
{MODULE_PATH}github.com/company/projectGo module import path
{SERVICE_NAME}ms-everflowKebab-case service name
{DOMAIN}eventLowercase domain name
{ENTITY}EventPascalCase entity name
{LAMBDA_FUNCTION_NAME}EventProcessorFunctionCloudFormation resource name

Post-Generation Commands

After creating the project, guide the user:

bash
# Install dependencies
cd src && go mod tidy

# Run locally with SAM
make run-dev

# Build Docker image
docker build -t {service-name} .

# Deploy with SAM
sam build && sam deploy

Resources

assets/skeleton/

Template files that get copied and customized when generating a new project:

  • go.mod.template - Go module definition
  • main.go.template - Lambda entrypoint
  • lambda.go.template - SQS event handler
  • database.go.template - MySQL initialization
  • timeout.go.template - Graceful shutdown
  • types.go.template - Custom types placeholder
  • event.go.template - Domain entity
  • mysql_client.go.template - Database client
  • error.go.template - Custom errors
  • log.go.template - Logging utilities
  • Dockerfile.template - Production build
  • Makefile.template - Development commands
  • template.yaml.template - SAM configuration
  • sqs_event.json.template - Test event
  • buildspec-ecs.yaml.template - CI/CD pipeline

See assets/skeleton/README.md for detailed file mapping.