+0
Daily
+14
Weekly
56,745
stars
5,416
forks
591
watchers
159
prs
116
issues
0
releases
README
Standard Go Project Layout Translations: 한국어 문서 简体中文 正體中文 简体中文 - ??? Français 日本語 Português Español Română Русский Türkçe Italiano Tiếng Việt Українська Indonesian हिन्दी فارسی Беларуская বাংলা Overview This is a basic layout for Go application projects. Note that it's basic in terms of content because it's focusing only on the general layout and not what you have inside. It's also basic because it's very high level and it doesn't go into great details in terms of how you can structure your project even further. For example, it doesn't try to cover the project structure you'd have with something like Clean Architecture. This is NOT an official standard defined by the core Go dev team. This is a set of common historical and emerging project layout patterns in the Go ecosystem. Some of these patterns are more popular than others. It also has a number of small enhancements along with several supporting directories common to any large enough real world application. Note that the core Go team provides a great set of general guidelines about structuring Go projects and what it means for your project when it's imported and when it's installed. See the Organizing a Go module page in the official Go docs for more details. It includes the internal and cmd directory patterns (described below) and other useful information. If you are trying to learn Go or if you are building a PoC or a simple project for yourself this project layout is an overkill. Start with something really simple instead (a single main.go file and go.mod is more than enough). As your project grows keep in mind that it'll be important to make sure your code is well structured otherwise you'll end up with a messy code with lots of hidden dependencies and global state. When you have more people working on the project you'll need even more structure. That's when it's important to introduce a common way to manage packages/libraries. When you have an open source project or when you know other projects import the code from your project repository that's when it's important to have private (aka internal) packages and code. Clone the repository, keep what you need and delete everything else! Just because it's there it doesn't mean you have to use it all. None of these patterns are used in every single project. Even the vendor pattern is not universal. With Go 1.14 Go Modules are finally ready for production. Use Go Modules unless you have a specific reason not to use them and if you do then you don’t need to worry about $GOPATH and where you put your project. The basic go.mod file in the repo assumes your project is hosted on GitHub, but it's not a requirement. The module path can be anything though the first module path component should have a dot in its name (the current version of Go doesn't enforce it anymore, but if you are using slightly older versions don't be surprised if your builds fail without it). See Issues 37554 and 32819 if you want to know more about it.
Top issues
#18Best project structure when using go 1.11 mod31 comments · 2018-10-31#10pkg directory should not be recommended for use29 comments · 2018-08-14#61golang.org says to use a src/ directory15 comments · 2020-03-12#36Delete this repo14 comments · 2019-08-12#11What about mail templates, localization files and sql files (migrations)?10 comments · 2018-08-21#1Go project sturcture question 10 comments · 2017-12-13#119#117 must be closed and locked9 comments · 2021-04-29#53Proposal: It would be nice if there's a CLI to generate this layout9 comments · 2020-01-06
Discussions
#288Start aa project on my iPad0 comments · 2026-10-10#254Any idea to manage the constants properly?1 comments · 2024-07-29#250.0 comments · 2024-06-28#242Welcome to project-layout Discussions!1 comments · 2024-01-25#251Should auxiliary code generators be in `cmd/` or in `tools/`?2 comments · 2023-09-28