golang-project-layout

Organize Go project directories and workspaces by project type and module boundaries.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-project-layout-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-project-layout
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-project-layout
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-project-layout-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

Helps you organize Go projects so they stay idiomatic, maintainable, and appropriately sized for the problem. It prevents common mistakes like over-layering small tools, placing business logic in cmd, or choosing the wrong home for shared code.

Core Features & Use Cases

  • Guides the choice between CLI, library, service, monorepo, and workspace layouts.
  • Explains correct use of cmd, internal, pkg, tests, configuration, and go.work.
  • Useful when starting a new Go project, restructuring an existing codebase, or splitting multiple binaries and modules.
  • Reinforces clean architecture boundaries, 12-factor conventions, and co-located test organization.

Quick Start

Ask the skill to review your Go project and recommend the right architecture, directory layout, module naming, and dependency-injection approach for your specific scope.

Frequently Asked Questions about golang-project-layout

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is the best way to structure a Golang project directory without overengineering?

The best way to structure a Golang project directory is to organize it based on project type and scope, enforcing clean architecture boundaries and 12-factor conventions. This ensures the layout stays idiomatic and maintainable without adding unnecessary layers for small tools.

How do I organize cmd, internal, and pkg folders for a new Go service?

To organize cmd, internal, and pkg folders, place minimal executable logic in cmd, keep proprietary business logic in internal, and use pkg for shared library code. This directory structure enforces clean architecture boundaries and maintains correct module boundaries for Go services.

When should I use a Go workspace (go.work) instead of a single module?

You should use a Go workspace (go.work) when splitting multiple binaries and modules within a monorepo. This project layout decision helps manage module boundaries effectively, ensuring maintainable dependency injection and clean architecture across different shared codebases.

Does this Go project layout approach work for CLI tools and libraries?

Yes, this Go project layout approach works for CLI tools and libraries by guiding the correct directory structure based on project type. It prevents common mistakes like over-layering small tools or placing business logic in cmd, ensuring the layout is appropriately sized for the problem.

How do I configure environment-based settings for a 12-factor Go application?

To configure environment-based settings for a 12-factor Go application, co-locate tests and apply environment-based configuration within your directory structure. This reinforces 12-factor conventions, separating config from code for maintainable Go services and CLI tools.