explaingit

golang-standards/project-layout

55,984MakefileAudience · developerComplexity · 1/5ActiveLicenseSetup · easy

TLDR

A community-maintained guide showing how to organize files and folders in Go projects, with recommended directory structures for different types of code.

Mindmap

mindmap
  root((repo))
    What it does
      Directory structure
      Organization guide
      Best practices
    Key directories
      cmd entry points
      internal private code
      pkg reusable libraries
      api definitions
    Use cases
      Starting new projects
      Team consistency
      Code review reference
    Audience
      Go developers
      Project leads
      Beginners learning

Things people build with this

USE CASE 1

Set up a new Go application with a clear, scalable folder structure from day one.

USE CASE 2

Ensure consistent project layout across multiple Go repositories on your team.

USE CASE 3

Review and refactor an existing Go project's organization to match community standards.

USE CASE 4

Learn where to place different types of code (commands, libraries, internal utilities) in a Go project.

Tech stack

GoMakefile

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

This repository is a community-maintained reference guide that shows developers how to organize the files and folders in a Go programming language project. Go (also called Golang) is a programming language made by Google, and when you start a new project in it, you face the question of where to put different types of code. This repo answers that question by providing a recommended folder structure that has become widely adopted across the Go ecosystem. The core idea is that a Go project should be split into well-named directories, each with a specific purpose. For example, the "/cmd" folder holds the entry points for your application, "/internal" holds private code that other projects cannot import, "/pkg" holds reusable library code that outside projects are welcome to use, and "/api" holds API definition files. Each directory name signals intent clearly to any developer who opens the project. This is not an official Go standard, the readme is careful to say it is a community convention, not a mandate from the Go core team. It is more like a widely-shared best practice that emerged from real-world usage across many large Go projects. Beginners are explicitly warned not to use it for small projects, since a single main.go file is fine for learning or prototyping. You would reach for this reference when starting a new Go application that is expected to grow, when joining a Go team that wants consistent structure across repositories, or when reviewing an existing Go project's layout. It does not provide runnable code; it is a documented template with explanations. The tech stack is minimal: the repository itself uses a Makefile for automation but its value is entirely in the documentation and directory structure it describes, all targeting the Go programming language and its module system.

Copy-paste prompts

Prompt 1
I'm starting a new Go project. Show me how to organize my directories using the golang-standards/project-layout structure, and explain what goes in /cmd, /internal, and /pkg.
Prompt 2
Our Go team has inconsistent project layouts. Use golang-standards/project-layout to create a template structure we can adopt across all our repos.
Prompt 3
I inherited a messy Go codebase. Help me refactor it to match the golang-standards/project-layout directory structure.
Prompt 4
Explain the difference between /internal and /pkg directories in the golang-standards/project-layout and when to use each one.
Prompt 5
Generate a sample Go project skeleton following golang-standards/project-layout with placeholder files in each recommended directory.
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.