Token导航 LogoToken导航TokenDH.com
研究检索external-servicegithub未标认证来源可访问clear审计通过

go-architecture去架构

Agent Skill

go-architecture 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

196

周安装

8

GitHub Stars

公开资料未说明

下载量

63
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:go-architecture(去架构)
来源仓库:https://github.com/direktly/agent-skills
仓库路径:skills/go-architecture
安装命令:
npx skills add https://github.com/direktly/agent-skills --skill go-architecture
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/direktly/agent-skills --skill go-architecture

简介

用于查找、检索和筛选相关信息。

  • 适合在关键词搜索或任务场景下快速定位候选结果。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装,需确认权限范围。
  • 使用前建议核验是否会触发联网或文件读写操作。
  • go-architecture 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Go Architecture Design

This guide explains the DDD and CQRS principles demonstrated in this codebase, presented in a way that allows engineers to apply these patterns to any industry or business domain.

Table of Contents

  1. Domain-Driven Design Overview
  2. Architecture Layers
  3. Domain Layer Principles
  4. Application Layer Patterns
  5. Infrastructure Layer Design
  6. CQRS Implementation
  7. Idempotency Pattern
  8. Best Practices
  9. Applying These Principles

Domain-Driven Design Overview

Domain-Driven Design (DDD) is a software development approach that:

  • Places the business domain at the heart of the software
  • Creates a shared language between developers and domain experts
  • Isolates business logic from technical concerns
  • Enables scalable and maintainable architectures

Core Concepts

  1. Ubiquitous Language: Use the same terminology in code that domain experts use
  2. Bounded Contexts: Define clear boundaries where specific domain models apply
  3. Entities: Objects with unique identity that persist over time
  4. Value Objects: Immutable objects defined by their attributes
  5. Aggregates: Clusters of entities and value objects with defined boundaries
  6. Repositories: Abstractions for data persistence

Architecture Layers

This implementation follows the Onion Architecture pattern with clear separation of concerns:

┌─────────────────────────────────────┐
│         Interface Layer             │ ← External APIs, Controllers
├─────────────────────────────────────┤
│       Application Layer             │ ← Use Cases, Commands, Queries
├─────────────────────────────────────┤
│         Domain Layer                │ ← Business Logic, Entities
├─────────────────────────────────────┤
│     Infrastructure Layer            │ ← Database, External Services
└─────────────────────────────────────┘

Layer Dependencies

  • Inner layers know nothing about outer layers
  • Domain layer has zero dependencies on other layers
  • Infrastructure implements interfaces defined by domain
  • Application layer orchestrates between domain and infrastructure

Domain Layer Principles

1. Entity Design

type Entity struct {
    ID        uuid.UUID    // Always use unique identifiers
    CreatedAt time.Time    // Set by domain, not database
    UpdatedAt time.Time    // Updated on modifications
    // Business attributes
}

Key Principles:

  • Entities have identity that persists across time
  • Factory methods (NewEntity) ensure valid initial state
  • Business rules are enforced through methods
  • Validation happens at creation and modification

2. Validation Pattern

// Private validation method
func (e *Entity) validate() error {
    // Business rule validations
    if e.BusinessAttribute == "" {
        return errors.New("business rule violation")
    }
    return nil
}

// Public modification method with validation
func (e *Entity) UpdateAttribute(value string) error {
    // Validate BEFORE modifying state
    if value == "" {
        return errors.New("business rule violation")
    }

    // Only modify if validation passes
    e.BusinessAttribute = value
    e.UpdatedAt = time.Now()
    return nil
}

3. Validated Entity Pattern

type ValidatedEntity struct {
    Entity
    isValidated bool
}

func NewValidatedEntity(entity *Entity) (*ValidatedEntity, error) {
    if err := entity.validate(); err != nil {
        return nil, err
    }
    return &ValidatedEntity{
        Entity:      *entity,
        isValidated: true,
    }, nil
}

Purpose: Ensures only valid entities can be persisted

4. Repository Interfaces

type EntityRepository interface {
    Create(entity *ValidatedEntity) (*Entity, error)
    FindByID(id uuid.UUID) (*Entity, error)
    FindAll() ([]*Entity, error)
    Update(entity *ValidatedEntity) (*Entity, error)
    Delete(id uuid.UUID) error
}

Key Points:

  • Domain defines interfaces, infrastructure implements them
  • Methods accept validated entities for writes
  • Read methods return regular entities (not validated)
  • Always return fresh data after writes

Application Layer Patterns

1. Service Structure

type EntityService struct {
    repo            repositories.EntityRepository
    idempotencyRepo repositories.IdempotencyRepository
}

Services orchestrate:

  • Command execution
  • Query handling
  • Transaction boundaries
  • Cross-aggregate operations

2. Use Case Implementation

  • Each use case is a method on the service
  • Clear input (commands) and output (results)
  • Handles idempotency
  • Coordinates between repositories

Infrastructure Layer Design

1. Repository Implementation

type SqlcEntityRepository struct {
    queries *db.Queries
}

func (repo *SqlcEntityRepository) Create(entity *ValidatedEntity) (*Entity, error) {
    ctx := context.Background()
    dbEntity, err := repo.queries.CreateEntity(ctx, db.CreateEntityParams{
        ID:        entity.ID,
        Name:      entity.Name,
        CreatedAt: timestamptzFromTime(entity.CreatedAt),
        UpdatedAt: timestamptzFromTime(entity.UpdatedAt),
    })
    if err != nil {
        return nil, err
    }
    // Always read after write
    return repo.FindByID(dbEntity.ID)
}

2. Mapping Pattern

// Domain to Database
func toDBModel(entity *ValidatedEntity) *DBModel {
    // Map domain entity to database model
}

// Database to Domain
func fromDBModel(dbModel *DBModel) *Entity {
    // Map database model to domain entity
}

Purpose: Keep domain models pure and database concerns isolated

CQRS Implementation

Command Pattern

Commands modify state and are task-oriented:

type CreateEntityCommand struct {
    IdempotencyKey string
    // Business attributes
}

type CreateEntityCommandResult struct {
    Result *EntityResult
}

Query Pattern

Queries retrieve data without side effects:

// For queries with parameters
type GetEntityByIDQuery struct {
    ID uuid.UUID
}

type GetEntityByIDQueryResult struct {
    Result *EntityResult
}

// For simple parameterless queries, use direct method calls
func (s *EntityService) FindAllEntities() (*EntityQueryListResult, error) {
    // Simple queries don't need query objects
}

// For complex queries with filters/parameters, use query objects
func (s *EntityService) FindEntitiesByCategory(query *GetEntitiesByCategoryQuery) (*EntityQueryListResult, error) {
    // Complex queries benefit from query objects
}

Query Object Guidelines:

  • Use query objects for queries with parameters or complex filters
  • Simple parameterless queries (like FindAll) can use direct method calls
  • This avoids unnecessary empty struct instantiation

Benefits of CQRS

  1. Optimized Read/Write Models: Different models for different purposes
  2. Scalability: Scale reads and writes independently
  3. Performance: Optimize queries without affecting write logic
  4. Clarity: Clear separation of intentions

Idempotency Pattern

Implementation

// Check for existing execution
if command.IdempotencyKey != "" {
    existing, err := idempotencyRepo.FindByKey(ctx, command.IdempotencyKey)
    if existing != nil {
        return cachedResponse, nil
    }
}

// Execute business logic
result := executeBusinessLogic()

// Store result for future requests
if command.IdempotencyKey != "" {
    record := NewIdempotencyRecord(command.IdempotencyKey, request)
    record.SetResponse(response, statusCode)
    idempotencyRepo.Create(ctx, record)
}

Benefits

  • Prevents duplicate operations
  • Handles network failures gracefully
  • Ensures consistency in distributed systems

Best Practices

1. Domain Layer Purity

  • No framework dependencies
  • No infrastructure concerns
  • Business logic only
  • Self-contained validation

2. Factory Methods

func NewEntity(businessAttribute string) *Entity {
    return &Entity{
        ID:                uuid.New(),
        CreatedAt:         time.Now(),
        UpdatedAt:         time.Now(),
        BusinessAttribute: businessAttribute,
    }
}

3. Read After Write

Always return fresh data from the database after modifications to ensure consistency.

4. Historical Data Compatibility

  • Don't validate on read operations
  • Allow loading of data created with old business rules
  • Validate only on write operations

5. Soft Delete Pattern

Implement soft deletes at the infrastructure layer without polluting domain entities:

Domain Layer (Pure):

type Entity struct {
    ID        uuid.UUID
    Name      string
    CreatedAt time.Time
    UpdatedAt time.Time
    // No DeletedAt field - keep domain pure
}

Infrastructure Layer (Database):

-- Database table includes deleted_at
CREATE TABLE entities (
    id UUID PRIMARY KEY,
    name TEXT NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE NOT NULL,
    updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
    deleted_at TIMESTAMP WITH TIME ZONE  -- Only in database
);

-- Delete operation becomes an UPDATE
-- name: DeleteEntity :exec
UPDATE entities SET deleted_at = NOW() WHERE id = $1;

-- All SELECT queries filter out soft-deleted records
-- name: GetEntityByID :one
SELECT id, name, created_at, updated_at
FROM entities
WHERE id = $1 AND deleted_at IS NULL;

Benefits:

  • Domain entities remain focused on business logic
  • Soft delete is an infrastructure concern, not a business rule
  • Data recovery is possible without domain knowledge
  • Audit trails are maintained at the database level
  • Foreign key relationships remain intact

Implementation Guidelines:

  1. Add deleted_at column only in database schema
  2. Update DELETE operations to set deleted_at = NOW()
  3. Add WHERE deleted_at IS NULL to all SELECT queries
  4. Repository implementations remain unchanged
  5. Domain layer is completely unaware of soft delete mechanism

Applying These Principles

Step 1: Identify Your Domain

  1. Work with domain experts to understand the business
  2. Identify key entities and their relationships
  3. Define business rules and invariants
  4. Create a ubiquitous language

Step 2: Design Your Entities

// Example for an e-commerce domain
type Order struct {
    ID         uuid.UUID
    CreatedAt  time.Time
    UpdatedAt  time.Time
    CustomerID uuid.UUID
    Items      []OrderItem
    Status     OrderStatus
    Total      Money
}

func NewOrder(customerID uuid.UUID) *Order {
    return &Order{
        ID:         uuid.New(),
        CreatedAt:  time.Now(),
        UpdatedAt:  time.Now(),
        CustomerID: customerID,
        Status:     OrderStatusPending,
        Items:      []OrderItem{},
    }
}

func (o *Order) AddItem(product Product, quantity int) error {
    // Business logic for adding items
    // Validate quantity, calculate prices, etc.
}

Step 3: Define Repository Interfaces

type OrderRepository interface {
    Create(order *ValidatedOrder) (*Order, error)
    FindByID(id uuid.UUID) (*Order, error)
    FindByCustomerID(customerID uuid.UUID) ([]*Order, error)
    Update(order *ValidatedOrder) (*Order, error)
}

Step 4: Implement CQRS

Commands:

type PlaceOrderCommand struct {
    IdempotencyKey string
    CustomerID     uuid.UUID
    Items          []OrderItemRequest
}

Queries:

type GetCustomerOrdersQuery struct {
    CustomerID uuid.UUID
    Status     *OrderStatus // Optional filterfunc NewEntity(businessAttribute string) *Entity {
        return &Entity{
            ID:                uuid.New(),
            CreatedAt:         time.Now(),
            UpdatedAt:         time.Now(),
            BusinessAttribute: businessAttribute,
        }
    }
}

Step 5: Create Application Services

type OrderService struct {
    orderRepo       repositories.OrderRepository
    productRepo     repositories.ProductRepository
    idempotencyRepo repositories.IdempotencyRepository
}

func (s *OrderService) PlaceOrder(cmd *PlaceOrderCommand) (*PlaceOrderResult, error) {
    // Implement idempotency check
    // Validate products exist
    // Create order
    // Calculate totals
    // Save order
    // Return result
}

Industry-Agnostic Guidelines

  1. Healthcare: Patient (Entity), Appointment (Entity), Diagnosis (Value Object)
  2. Finance: Account (Entity), Transaction (Entity), Money (Value Object)
  3. Education: Student (Entity), Course (Entity), Grade (Value Object)
  4. Logistics: Shipment (Entity), Package (Entity), Address (Value Object)

The patterns remain the same; only the domain concepts change.

Conclusion

These DDD and CQRS principles provide a robust foundation for building maintainable, scalable applications regardless of your business domain. The key is to:

  1. Keep domain logic pure and isolated
  2. Use CQRS to separate read and write concerns
  3. Implement proper validation and factory patterns
  4. Handle idempotency for distributed systems
  5. Follow the dependency rules between layers

By applying these principles, you create software that clearly expresses business requirements while remaining flexible for future changes.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

windsurf

32.82%
按下载量换算21

OpenCode

22.66%
按下载量换算14

Codex

18.01%
按下载量换算11

Claude Code

11.6%
按下载量换算7

Antigravity

7.97%
按下载量换算5

Gemini CLI

3.94%
按下载量换算2

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills