MCP HubMCP Hub
SKILL·93AC90

go-project-layout

eduardo-sl
更新日 27 days ago
5 閲覧
69
9
69
GitHubで表示
メタai

について

このスキルは、プロジェクトの規模に応じた適切なディレクトリ構造と規約を用いて、新しいGoプロジェクトの基盤を作成します。開発者がフラットレイアウトと、cmd/やinternal/ディレクトリを備えた構造化アプローチのどちらを選択するかを支援し、モジュール名の決定やmainパッケージの接続もカバーします。新しいGoモジュールやサービスを開始する際に使用しますが、既存のアーキテクチャのレビューや詳細な依存性注入には使用しません。

クイックインストール

Claude Code

推奨
メイン
npx skills add eduardo-sl/go-agent-skills -a claude-code
プラグインコマンド代替
/plugin add https://github.com/eduardo-sl/go-agent-skills
Git クローン代替
git clone https://github.com/eduardo-sl/go-agent-skills.git ~/.claude/skills/go-project-layout

このコマンドをClaude Codeにコピー&ペーストしてスキルをインストールします

ドキュメント

Go Project Layout

Structure follows size. The biggest layout mistake in Go is copying a microservice skeleton for a 500-line tool — or growing a 50-package service inside a flat directory. Match the layout to the project.

1. Pick the Layout by Project Size

ProjectLayout
Small tool, single binary, <5 filesFlat: everything in package main at the root
Library for others to importRoot package named after the module, internal/ for helpers
Service with one binarycmd/<name>/main.go + internal/ packages
Multiple binaries sharing codecmd/<name1>/, cmd/<name2>/ + internal/

Never start with empty pkg/, api/, docs/, build/ directories "for later". Add structure when the code demands it, not before.

2. Module Naming

# ✅ Good — repository path, lowercase
go mod init github.com/acme/payment-service

# ❌ Bad — not fetchable, uppercase, or vanity without DNS
go mod init PaymentService
go mod init payment_service

The last path element should match what users will see: for a library, it becomes the default import name.

3. Service Layout (the default for APIs and workers)

payment-service/
├── cmd/
│   └── payment-api/
│       └── main.go         # flag/env parsing, wiring, Run() — nothing else
├── internal/
│   ├── domain/             # core types, business rules; zero external deps
│   ├── service/            # use cases orchestrating domain + stores
│   ├── store/              # data access implementations (postgres/, redis/)
│   ├── handler/            # HTTP/gRPC adapters
│   └── config/             # config loading and validation
├── migrations/             # if the service owns a database
├── go.mod
├── Makefile
└── README.md

Rules:

  • internal/ by default — the compiler enforces that nobody outside the module imports it. Promote to a public package only on demand.
  • pkg/ only when external consumers exist AND the module also has private code. When in doubt, don't create it.
  • Dependencies point inward: handler → service → domain ← store. domain imports neither store nor handler.

4. Thin main, Runnable Run

Keep main.go to wiring plus a delegating call, so the app is testable:

func main() {
    if err := run(context.Background(), os.Args[1:], os.Getenv); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}

func run(ctx context.Context, args []string, getenv func(string) string) error {
    cfg, err := config.Load(getenv)
    if err != nil {
        return fmt.Errorf("load config: %w", err)
    }

    db, err := store.Open(ctx, cfg.DatabaseURL)
    if err != nil {
        return fmt.Errorf("open db: %w", err)
    }
    defer db.Close()

    svc := service.New(store.NewUserRepo(db))
    srv := handler.NewServer(cfg.Addr, svc)
    return srv.ListenAndServe(ctx)
}
  • os.Exit appears exactly once, in main.
  • run takes its dependencies (args, getenv) so tests can call it.
  • No init() functions for wiring — explicit construction order only.

5. Library Layout

retry/
├── retry.go            # package retry — the API, in the root
├── retry_test.go
├── backoff.go          # same package, split by topic
├── internal/
│   └── clock/          # implementation details users must not import
├── examples_test.go    # Example* functions shown in godoc
└── go.mod
  • The root directory IS the package. No src/, no lib/.
  • One package per concept. Resist util, common, helpers — name packages after what they provide (retry, clock, httpsign).

6. Naming Rules for Directories and Packages

  • Package name == directory name, short, lowercase, no underscores: store/postgres, not store/postgres_impl.
  • Don't stutter: payment.Service, not payment.PaymentService.
  • Binary names in cmd/ are user-facing: cmd/payment-api, hyphenated is fine (directory only holds package main).

7. Files That Belong at the Root

  • go.mod, go.sum, README.md, LICENSE, Makefile, .golangci.yml, Dockerfile (single-binary projects).
  • Do NOT create: src/ (un-idiomatic), vendor/ (unless the team explicitly vendors), one-file packages like types/ or models/ that become dumping grounds.

Scaffolding Procedure

  1. Ask/decide: tool, library, or service? How many binaries?
  2. go mod init <repo-path>.
  3. Create only the directories the first feature needs.
  4. Write main.go with the thin-main pattern above.
  5. Add Makefile targets: build, test, lint.
  6. Verify: go build ./... and go vet ./... pass on the skeleton.

Verification Checklist

  1. Layout matches project size — no empty scaffolding directories
  2. Module path is the fetchable repository path
  3. All non-public packages live under internal/
  4. main.go is thin: parse, wire, call run, exit
  5. os.Exit only in main; no wiring in init()
  6. Dependencies flow inward; domain has zero infrastructure imports
  7. No util/common/helpers/models grab-bag packages
  8. Package names match directories, lowercase, no stutter
  9. go build ./... passes on the fresh skeleton

GitHub リポジトリ

eduardo-sl/go-agent-skills
パス: skills/(architecture)/go-project-layout
0
FAQ

よくある質問

go-project-layout Skillとは何ですか?

go-project-layout はeduardo-sl が作成した Claude Skillです。Skillは、Claudeが必要に応じて読み込む指示とリソースをまとめ、追加の指示なしで go-project-layout に関連するタスクを実行できるようにします。

go-project-layout をインストールするには?

このページのインストールコマンドを使用してください。go-project-layout をプラグインとして Claude Code に追加するか、リポジトリを skills ディレクトリにクローンし、Claudeを再起動してSkillを読み込みます。

go-project-layout はどのカテゴリに属しますか?

go-project-layout は メタ カテゴリに属します。

go-project-layout は無料で利用できますか?

はい。go-project-layout は AIMCP に掲載されており、無料でインストールできます。

関連スキル

content-collections
メタ

このスキルは、Content Collections(Markdown/MDXファイルを型安全なデータコレクションに変換するTypeScriptファーストのツール)の本番環境でテストされた設定を提供します。Zodバリデーションによる型安全性を実現し、ブログ、ドキュメントサイト、コンテンツ重視のVite + Reactアプリケーション構築時にご利用ください。Viteプラグインの設定、MDXコンパイルから、デプロイ最適化、スキーマバリデーションまで、すべてを網羅しています。

スキルを見る
polymarket
メタ

このスキルは、開発者がPolymarket予測市場プラットフォームを活用したアプリケーション構築を可能にします。API統合による取引や市場データの取得に加え、WebSocketを介したリアルタイムデータストリーミングにより、ライブ取引や市場活動を監視できます。取引戦略の実装や、ライブ市場更新を処理するツールの作成にご利用ください。

スキルを見る
creating-opencode-plugins
メタ

このスキルは、開発者がコマンド、ファイル、LSP操作など25種類以上のイベントタイプにフックするOpenCodeプラグインを作成することを支援します。JavaScript/TypeScriptモジュール向けに、プラグイン構造、イベントAPI仕様、および実装パターンを提供します。カスタムイベント駆動ロジックでOpenCode AIアシスタントのライフサイクルをインターセプト、監視、または拡張する必要がある場合にご利用ください。

スキルを見る
sglang
メタ

SGLangは、高性能なLLMサービングフレームワークであり、RadixAttentionプレフィックスキャッシュを活用したJSON、正規表現、エージェントワークフロー向けの高速で構造化された生成を特長とします。特にプレフィックスが繰り返されるタスクにおいて、大幅に高速な推論を実現し、複雑な構造化出力やマルチターン対話に最適です。制約付きデコードが必要な場合や、広範なプレフィックス共有を伴うアプリケーションを構築する場合は、vLLMなどの代替案ではなくSGLangを選択してください。

スキルを見る