golang-project-layout

Guide Go project layout decisions for CLIs, services, libraries, and monorepos.

7|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/Harmeet10000/skills --skill golang-project-layout-harmeet10000
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-project-layout
Source: https://github.com/Harmeet10000/skills/tree/main/skills/backend/Golang/golang-project-layout
Command: npx skills add https://github.com/Harmeet10000/skills --skill golang-project-layout-harmeet10000

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes assets (resource) components.

What problem does it solve?

Go projects often suffer from over- or under-structured layouts that hinder collaboration and evolution. This skill guides you to pick and apply a Go project structure that matches the size and goals of your project, from tiny CLIs to monorepos.

Core Features & Use Cases

  • Guidance on choosing an appropriate project type (CLI tool, library, service, monorepo) and where to place code (cmd/, internal/, pkg/).
  • Decision criteria for architecture and dependencies, including when to apply 12-Factor practices and DI considerations.
  • Real-world usage: starting a new Go module, organizing multiple main packages, and aligning with go.work for multi-module setups where appropriate.

Quick Start

Choose your Go project type (CLI, library, service, or monorepo) and follow the layout guidelines to initialize directories, module naming, and essential config.

Frequently Asked Questions about golang-project-layout

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

FAQPage Schema
How do I structure a Golang project to avoid over-engineering the directory layout?

To structure a Golang project effectively, match the directory layout to your project's size and goals, applying right-sized guidelines for CLI tools, libraries, services, or monorepos to prevent over-engineering.

What is the best way to organize multiple main packages in a Go service?

The best way to organize multiple main packages is by using the cmd/ directory layout, placing each executable in its own subdirectory to maintain clear entry points and simplify build management.

When do I need to use go.work for a multi-module Go monorepo setup?

You need to use go.work for a multi-module Go setup when managing a monorepo with interdependent modules, allowing local development workflows to resolve module dependencies without pushing changes.

Does a Go project layout need dependency injection and 12-factor considerations?

A Go project layout often needs dependency injection and 12-factor considerations for services to cleanly separate configuration, environment variables, and internal dependencies from the core business logic.

Can I use internal/ and pkg/ directories for both Go libraries and CLI tools?

You can use the internal/ directory to restrict package visibility and pkg/ for public reusable code, applying both to Go libraries and CLI tools to enforce proper encapsulation and dependency boundaries.

Why should I co-locate tests with source code in a Go project directory structure?

You should co-locate tests with source code in a Go project directory structure to maintain proximity between implementation and test files, simplifying navigation and ensuring cohesive module testing practices.